Package software.amazon.awssdk.utils
Class IoUtils
- java.lang.Object
-
- software.amazon.awssdk.utils.IoUtils
-
public final class IoUtils extends Object
Utilities for IO operations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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
drainInputStream(InputStream in)
Read all remaining data in the stream.static void
markStreamWithMaxReadLimit(InputStream s)
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[]
toByteArray(InputStream is)
Reads and returns the rest of the given input stream as a byte array.static String
toUtf8String(InputStream is)
Reads and returns the rest of the given input stream as a string.
-
-
-
Method Detail
-
toByteArray
public static byte[] toByteArray(InputStream is) throws IOException
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
public static String toUtf8String(InputStream is) throws IOException
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
public static void closeQuietly(AutoCloseable is, org.slf4j.Logger log)
Closes the given Closeable quietly.- Parameters:
is
- the given closeablelog
- logger used to log any failure should the close fail
-
closeIfCloseable
public static void closeIfCloseable(Object maybeCloseable, org.slf4j.Logger log)
Closes the given Closeable quietly.- Parameters:
maybeCloseable
- the given closeablelog
- logger used to log any failure should the close fail
-
copy
public static long copy(InputStream in, OutputStream out) throws IOException
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
public static long copy(InputStream in, OutputStream out, long readLimit) throws IOException
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
public static void drainInputStream(InputStream in)
Read all remaining data in the stream.- Parameters:
in
- InputStream to read.
-
markStreamWithMaxReadLimit
public static void markStreamWithMaxReadLimit(InputStream s)
If the stream supports marking, marks the stream at the current position with areadLimit
value of 128 KiB.- Parameters:
s
- The stream.
-
markStreamWithMaxReadLimit
public 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
.- Parameters:
maxReadLimit
- the maxReadLimit, if it's null, 128 KiB will be used.s
- The stream.
-
-