Package arc.util.io
Class Streams
java.lang.Object
arc.util.io.Streams
Provides utility methods to copy streams.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A ByteArrayOutputStream which avoids copying of the byte array if possible. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final byte[]
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Close and ignore all errors.static void
copy
(InputStream input, OutputStream output) Allocates a 4096 byte[] for use as a temporary buffer and callscopy(InputStream, OutputStream, byte[])
.static void
copy
(InputStream input, OutputStream output, byte[] buffer) Copy the data from anInputStream
to anOutputStream
, using the specified byte[] as a temporary buffer.static void
copy
(InputStream input, OutputStream output, int bufferSize) Allocates a byte[] of the specified size for use as a temporary buffer and callscopy(InputStream, OutputStream, byte[])
.static void
copy
(InputStream input, ByteBuffer output) Allocates a 4096 byte[] for use as a temporary buffer and callscopy(InputStream, OutputStream, byte[])
.static int
copy
(InputStream input, ByteBuffer output, byte[] buffer) Copy the data from anInputStream
to aByteBuffer
, using the specified byte[] as a temporary buffer.static void
copy
(InputStream input, ByteBuffer output, int bufferSize) Allocates a byte[] of the specified size for use as a temporary buffer and callscopy(InputStream, ByteBuffer, byte[])
.static byte[]
copyBytes
(InputStream input) Copy the data from anInputStream
to a byte array.static byte[]
copyBytes
(InputStream input, int estimatedSize) Copy the data from anInputStream
to a byte array.static void
copyProgress
(InputStream input, OutputStream output, long totalLength, int bufferSize, Floatc progress) Copy the data from anInputStream
to anOutputStream
, using the specified byte[] as a temporary buffer.static String
copyString
(InputStream input) CallscopyString(InputStream, int, String)
using the input'savailable
size and the platform's default charset.static String
copyString
(InputStream input, int estimatedSize) CallscopyString(InputStream, int, String)
using the platform's default charset.static String
copyString
(InputStream input, int estimatedSize, String charset) Copy the data from anInputStream
to a string using the specified charset.
-
Field Details
-
defaultBufferSize
public static final int defaultBufferSize- See Also:
-
emptyBytes
public static final byte[] emptyBytes
-
-
Constructor Details
-
Streams
public Streams()
-
-
Method Details
-
copy
Allocates a 4096 byte[] for use as a temporary buffer and callscopy(InputStream, OutputStream, byte[])
.- Throws:
IOException
-
copy
Allocates a byte[] of the specified size for use as a temporary buffer and callscopy(InputStream, OutputStream, byte[])
.- Throws:
IOException
-
copy
Copy the data from anInputStream
to anOutputStream
, using the specified byte[] as a temporary buffer. The stream is not closed.- Throws:
IOException
-
copyProgress
public static void copyProgress(InputStream input, OutputStream output, long totalLength, int bufferSize, Floatc progress) throws IOException Copy the data from anInputStream
to anOutputStream
, using the specified byte[] as a temporary buffer. The stream is not closed. Provides progress as a 0-1 value through the specified listener.- Parameters:
totalLength
- the total byte length of the input.- Throws:
IOException
-
copy
Allocates a 4096 byte[] for use as a temporary buffer and callscopy(InputStream, OutputStream, byte[])
.- Throws:
IOException
-
copy
Allocates a byte[] of the specified size for use as a temporary buffer and callscopy(InputStream, ByteBuffer, byte[])
.- Throws:
IOException
-
copy
Copy the data from anInputStream
to aByteBuffer
, using the specified byte[] as a temporary buffer. The buffer's limit is increased by the number of bytes copied, the position is left unchanged. The stream is not closed.- Parameters:
output
- Must be a direct Buffer with native byte order and the buffer MUST be large enough to hold all the bytes in the stream. No error checking is performed.- Returns:
- the number of bytes copied.
- Throws:
IOException
-
copyBytes
Copy the data from anInputStream
to a byte array. The stream is not closed.- Throws:
IOException
-
copyBytes
Copy the data from anInputStream
to a byte array. The stream is not closed.- Parameters:
estimatedSize
- Used to allocate the output byte[] to possibly avoid an array copy.- Throws:
IOException
-
copyString
CallscopyString(InputStream, int, String)
using the input'savailable
size and the platform's default charset.- Throws:
IOException
-
copyString
CallscopyString(InputStream, int, String)
using the platform's default charset.- Throws:
IOException
-
copyString
public static String copyString(InputStream input, int estimatedSize, String charset) throws IOException Copy the data from anInputStream
to a string using the specified charset.- Parameters:
estimatedSize
- Used to allocate the output buffer to possibly avoid an array copy.charset
- May be null to use the platform's default charset.- Throws:
IOException
-
close
Close and ignore all errors.
-