Package com.badlogic.gdx.utils
Class StreamUtils
- java.lang.Object
-
- com.badlogic.gdx.utils.StreamUtils
-
public final class StreamUtils extends java.lang.ObjectProvides utility methods to copy streams.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStreamUtils.OptimizedByteArrayOutputStreamA ByteArrayOutputStream which avoids copying of the byte array if possible.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEstatic byte[]EMPTY_BYTES
-
Constructor Summary
Constructors Constructor Description StreamUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseQuietly(java.io.Closeable c)Close and ignore all errors.static voidcopyStream(java.io.InputStream input, java.io.OutputStream output)Allocates a 4096 byte[] for use as a temporary buffer and callscopyStream(InputStream, OutputStream, byte[]).static voidcopyStream(java.io.InputStream input, java.io.OutputStream output, byte[] buffer)Copy the data from anInputStreamto anOutputStream, using the specified byte[] as a temporary buffer.static voidcopyStream(java.io.InputStream input, java.io.OutputStream output, int bufferSize)Allocates a byte[] of the specified size for use as a temporary buffer and callscopyStream(InputStream, OutputStream, byte[]).static voidcopyStream(java.io.InputStream input, java.nio.ByteBuffer output)Allocates a 4096 byte[] for use as a temporary buffer and callscopyStream(InputStream, OutputStream, byte[]).static intcopyStream(java.io.InputStream input, java.nio.ByteBuffer output, byte[] buffer)Copy the data from anInputStreamto aByteBuffer, using the specified byte[] as a temporary buffer.static voidcopyStream(java.io.InputStream input, java.nio.ByteBuffer output, int bufferSize)Allocates a byte[] of the specified size for use as a temporary buffer and callscopyStream(InputStream, ByteBuffer, byte[]).static byte[]copyStreamToByteArray(java.io.InputStream input)Copy the data from anInputStreamto a byte array.static byte[]copyStreamToByteArray(java.io.InputStream input, int estimatedSize)Copy the data from anInputStreamto a byte array.static java.lang.StringcopyStreamToString(java.io.InputStream input)CallscopyStreamToString(InputStream, int, String)using the input'savailablesize and the platform's default charset.static java.lang.StringcopyStreamToString(java.io.InputStream input, int estimatedSize)CallscopyStreamToString(InputStream, int, String)using the platform's default charset.static java.lang.StringcopyStreamToString(java.io.InputStream input, int estimatedSize, java.lang.String charset)Copy the data from anInputStreamto a string using the specified charset.
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
EMPTY_BYTES
public static final byte[] EMPTY_BYTES
-
-
Method Detail
-
copyStream
public static void copyStream(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOExceptionAllocates a 4096 byte[] for use as a temporary buffer and callscopyStream(InputStream, OutputStream, byte[]).- Throws:
java.io.IOException
-
copyStream
public static void copyStream(java.io.InputStream input, java.io.OutputStream output, int bufferSize) throws java.io.IOExceptionAllocates a byte[] of the specified size for use as a temporary buffer and callscopyStream(InputStream, OutputStream, byte[]).- Throws:
java.io.IOException
-
copyStream
public static void copyStream(java.io.InputStream input, java.io.OutputStream output, byte[] buffer) throws java.io.IOExceptionCopy the data from anInputStreamto anOutputStream, using the specified byte[] as a temporary buffer. The stream is not closed.- Throws:
java.io.IOException
-
copyStream
public static void copyStream(java.io.InputStream input, java.nio.ByteBuffer output) throws java.io.IOExceptionAllocates a 4096 byte[] for use as a temporary buffer and callscopyStream(InputStream, OutputStream, byte[]).- Throws:
java.io.IOException
-
copyStream
public static void copyStream(java.io.InputStream input, java.nio.ByteBuffer output, int bufferSize) throws java.io.IOExceptionAllocates a byte[] of the specified size for use as a temporary buffer and callscopyStream(InputStream, ByteBuffer, byte[]).- Throws:
java.io.IOException
-
copyStream
public static int copyStream(java.io.InputStream input, java.nio.ByteBuffer output, byte[] buffer) throws java.io.IOExceptionCopy 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:
java.io.IOException
-
copyStreamToByteArray
public static byte[] copyStreamToByteArray(java.io.InputStream input) throws java.io.IOExceptionCopy the data from anInputStreamto a byte array. The stream is not closed.- Throws:
java.io.IOException
-
copyStreamToByteArray
public static byte[] copyStreamToByteArray(java.io.InputStream input, int estimatedSize) throws java.io.IOExceptionCopy 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:
java.io.IOException
-
copyStreamToString
public static java.lang.String copyStreamToString(java.io.InputStream input) throws java.io.IOExceptionCallscopyStreamToString(InputStream, int, String)using the input'savailablesize and the platform's default charset.- Throws:
java.io.IOException
-
copyStreamToString
public static java.lang.String copyStreamToString(java.io.InputStream input, int estimatedSize) throws java.io.IOExceptionCallscopyStreamToString(InputStream, int, String)using the platform's default charset.- Throws:
java.io.IOException
-
copyStreamToString
public static java.lang.String copyStreamToString(java.io.InputStream input, int estimatedSize, @Null java.lang.String charset) throws java.io.IOExceptionCopy 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:
java.io.IOException
-
closeQuietly
public static void closeQuietly(java.io.Closeable c)
Close and ignore all errors.
-
-