Package com.kosdev.kos.commons.util
Class StreamUtil
java.lang.Object
com.kosdev.kos.commons.util.StreamUtil
A few common stream utilities.
- Since:
- 9
- Version:
- 9
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidCloses the given closeable and ignores any thrown exceptionsstatic booleanCopy the source file to the destination.static booleancopy(File file, OutputStream os) Copy the contents of the file to the output stream.static booleancopy(File file, OutputStream os, boolean closeOutput) Copy the contents of the file to the output stream.static booleancopy(InputStream is, File file) Copy the input stream to the specified file.static booleancopy(InputStream is, File file, boolean closeInput) Copy the stream to the specified file.static booleancopy(InputStream is, OutputStream os) Copy the contents of the input stream to the output stream.static booleancopy(InputStream is, OutputStream os, boolean closeInput, boolean closeOutput) Copy the contents of the input stream to the output stream and close inputs based on supplied flags.static booleancopy(InputStream is, OutputStream os, boolean closeInput, boolean closeOutput, int size) Copy the contents of the input stream to the output stream.static byte[]Reads all remaining bytes from the streamstatic byte[]readAllBytes(InputStream in, boolean closeInput) Reads all remaining bytes from the streamstatic byte[]readBytes(InputStream in, int len) Forces reading the given length from the given streamstatic byte[]readBytes(InputStream in, int len, boolean closeInput) Forces reading the given length from the given streamstatic voidwrite(byte[] bytes, OutputStream os) Write the array of bytes to given output stream.
-
Constructor Details
-
StreamUtil
public StreamUtil()
-
-
Method Details
-
copy
public static boolean copy(InputStream is, OutputStream os, boolean closeInput, boolean closeOutput, int size) Copy the contents of the input stream to the output stream. Close the steams based on the close flags.- Parameters:
is- the input stream to copy fromos- the output stream to copy tocloseInput- close the input when donecloseOutput- close the output when donesize- the block size- Returns:
- false if there was any error
-
copy
public static boolean copy(InputStream is, OutputStream os, boolean closeInput, boolean closeOutput) Copy the contents of the input stream to the output stream and close inputs based on supplied flags.- Parameters:
is- the input stream to copy fromos- the output stream to copy tocloseInput- close the input when donecloseOutput- close the output when done- Returns:
- false if there was any error
-
copy
Copy the contents of the input stream to the output stream. This will close the input and output stream automatically.- Parameters:
is- the input stream to copy fromos- the output stream to copy to- Returns:
- false if there was any error
-
copy
Copy the contents of the file to the output stream. Close the output stream if specified.- Parameters:
file- the file to sendos- the output stream to copy tocloseOutput- close the output when done- Returns:
- false if there was any error
-
copy
Copy the contents of the file to the output stream. Close the output stream upon completion.- Parameters:
file- the file to sendos- the output stream to copy to- Returns:
- false if there was any error
-
copy
Copy the stream to the specified file. Close the input stream if specified.- Parameters:
is- the input stream to copy fromfile- the file to write tocloseInput- close the input when done- Returns:
- false if there was any error
-
copy
Copy the input stream to the specified file. Close the input stream upon completion.- Parameters:
is- the input stream to copy fromfile- the file to write to- Returns:
- false if there was any error
-
copy
Copy the source file to the destination.- Parameters:
src- the file to copydst- the file to copy to- Returns:
- false if there was any error
-
readAllBytes
Reads all remaining bytes from the stream- Parameters:
in- input stream- Returns:
- read bytes
-
readAllBytes
Reads all remaining bytes from the stream- Parameters:
in- input streamcloseInput- indicator whether the input stream should be closed- Returns:
- read bytes
-
readBytes
Forces reading the given length from the given stream- Parameters:
in- input streamlen- length to read- Returns:
- read bytes
-
readBytes
Forces reading the given length from the given stream- Parameters:
in- input streamlen- length to readcloseInput- indicates if the input should be closed- Returns:
- read bytes
-
close
Closes the given closeable and ignores any thrown exceptions- Parameters:
closeable- closeable
-
write
Write the array of bytes to given output stream.- Parameters:
bytes- write to output streamos- output stream to write to
-