Package de.espirit.common.tools
Class Streams
java.lang.Object
de.espirit.common.tools.Streams
Generic utility to provide stream related operations.
- Since:
- 5.2.21
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
static String
toBase64
(byte[] bytes) Encodes a raw byte array into a BASE64 string representation in accordance with RFC 2045.static byte[]
Read the content of an input stream into a byte array.static String
toString
(InputStream in, String encoding) Read the content of the specified input stream and returns the content as string using the specified encoding.static long
write
(InputStream in, OutputStream out) Transfers all date from the given input stream to the given output stream and returns the number of transfered bytes.
-
Constructor Details
-
Streams
public Streams()
-
-
Method Details
-
toByteArray
Read the content of an input stream into a byte array. The stream will be closed after processing.- Parameters:
in
- The input stream to read from.- Returns:
- A byte array containing the content of the provided input stream.
- Throws:
IOException
- If the first byte cannot be read for any reason other than the end of the file,if the input stream has been closed, or if some other I/O error occurs.- Since:
- 5.2.21
-
toString
@NotNull public static String toString(@NotNull InputStream in, @NotNull String encoding) throws IOException Read the content of the specified input stream and returns the content as string using the specified encoding. The stream will be closed after processing.- Parameters:
in
- The input stream to read from.encoding
- The encoding to use for the string interpretation.- Returns:
- The stream content as string.
- Throws:
IOException
- If the first byte cannot be read for any reason other than the end of the file,if the input stream has been closed, or if some other I/O error occurs.- Since:
- 5.2.21
-
toBase64
Encodes a raw byte array into a BASE64 string representation in accordance with RFC 2045.- Parameters:
bytes
- The bytes to convert. If length 0, "" will be returned.- Returns:
- A BASE64 encoded string.
- Since:
- 5.2.21
-
write
Transfers all date from the given input stream to the given output stream and returns the number of transfered bytes. Both input and output stream will be closed when this call returns.- Parameters:
in
- The input stream to read from.out
- The ouput stream to write to.- Returns:
- The number of transfered bytes.
- Throws:
IOException
- Since:
- 5.2.21
-
close
- Parameters:
closables
- the instances to close -null
-values are ignored- Since:
- 5.2.21
-