APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.utils

public final Class StreamUtils

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .Closeable, .IOException, .InputStream, .InputStreamReader, .OutputStream, .StringWriter, java.nio.Buffer, .ByteBuffer

Provides utility methods to copy streams.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
StreamUtils.OptimizedByteArrayOutputStream

A ByteArrayOutputStream which avoids copying of the byte array if possible.

Field Summary

Modifier and TypeField and Description
public static final int
public static final byte[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
closeQuietly(Closeable c)

Close and ignore all errors.

public static void
copyStream(InputStream input, OutputStream output)

Allocates a 4096 byte[] for use as a temporary buffer and calls copyStream(InputStream, OutputStream, byte[]).

public static void
copyStream(InputStream input, OutputStream output, int bufferSize)

Allocates a byte[] of the specified size for use as a temporary buffer and calls copyStream(InputStream, OutputStream, byte[]).

public static void
copyStream(InputStream input, OutputStream output, byte[] buffer)

Copy the data from an InputStream to an OutputStream, using the specified byte[] as a temporary buffer.

public static void
copyStream(InputStream input, ByteBuffer output)

Allocates a 4096 byte[] for use as a temporary buffer and calls copyStream(InputStream, OutputStream, byte[]).

public static void
copyStream(InputStream input, ByteBuffer output, int bufferSize)

Allocates a byte[] of the specified size for use as a temporary buffer and calls copyStream(InputStream, ByteBuffer, byte[]).

public static int

Returns:

the number of bytes copied.
copyStream
(InputStream input, ByteBuffer
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.
output
,
byte[] buffer)

Copy the data from an InputStream to a ByteBuffer, using the specified byte[] as a temporary buffer.

public static byte[]
copyStreamToByteArray(InputStream input)

Copy the data from an InputStream to a byte array.

public static byte[]
copyStreamToByteArray(InputStream input, int
Used to allocate the output byte[] to possibly avoid an array copy.
estimatedSize
)

Copy the data from an InputStream to a byte array.

public static String
copyStreamToString(InputStream input)

Calls copyStreamToString(InputStream, int, String) using the input's available size and the platform's default charset.

public static String
copyStreamToString(InputStream input, int estimatedSize)

Calls copyStreamToString(InputStream, int, String) using the platform's default charset.

public static String
copyStreamToString(InputStream input, int
Used to allocate the output buffer to possibly avoid an array copy.
estimatedSize
,
String
May be null to use the platform's default charset.
charset
)

Copy the data from an InputStream to a string using the specified charset.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE
EMPTY_BYTESback to summary
public static final byte[] EMPTY_BYTES

Constructor Detail

StreamUtilsback to summary
public StreamUtils()

Method Detail

closeQuietlyback to summary
public static void closeQuietly(Closeable c)

Close and ignore all errors.

copyStreamback to summary
public static void copyStream(InputStream input, OutputStream output) throws IOException

Allocates a 4096 byte[] for use as a temporary buffer and calls copyStream(InputStream, OutputStream, byte[]).

copyStreamback to summary
public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws IOException

Allocates a byte[] of the specified size for use as a temporary buffer and calls copyStream(InputStream, OutputStream, byte[]).

copyStreamback to summary
public static void copyStream(InputStream input, OutputStream output, byte[] buffer) throws IOException

Copy the data from an InputStream to an OutputStream, using the specified byte[] as a temporary buffer. The stream is not closed.

copyStreamback to summary
public static void copyStream(InputStream input, ByteBuffer output) throws IOException

Allocates a 4096 byte[] for use as a temporary buffer and calls copyStream(InputStream, OutputStream, byte[]).

copyStreamback to summary
public static void copyStream(InputStream input, ByteBuffer output, int bufferSize) throws IOException

Allocates a byte[] of the specified size for use as a temporary buffer and calls copyStream(InputStream, ByteBuffer, byte[]).

copyStreamback to summary
public static int copyStream(InputStream input, ByteBuffer output, byte[] buffer) throws IOException

Copy the data from an InputStream to a ByteBuffer, 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:ByteBuffer

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:int

the number of bytes copied.

copyStreamToByteArrayback to summary
public static byte[] copyStreamToByteArray(InputStream input) throws IOException

Copy the data from an InputStream to a byte array. The stream is not closed.

copyStreamToByteArrayback to summary
public static byte[] copyStreamToByteArray(InputStream input, int estimatedSize) throws IOException

Copy the data from an InputStream to a byte array. The stream is not closed.

Parameters
estimatedSize:int

Used to allocate the output byte[] to possibly avoid an array copy.

copyStreamToStringback to summary
public static String copyStreamToString(InputStream input) throws IOException

Calls copyStreamToString(InputStream, int, String) using the input's available size and the platform's default charset.

copyStreamToStringback to summary
public static String copyStreamToString(InputStream input, int estimatedSize) throws IOException

Calls copyStreamToString(InputStream, int, String) using the platform's default charset.

copyStreamToStringback to summary
public static String copyStreamToString(InputStream input, int estimatedSize, String charset) throws IOException

Copy the data from an InputStream to a string using the specified charset.

Parameters
estimatedSize:int

Used to allocate the output buffer to possibly avoid an array copy.

charset:String

May be null to use the platform's default charset.

com.badlogic.gdx.utils back to summary

public Class StreamUtils.OptimizedByteArrayOutputStream

extends ByteArrayOutputStream
Class Inheritance

A ByteArrayOutputStream which avoids copying of the byte array if possible.

Field Summary

Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public byte[]
public synchronized byte[]
toByteArray()

Overrides java.io.ByteArrayOutputStream.toByteArray.

Creates a newly allocated byte array.

Inherited from java.io.ByteArrayOutputStream:
closeresetsizetoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Constructor Detail

OptimizedByteArrayOutputStreamback to summary
public OptimizedByteArrayOutputStream(int initialSize)

Method Detail

getBufferback to summary
public byte[] getBuffer()
toByteArrayback to summary
public synchronized byte[] toByteArray()

Overrides java.io.ByteArrayOutputStream.toByteArray.

Doc from java.io.ByteArrayOutputStream.toByteArray.

Creates a newly allocated byte array. Its size is the current size of this output stream and the valid contents of the buffer have been copied into it.

Annotations
@Override