Package arc.util.io
Class Streams
java.lang.Object
arc.util.io.Streams
Provides utility methods to copy streams.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA ByteArrayOutputStream which avoids copying of the byte array if possible. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final byte[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClose and ignore all errors.static voidcopy(InputStream input, OutputStream output) Allocates a 8192 byte[] for use as a temporary buffer and callscopy(InputStream, OutputStream, byte[]).static voidcopy(InputStream input, OutputStream output, byte[] buffer) Copy the data from anInputStreamto anOutputStream, using the specified byte[] as a temporary buffer.static voidcopy(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 voidcopy(InputStream input, ByteBuffer output) Allocates a 8192 byte[] for use as a temporary buffer and callscopy(InputStream, OutputStream, byte[]).static intcopy(InputStream input, ByteBuffer output, byte[] buffer) Copy the data from anInputStreamto aByteBuffer, using the specified byte[] as a temporary buffer.static voidcopy(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 anInputStreamto a byte array.static byte[]copyBytes(InputStream input, int estimatedSize) Copy the data from anInputStreamto a byte array.static voidcopyProgress(InputStream input, OutputStream output, long totalLength, int bufferSize, Floatc progress) Copy the data from anInputStreamto anOutputStream, using the specified byte[] as a temporary buffer.static StringcopyString(InputStream input) CallscopyString(InputStream, int, String)using the input'savailablesize and the platform's default charset.static StringcopyString(InputStream input, int estimatedSize) CallscopyString(InputStream, int, String)using the platform's default charset.static StringcopyString(InputStream input, int estimatedSize, String charset) Copy the data from anInputStreamto a string using the specified charset.static byte[]sha256(byte[] bytes)
-
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 8192 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 anInputStreamto 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 anInputStreamto 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 8192 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 anInputStreamto 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 anInputStreamto a byte array. The stream is not closed.- Throws:
IOException
-
copyBytes
Copy the data from anInputStreamto 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'savailablesize 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 anInputStreamto 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. -
sha256
public static byte[] sha256(byte[] bytes) - Returns:
- sha256 hash of provided byte array
-