public abstract class StreamUtils extends 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 | Field and Description |
---|---|
static int |
BUFFER_SIZE |
Constructor and Description |
---|
StreamUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
copy(byte[] in,
OutputStream out)
Copy the contents of the given byte array to the given OutputStream.
|
static int |
copy(InputStream in,
OutputStream out)
Copy the contents of the given InputStream to the given OutputStream.
|
static void |
copy(String in,
Charset charset,
OutputStream out)
Copy the contents of the given String to the given output OutputStream.
|
static long |
copyRange(InputStream in,
OutputStream out,
long start,
long end)
Copy a range of content of the given InputStream to the given OutputStream.
|
static byte[] |
copyToByteArray(InputStream in)
Copy the contents of the given InputStream into a new byte array.
|
static String |
copyToString(InputStream in,
Charset charset)
Copy the contents of the given InputStream into a String.
|
static int |
drain(InputStream in)
Drain the remaining content of the given InputStream.
|
static InputStream |
emptyInput()
Return an efficient empty
InputStream . |
static InputStream |
nonClosing(InputStream in)
Return a variant of the given
InputStream where calling
close() has no effect. |
static OutputStream |
nonClosing(OutputStream out)
Return a variant of the given
OutputStream where calling
close() has no effect. |
public static final int BUFFER_SIZE
public static byte[] copyToByteArray(InputStream in) throws IOException
in
- the stream to copy from (may be null
or empty)IOException
- in case of I/O errorspublic static String copyToString(InputStream in, Charset charset) throws IOException
in
- the InputStream to copy from (may be null
or empty)IOException
- in case of I/O errorspublic static void copy(byte[] in, OutputStream out) throws IOException
in
- the byte array to copy fromout
- the OutputStream to copy toIOException
- in case of I/O errorspublic static void copy(String in, Charset charset, OutputStream out) throws IOException
in
- the String to copy fromcharset
- the Charsetout
- the OutputStream to copy toIOException
- in case of I/O errorspublic static int copy(InputStream in, OutputStream out) throws IOException
in
- the InputStream to copy fromout
- the OutputStream to copy toIOException
- in case of I/O errorspublic static long copyRange(InputStream in, OutputStream out, long start, long end) throws 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 copyingIOException
- in case of I/O errorspublic static int drain(InputStream in) throws IOException
in
- the InputStream to drainIOException
- in case of I/O errorspublic static InputStream emptyInput()
InputStream
.ByteArrayInputStream
based on an empty byte arraypublic static InputStream nonClosing(InputStream in)
InputStream
where calling
close()
has no effect.in
- the InputStream to decoratepublic static OutputStream nonClosing(OutputStream out)
OutputStream
where calling
close()
has no effect.out
- the OutputStream to decorate