public abstract class StreamUtils
extends java.lang.Object
FileCopyUtils
except that all affected streams are
left open when done. All copy methods use a block size of 4096 bytes.
Mainly for use within the framework, but also useful for application code.
FileCopyUtils
Modifier and Type | Class and Description |
---|---|
private static class |
StreamUtils.NonClosingInputStream |
private static class |
StreamUtils.NonClosingOutputStream |
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE
The default buffer size used why copying bytes.
|
private static byte[] |
EMPTY_CONTENT |
Constructor and Description |
---|
StreamUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
copy(byte[] in,
java.io.OutputStream out)
Copy the contents of the given byte array to the given OutputStream.
|
static int |
copy(java.io.InputStream in,
java.io.OutputStream out)
Copy the contents of the given InputStream to the given OutputStream.
|
static void |
copy(java.lang.String in,
java.nio.charset.Charset charset,
java.io.OutputStream out)
Copy the contents of the given String to the given output OutputStream.
|
static long |
copyRange(java.io.InputStream in,
java.io.OutputStream out,
long start,
long end)
Copy a range of content of the given InputStream to the given OutputStream.
|
static byte[] |
copyToByteArray(java.io.InputStream in)
Copy the contents of the given InputStream into a new byte array.
|
static java.lang.String |
copyToString(java.io.InputStream in,
java.nio.charset.Charset charset)
Copy the contents of the given InputStream into a String.
|
static int |
drain(java.io.InputStream in)
Drain the remaining content of the given InputStream.
|
static java.io.InputStream |
emptyInput()
Return an efficient empty
InputStream . |
static java.io.InputStream |
nonClosing(java.io.InputStream in)
Return a variant of the given
InputStream where calling
close() has no effect. |
static java.io.OutputStream |
nonClosing(java.io.OutputStream out)
Return a variant of the given
OutputStream where calling
close() has no effect. |
public static final int BUFFER_SIZE
private static final byte[] EMPTY_CONTENT
public static byte[] copyToByteArray(@Nullable java.io.InputStream in) throws java.io.IOException
in
- the stream to copy from (may be null
or empty)java.io.IOException
- in case of I/O errorspublic static java.lang.String copyToString(@Nullable java.io.InputStream in, java.nio.charset.Charset charset) throws java.io.IOException
in
- the InputStream to copy from (may be null
or empty)java.io.IOException
- in case of I/O errorspublic static void copy(byte[] in, java.io.OutputStream out) throws java.io.IOException
in
- the byte array to copy fromout
- the OutputStream to copy tojava.io.IOException
- in case of I/O errorspublic static void copy(java.lang.String in, java.nio.charset.Charset charset, java.io.OutputStream out) throws java.io.IOException
in
- the String to copy fromcharset
- the Charsetout
- the OutputStream to copy tojava.io.IOException
- in case of I/O errorspublic static int copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- the InputStream to copy fromout
- the OutputStream to copy tojava.io.IOException
- in case of I/O errorspublic static long copyRange(java.io.InputStream in, java.io.OutputStream out, long start, long end) throws java.io.IOException
If the specified range exceeds the length of the InputStream, this copies up to the end of the stream and returns the actual number of copied bytes.
Leaves both streams open when done.
in
- the InputStream to copy fromout
- the OutputStream to copy tostart
- the position to start copying fromend
- the position to end copyingjava.io.IOException
- in case of I/O errorspublic static int drain(java.io.InputStream in) throws java.io.IOException
in
- the InputStream to drainjava.io.IOException
- in case of I/O errorspublic static java.io.InputStream emptyInput()
InputStream
.ByteArrayInputStream
based on an empty byte arraypublic static java.io.InputStream nonClosing(java.io.InputStream in)
InputStream
where calling
close()
has no effect.in
- the InputStream to decoratepublic static java.io.OutputStream nonClosing(java.io.OutputStream out)
OutputStream
where calling
close()
has no effect.out
- the OutputStream to decorate