Class StreamUtils
- java.lang.Object
-
- com.github.nosan.embedded.cassandra.commons.StreamUtils
-
public final class StreamUtils extends Object
Utility class providing simple methods for working with streams.- Since:
- 4.0.0
- Author:
- Dmytro Nosan
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopy(InputStream inputStream, OutputStream outputStream)Copies the contents of anInputStreamto anOutputStream.static byte[]toByteArray(InputStream inputStream)Reads the entire contents of anInputStreaminto a byte array.static StringtoString(InputStream inputStream, Charset charset)
-
-
-
Method Detail
-
toString
public static String toString(InputStream inputStream, Charset charset) throws IOException
Converts the contents of anInputStreamto aStringusing the specifiedCharset.Note: The provided
InputStreamwill not be closed by this method. It is the caller's responsibility to close the stream once processing is complete.- Parameters:
inputStream- theInputStreamto read fromcharset- the character encoding to use- Returns:
- the decoded
Stringrepresentation of theInputStream's contents - Throws:
IOException- if an I/O error occurs while reading theInputStreamNullPointerException- ifinputStreamorcharsetisnull
-
toByteArray
public static byte[] toByteArray(InputStream inputStream) throws IOException
Reads the entire contents of anInputStreaminto a byte array.Note: The provided
InputStreamwill not be closed by this method. It is the caller's responsibility to close the stream once processing is complete.- Parameters:
inputStream- theInputStreamto read from- Returns:
- a byte array containing the data read from the
InputStream - Throws:
IOException- if an I/O error occurs while reading theInputStreamNullPointerException- ifinputStreamisnull
-
copy
public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException
Copies the contents of anInputStreamto anOutputStream.Note: Neither the
InputStreamnor theOutputStreamwill be closed by this method. It is the caller's responsibility to close the streams once processing is complete.- Parameters:
inputStream- theInputStreamto read fromoutputStream- theOutputStreamto write to- Throws:
IOException- if an I/O error occurs while reading or writingNullPointerException- ifinputStreamoroutputStreamisnull
-
-