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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
static @NotNull String
toBase64
(@org.jetbrains.annotations.NotNull byte[] bytes) Encodes a raw byte array into a BASE64 string representation in accordance with RFC 2045.static @org.jetbrains.annotations.NotNull byte[]
toByteArray
(@NotNull InputStream in) Read the content of an input stream into a byte array.static @NotNull String
toString
(@NotNull InputStream in, @NotNull String encoding) Read the content of the specified input stream and returns the content as string using the specified encoding.static long
write
(@NotNull InputStream in, @NotNull 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
@NotNull public static @org.jetbrains.annotations.NotNull byte[] toByteArray(@NotNull @NotNull InputStream in) throws IOException 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 @NotNull String toString(@NotNull @NotNull InputStream in, @NotNull @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
@NotNull public static @NotNull String toBase64(@NotNull @org.jetbrains.annotations.NotNull byte[] bytes) 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
public static long write(@NotNull @NotNull InputStream in, @NotNull @NotNull OutputStream out) throws IOException 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
-