public class StreamUtils extends Object
Constructor and Description |
---|
StreamUtils() |
Modifier and Type | Method and Description |
---|---|
static long |
copy(InputStream source,
OutputStream destination) |
static void |
copy(InputStream source,
OutputStream destination,
long numBytes)
Copies
numBytes from source to destination . |
static byte[] |
copyExclusive(InputStream in,
OutputStream out,
int maxBytes,
byte[]... stoppers)
Copies data from in to out until either we are out of data (returns null) or we hit one of the byte patterns identified by the
stoppers parameter (returns the byte pattern
matched). |
static byte[] |
copyInclusive(InputStream in,
OutputStream out,
int maxBytes,
byte[]... stoppers)
Copies data from in to out until either we are out of data (returns null) or we hit one of the byte patterns identified by the
stoppers parameter (returns the byte pattern
matched). |
static void |
fillBuffer(InputStream source,
byte[] destination)
Reads data from the given input stream, copying it to the destination byte array.
|
static int |
fillBuffer(InputStream source,
byte[] destination,
boolean ensureCapacity)
Reads data from the given input stream, copying it to the destination byte array.
|
static void |
skip(InputStream stream,
long bytesToSkip)
Skips the specified number of bytes from the InputStream
If unable to skip that number of bytes, throws EOFException
|
public static long copy(InputStream source, OutputStream destination) throws IOException
IOException
public static void copy(InputStream source, OutputStream destination, long numBytes) throws IOException
numBytes
from source
to destination
. If numBytes
are not available from source
, throws EOFExceptionsource
- the source of bytes to copydestination
- the destination to copy bytes tonumBytes
- the number of bytes to copyIOException
- if any issues occur while copyingpublic static void fillBuffer(InputStream source, byte[] destination) throws IOException
source
- the source to copy bytes fromdestination
- the destination to fillIOException
- if any issues occur reading bytespublic static int fillBuffer(InputStream source, byte[] destination, boolean ensureCapacity) throws IOException
ensureCapacity
is true and otherwise returns the number of bytes copiedsource
- the source to read bytes fromdestination
- the destination to fillensureCapacity
- whether or not to enforce that the InputStream have at least as much data as the capacity of the destination byte arrayIOException
- if unable to read from the underlying streampublic static byte[] copyInclusive(InputStream in, OutputStream out, int maxBytes, byte[]... stoppers) throws IOException
stoppers
parameter (returns the byte pattern
matched). The bytes in the stopper will be copied.in
- the source to read bytes fromout
- the destination to write bytes tomaxBytes
- the max bytes to copystoppers
- patterns of bytes which if seen will cause the copy to stopIOException
- if issues occur reading or writing bytes to the underlying streamspublic static byte[] copyExclusive(InputStream in, OutputStream out, int maxBytes, byte[]... stoppers) throws IOException
stoppers
parameter (returns the byte pattern
matched). The byte pattern matched will NOT be copied to the output and will be un-read from the input.in
- the source to read bytes fromout
- the destination to write bytes tomaxBytes
- the maximum number of bytes to copystoppers
- byte patterns which will cause the copy to stop if foundIOException
- for issues reading or writing to underlying streamspublic static void skip(InputStream stream, long bytesToSkip) throws IOException
stream
- the stream to skip overbytesToSkip
- the number of bytes to skipIOException
- if any issues reading or skipping underlying streamCopyright © 2016 Apache NiFi Project. All rights reserved.