public class StreamUtils extends Object
Constructor and Description |
---|
StreamUtils() |
Modifier and Type | Method and Description |
---|---|
static long |
copyAndClose(InputStream is,
OutputStream os)
Copy from `is` to `os` and close the streams regardless of the result.
|
static long |
copyToFileAndClose(InputStream is,
File file)
Copy from an input stream to a file (and buffer it) and close the input stream.
|
static long |
retryCopy(com.google.common.io.ByteSource byteSource,
com.google.common.io.ByteSink byteSink,
com.google.common.base.Predicate<Throwable> shouldRetry,
int maxAttempts)
Retry copy attempts from input stream to output stream.
|
public static long copyToFileAndClose(InputStream is, File file) throws IOException
It is highly recommended to use FileUtils.retryCopy whenever possible, and not use a raw `InputStream`
is
- The input stream to copy bytes from. `is` is closed regardless of the copy result.file
- The file to copy bytes to. Any parent directories are automatically created.IOException
public static long copyAndClose(InputStream is, OutputStream os) throws IOException
is
- The `InputStream` to copy results from. It is closedos
- The `OutputStream` to copy results to. It is closedIOException
public static long retryCopy(com.google.common.io.ByteSource byteSource, com.google.common.io.ByteSink byteSink, com.google.common.base.Predicate<Throwable> shouldRetry, int maxAttempts)
byteSource
- Supplier for input streams to copy from. The stream is closed on every retry.byteSink
- Supplier for output streams. The stream is closed on every retry.shouldRetry
- Predicate to determine if the throwable is recoverable for a retrymaxAttempts
- Maximum number of retries before failingCopyright © 2011–2023 The Apache Software Foundation. All rights reserved.