Package com.saperion.common.io
Class Streams
- java.lang.Object
-
- com.saperion.common.io.Streams
-
public final class Streams extends java.lang.ObjectUtility class for stream treatment.- Author:
- agz, jsc
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]convertInputStreamToByteArray(java.io.InputStream inputStream)Returns the content of the specifiedInputStreamas abyte[], which has exactly the size of the content.static java.lang.StringconvertInputStreamToString(java.io.InputStream inputStream, java.nio.charset.Charset charset)Reads the content of the specifiedInputStreamto abyte[], which will then be interpreted asStringwith the given encoding.static longstream(java.io.InputStream inputStream, java.io.OutputStream outputStream, int bufferSize)Streams anInputStreamcompletely to anOutputStream.
-
-
-
Method Detail
-
stream
public static long stream(java.io.InputStream inputStream, java.io.OutputStream outputStream, int bufferSize) throws java.io.IOExceptionStreams anInputStreamcompletely 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:
java.io.IOException
-
convertInputStreamToByteArray
public static byte[] convertInputStreamToByteArray(java.io.InputStream inputStream) throws java.io.IOExceptionReturns the content of the specifiedInputStreamas abyte[], which has exactly the size of the content. The specifiedInputStreammust not benull.- Parameters:
inputStream-InputStreamto convert into abyte[]- Returns:
byte[]with the content of the specifiedInputStream- Throws:
java.io.IOException- on errors reading the inputStream
-
convertInputStreamToString
public static java.lang.String convertInputStreamToString(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws java.io.IOExceptionReads the content of the specifiedInputStreamto abyte[], which will then be interpreted asStringwith the given encoding.- Parameters:
inputStream-InputStreamthe input stream to read fromcharset- theCharsetto decode the bytes to aString. Must not be null.- Returns:
- a
Stringbeing the content of the givenInputStream - Throws:
java.io.IOException
-
-