Package com.saperion.common.io
Class Streams
java.lang.Object
com.saperion.common.io.Streams
Utility class for stream treatment.
- Author:
- agz, jsc
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
convertInputStreamToByteArray
(InputStream inputStream) Returns the content of the specifiedInputStream
as abyte[]
, which has exactly the size of the content.static String
convertInputStreamToString
(InputStream inputStream, Charset charset) Reads the content of the specifiedInputStream
to abyte[]
, which will then be interpreted asString
with the given encoding.static long
stream
(InputStream inputStream, OutputStream outputStream, int bufferSize) Streams anInputStream
completely to anOutputStream
.
-
Method Details
-
stream
public static long stream(InputStream inputStream, OutputStream outputStream, int bufferSize) throws IOException Streams anInputStream
completely to anOutputStream
. The binary data from inputStream will be stored to outputStream in chunks of the size bufferSize until the end of inputStream is reached.- Parameters:
inputStream
- the input stream to read fromoutputStream
- the output stream to write tobufferSize
- the size of the chunks to use- Returns:
- the number of bytes streamed
- Throws:
IOException
-
convertInputStreamToByteArray
Returns the content of the specifiedInputStream
as abyte[]
, which has exactly the size of the content. The specifiedInputStream
must not benull
.- Parameters:
inputStream
-InputStream
to convert into abyte[]
- Returns:
byte[]
with the content of the specifiedInputStream
- Throws:
IOException
- on errors reading the inputStream
-
convertInputStreamToString
public static String convertInputStreamToString(InputStream inputStream, Charset charset) throws IOException Reads the content of the specifiedInputStream
to abyte[]
, which will then be interpreted asString
with the given encoding.- Parameters:
inputStream
-InputStream
the input stream to read fromcharset
- theCharset
to decode the bytes to aString
. Must not be null.- Returns:
- a
String
being the content of the givenInputStream
- Throws:
IOException
-