public final class StreamUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
CLOSE_INPUT
An option for transfer().
|
static int |
CLOSE_OUTPUT
An option for transfer().
|
static int |
DONT_CLOSE_IF_ABORTED
An option for transfer().
|
static int |
DONT_STOP_AFTER_KNOWN_SIZE
An option for transfer().
|
| Modifier and Type | Method and Description |
|---|---|
static ByteArray |
readAllBytes(Handle h,
InputStream in,
ByteArray dest)
Read all the bytes from an InputStream, placing them in a ByteArray.
|
static ByteArray |
readAllBytes(Handle h,
InputStream in,
ByteArray dest,
long knownSize,
int optionsAndBufferSize)
Read all the bytes from an InputStream, placing them in a ByteArray.
|
static Handle |
readAllBytes(InputStream in,
ByteArray dest)
Read all the bytes in a separate thread.
|
static Handle |
readAllBytes(InputStream in,
ByteArray dest,
long knownSize,
int optionsAndBufferSize)
Read all the bytes in a separate thread.
|
static void |
readFully(InputStream in,
byte[] dest)
Reads in all the bytes of an array.
|
static void |
readFully(InputStream in,
byte[] dest,
int start,
int count)
Reads in exactly a certain number of bytes.
|
static long |
transfer(Handle h,
InputStream in,
OutputStream out)
Transfer data from an InputStream to an OutputStream.
|
static long |
transfer(Handle h,
InputStream in,
OutputStream out,
long knownSize,
int optionsAndBufferSize)
Transfer data from an InputStream to an OutputStream.
|
static long |
transfer(Handle h,
Reader in,
Writer out,
long knownSize,
int optionsAndBufferSize)
Transfer data from a Reader to a Writer.
|
static Handle |
transfer(InputStream in,
OutputStream out)
Transfer data from an InputStream to an OutputStream in a separate thread.
|
static Handle |
transfer(InputStream in,
OutputStream out,
boolean closeStreams)
Transfer data from an InputStream to an OutputStream in a separate thread.
|
static Handle |
transfer(InputStream in,
OutputStream out,
long knownSize,
int optionsAndBufferSize)
Transfer data from an InputStream to an OutputStream in a separate thread.
|
static Handle |
transfer(Reader in,
Writer out)
Transfer data from a Reader to a Writer in a separate thread.
|
static Handle |
transfer(Reader in,
Writer out,
long knownSize,
int optionsAndBufferSize)
Transfer data from a Reader to a Writer in a separate thread.
|
public static final int CLOSE_INPUT
public static final int CLOSE_OUTPUT
public static final int DONT_STOP_AFTER_KNOWN_SIZE
public static final int DONT_CLOSE_IF_ABORTED
public static void readFully(InputStream in, byte[] dest, int start, int count) throws IOException, EOFException
in - The InputStreamdest - The destination for the input data bytes.start - The offset in the dest to read from.count - The number of bytes to read.IOException - If an I/O error occurs.EOFException - If the stream ends before all the bytes are read.public static void readFully(InputStream in, byte[] dest) throws IOException, EOFException
in - The InputStreamdest - The destination for the input data bytes.IOExceptionEOFExceptionpublic static long transfer(Handle h, InputStream in, OutputStream out, long knownSize, int optionsAndBufferSize) throws IOException
h - an optional handle that can be used by another Thread to monitor and cancel the transfer.in - the InputStream.out - the OutputStream.knownSize - If the number of bytes is known, set this to be that value. Otherwise set it to -1.optionsAndBufferSize - any of CLOSE_INPUT|CLOSE_OUTPUT|DONT_STOP_AFTER_KNOWN_SIZE OR'ed with
an optional buffer size specified in Kilobytes. e.g. CLOSE_INPUT|CLOSE_OUTPUT|10IOException - if an IOException occurs.public static long transfer(Handle h, InputStream in, OutputStream out) throws IOException
h - an optional handle that can be used by another Thread to monitor and cancel the transfer.in - the InputStream.out - the OutputStream.IOException - if an IOException occurs.public static Handle transfer(InputStream in, OutputStream out, long knownSize, int optionsAndBufferSize)
in - the InputStream.out - the OutputStream.knownSize - If the number of bytes is known, set this to be that value. Otherwise set it to -1.optionsAndBufferSize - any of CLOSE_INPUT|CLOSE_OUTPUT|DONT_STOP_AFTER_KNOWN_SIZE OR'ed with
an optional buffer size specified in Kilobytes. e.g. CLOSE_INPUT|CLOSE_OUTPUT|10public static Handle transfer(InputStream in, OutputStream out)
in - the InputStream.out - the OutputStream.public static Handle transfer(InputStream in, OutputStream out, boolean closeStreams)
in - the InputStream.out - the OutputStream.closeStreams - - close the streams on completion.public static ByteArray readAllBytes(Handle h, InputStream in, ByteArray dest, long knownSize, int optionsAndBufferSize) throws IOException
h - an optional handle that can be used by another Thread to monitor and cancel the transfer.in - The input stream.dest - An optional destination ByteArray.knownSize - If the size is known then set this to be that size. If it is not known then set it to -1.optionsAndBufferSize - any of CLOSE_INPUT|CLOSE_OUTPUT|DONT_STOP_AFTER_KNOWN_SIZE OR'ed with
an optional buffer size specified in Kilobytes. e.g. CLOSE_INPUT|CLOSE_OUTPUT|10IOException - if an IOException occurs.public static ByteArray readAllBytes(Handle h, InputStream in, ByteArray dest) throws IOException
h - an optional handle that can be used by another Thread to monitor and cancel the transfer.in - The input stream.dest - An optional destination ByteArray.IOException - if an IOException occurs.public static Handle readAllBytes(InputStream in, ByteArray dest, long knownSize, int optionsAndBufferSize)
in - The input stream.dest - An optional destination ByteArray.knownSize - If the size is known then set this to be that size. If it is not known then set it to -1.optionsAndBufferSize - any of CLOSE_INPUT|CLOSE_OUTPUT|DONT_STOP_AFTER_KNOWN_SIZE OR'ed with
an optional buffer size specified in Kilobytes. e.g. CLOSE_INPUT|CLOSE_OUTPUT|10public static Handle readAllBytes(InputStream in, ByteArray dest)
in - The input stream.dest - An optional destination ByteArray.public static long transfer(Handle h, Reader in, Writer out, long knownSize, int optionsAndBufferSize) throws IOException
h - an optional handle that can be used by another Thread to monitor and cancel the transfer.in - the Reader.out - the Writer.knownSize - If the number of bytes is known, set this to be that value. Otherwise set it to -1.optionsAndBufferSize - any of CLOSE_INPUT|CLOSE_OUTPUT|DONT_STOP_AFTER_KNOWN_SIZE OR'ed with
an optional buffer size specified in Kilobytes. e.g. CLOSE_INPUT|CLOSE_OUTPUT|10IOException - if an IOException occurs.public static Handle transfer(Reader in, Writer out, long knownSize, int optionsAndBufferSize)
in - the Reader.out - the Writer.knownSize - If the number of bytes is known, set this to be that value. Otherwise set it to -1.optionsAndBufferSize - any of CLOSE_INPUT|CLOSE_OUTPUT|DONT_STOP_AFTER_KNOWN_SIZE OR'ed with
an optional buffer size specified in Kilobytes. e.g. CLOSE_INPUT|CLOSE_OUTPUT|10public static Handle transfer(Reader in, Writer out)
in - the Reader.out - the Writer.