Skip to content

Commit

Permalink
Add util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Apr 1, 2011
1 parent 209aee0 commit 60e729c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions core/src/java/com/dtolabs/utils/Streams.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@ public static void copyStream(final InputStream in, final OutputStream out) thro
}
}

/**
* A simple Thread subclass that performs a stream copy from an InputStream to an OutputStream. If an IOException
* is thrown, it is available via {@link #getException()}.
*/
public static class StreamCopyThread extends Thread {
final InputStream in;
final OutputStream out;
private IOException exception;

public StreamCopyThread(final InputStream in, final OutputStream out) {
this.in = in;
this.out = out;
}

@Override
public void run() {
try {
Streams.copyStream(in, out);
} catch (IOException e) {
exception = e;
}
}

public IOException getException() {
return exception;
}
}

/**
* Return a new thread that will copy an inputstream to an output stream. You must start the thread.
*
* @param in inputstream
* @param out outputstream
*
* @return an unstarted {@link StreamCopyThread}
*/
public static StreamCopyThread copyStreamThread(final InputStream in, final OutputStream out) {
return new StreamCopyThread(in, out);
}

/**
* Read the data from the input stream and write to the outputstream, filtering with an Ant FilterSet.
*
Expand Down

0 comments on commit 60e729c

Please sign in to comment.