Package software.amazon.awssdk.utils
Class IoUtils
java.lang.Object
software.amazon.awssdk.utils.IoUtils
Utilities for IO operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
closeIfCloseable
(Object maybeCloseable, org.slf4j.Logger log) Closes the given Closeable quietly.static void
closeQuietly
(AutoCloseable is, org.slf4j.Logger log) Closes the given Closeable quietly.static long
copy
(InputStream in, OutputStream out) Copies all bytes from the given input stream to the given output stream.static long
copy
(InputStream in, OutputStream out, long readLimit) Copies all bytes from the given input stream to the given output stream.static void
Read all remaining data in the stream.static void
If the stream supports marking, marks the stream at the current position with areadLimit
value of 128 KiB.static void
markStreamWithMaxReadLimit
(InputStream s, Integer maxReadLimit) If the stream supports marking, marks the stream at the current position with a read limit specified inmaxReadLimit
.static byte[]
Reads and returns the rest of the given input stream as a byte array.static String
Reads and returns the rest of the given input stream as a string.
-
Method Details
-
toByteArray
Reads and returns the rest of the given input stream as a byte array. Caller is responsible for closing the given input stream.- Throws:
IOException
-
toUtf8String
Reads and returns the rest of the given input stream as a string. Caller is responsible for closing the given input stream.- Throws:
IOException
-
closeQuietly
Closes the given Closeable quietly.- Parameters:
is
- the given closeablelog
- logger used to log any failure should the close fail
-
closeIfCloseable
Closes the given Closeable quietly.- Parameters:
maybeCloseable
- the given closeablelog
- logger used to log any failure should the close fail
-
copy
Copies all bytes from the given input stream to the given output stream. Caller is responsible for closing the streams.- Throws:
IOException
- if there is any IO exception during read or write.
-
copy
Copies all bytes from the given input stream to the given output stream. Caller is responsible for closing the streams.- Throws:
IOException
- if there is any IO exception during read or write or the read limit is exceeded.
-
drainInputStream
Read all remaining data in the stream.- Parameters:
in
- InputStream to read.
-
markStreamWithMaxReadLimit
If the stream supports marking, marks the stream at the current position with areadLimit
value of 128 KiB.- Parameters:
s
- The stream.
-
markStreamWithMaxReadLimit
If the stream supports marking, marks the stream at the current position with a read limit specified inmaxReadLimit
.- Parameters:
s
- The stream.maxReadLimit
- the maxReadLimit, if it's null, 128 KiB will be used.
-