Package org.pepsoft.util
Class StreamUtils
java.lang.Object
org.pepsoft.util.StreamUtils
Utility methods for working with
InputStreams and OutputStreams.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopy(InputStream in, OutputStream out) Copy all bytes from the input stream to the output stream and close both streams.static voidcopy(InputStream in, OutputStream out, int maximumBytes) Copy all bytes (up to a specified maximum) from the input stream to the output stream and close both streams.static voidcopy(InputStream in, OutputStream out, ProgressReceiver progressReceiver, long byteCount) Copy all bytes from the input stream to the output stream and close both streams.static byte[]load(InputStream in) Load all bytes from an input stream and close it.
-
Method Details
-
load
Load all bytes from an input stream and close it. Note that there may not be more thanInteger.MAX_VALUEbytes left in the stream.- Parameters:
in- The input stream to load.- Returns:
- All bytes from the input stream.
- Throws:
IOException- If an I/O error occurs while loading the bytes or closing the stream.
-
copy
Copy all bytes from the input stream to the output stream and close both streams.- Parameters:
in- The input stream to copy from.out- The output stream to copy to.- Throws:
IOException- If an I/O error occurs while copying the bytes or closing the streams.
-
copy
Copy all bytes (up to a specified maximum) from the input stream to the output stream and close both streams. This version allows the specification of a maximum number of bytes to copy. If the input stream contains more bytes, the method throws anIOException.- Parameters:
in- The input stream to copy from.out- The output stream to copy to.maximumBytes- The maximum number of bytes to allow in the input stream.- Throws:
IOException- If an I/O error occurs while copying the bytes or closing the streams, or if the input stream contained more than the specified number of bytes.
-
copy
public static void copy(InputStream in, OutputStream out, ProgressReceiver progressReceiver, long byteCount) throws IOException, ProgressReceiver.OperationCancelled Copy all bytes from the input stream to the output stream and close both streams.- Parameters:
in- The input stream to copy from.out- The output stream to copy to.progressReceiver- An optional progress receiver to report copy progress to.byteCount- The number of bytes in the input stream. If the input stream contains more bytes, anIOExceptionis thrown. Specify-1to disable a byte limit. If a progress receiver is specified then this parameter is mandatory.- Throws:
IOException- If an I/O error occurs while copying the bytes or closing the streams, or if there were more.ProgressReceiver.OperationCancelled- If a progress receiver was provided and it threw anOperationCancelledexception.
-