public final class IO extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_TMP_FILE_LIMIT
1 GiB.
|
static int |
DEFAULT_TMP_INIT_LENGTH
8 KiB.
|
static int |
DEFAULT_TMP_MEMORY_LIMIT
64 KiB.
|
Modifier and Type | Method and Description |
---|---|
static BranchingInputStream |
newBranchingInputStream(byte[] bytes)
Creates a new branching input stream that wraps a byte array.
|
static BranchingInputStream |
newBranchingInputStream(InputStream in,
Factory<Buffer> bufferFactory)
Creates a new branching input stream to wrap another input stream.
|
static Buffer |
newFileBuffer(File file,
int limit)
Creates a new file buffer that uses a local file for data storage.
|
static Buffer |
newMemoryBuffer(int initial,
int limit)
Creates a new buffer that uses a byte array for data storage.
|
static Buffer |
newTemporaryBuffer(int initialLength,
int memoryLimit,
int fileLimit,
File directory)
Creates a new temporary buffer that first uses memory, then a temporary
file for data storage.
|
static Factory<Buffer> |
newTemporaryStorage()
Creates a new storage using the system dependent default temporary
directory and default sizes.
|
static Factory<Buffer> |
newTemporaryStorage(File directory)
Builds a storage using the given directory (may be null) and
default sizes.
|
static Factory<Buffer> |
newTemporaryStorage(File directory,
int initialLength,
int memoryLimit,
int fileLimit)
Builds a storage using the given directory (may be null) and
provided sizes.
|
static InputStream |
nullInputStream()
Returns an input stream that holds no data.
|
static OutputStream |
nullOutputStream()
Returns an output stream that discards all data written to it.
|
static void |
stream(InputStream in,
OutputStream out)
Streams all data from an input stream to an output stream.
|
static void |
stream(InputStream in,
OutputStream out,
boolean forceFlush)
Streams all data from an input stream to an output stream.
|
static int |
stream(InputStream in,
OutputStream out,
int len)
Streams data from an input stream to an output stream, up to a specified
length.
|
static void |
stream(Reader in,
Writer out)
Streams all characters from a reader to a writer.
|
public static final int DEFAULT_TMP_INIT_LENGTH
public static final int DEFAULT_TMP_MEMORY_LIMIT
public static final int DEFAULT_TMP_FILE_LIMIT
public static BranchingInputStream newBranchingInputStream(byte[] bytes)
bytes
- byte array to wrap with the branching input stream.public static BranchingInputStream newBranchingInputStream(InputStream in, Factory<Buffer> bufferFactory)
If the stream being wrapped is a branching input stream, this constructor will simply branch off of that existing stream rather than wrapping it with another branching input stream.
Note: This stream and any branches it creates are not safe for use by multiple concurrent threads.
in
- the stream to be wrapped.bufferFactory
- an object that can create new temporary buffers (e.g. @link
TemporaryStorage}).public static Buffer newFileBuffer(File file, int limit) throws FileNotFoundException
Note: The returned buffer is not synchronized. If multiple threads access a buffer concurrently, threads that append to the buffer should synchronize on the instance of this object.
file
- the file to use as storage for the buffer.limit
- the buffer length limit, after which an
OverflowException
will be thrown.FileNotFoundException
- if the file cannot be created or opened for writing.SecurityException
- if a security manager denies access to the specified file.public static Buffer newMemoryBuffer(int initial, int limit)
Note: The returned buffer is not synchronized. If multiple threads access a buffer concurrently, threads that append to the buffer should synchronize on the instance of this object.
initial
- the initial size of the byte array to create.limit
- the buffer length limit, after which an
OverflowException
will be thrown.public static Buffer newTemporaryBuffer(int initialLength, int memoryLimit, int fileLimit, File directory)
memory
buffer is used; when the memory buffer limit is exceeded it
promotes to the use of a file
buffer.initialLength
- the initial length of memory buffer byte array.memoryLimit
- the length limit of the memory buffer.fileLimit
- the length limit of the file buffer.directory
- the directory where temporary files are created, or
null
to use the system-dependent default temporary
directory.public static Factory<Buffer> newTemporaryStorage()
newTemporaryStorage(null)
.public static Factory<Buffer> newTemporaryStorage(File directory)
newTemporaryStorage(directory, HEIGHT_KB, SIXTY_FOUR_KB, ONE_MB)
.directory
- The directory where temporary files are created. If
null
, then the system-dependent default temporary
directory will be used.public static Factory<Buffer> newTemporaryStorage(File directory, int initialLength, int memoryLimit, int fileLimit)
directory
- The directory where temporary files are created. If
null
, then the system-dependent default temporary
directory will be used.initialLength
- The initial length of memory buffer byte array.memoryLimit
- The length limit of the memory buffer. Attempts to exceed this
limit will result in promoting the buffer from a memory to a
file buffer.fileLimit
- The length limit of the file buffer. Attempts to exceed this
limit will result in an OverflowException
being
thrown.public static InputStream nullInputStream()
public static OutputStream nullOutputStream()
public static void stream(InputStream in, OutputStream out) throws IOException
in
- the input stream to stream the data from.out
- the output stream to stream the data to.IOException
- if an I/O exception occurs.public static void stream(InputStream in, OutputStream out, boolean forceFlush) throws IOException
in
- the input stream to stream the data from.out
- the output stream to stream the data to.forceFlush
- flush the output stream after each buffer is written.IOException
- if an I/O exception occurs.public static int stream(InputStream in, OutputStream out, int len) throws IOException
in
- the input stream to stream the data from.out
- the output stream to stream the data to.len
- the number of bytes to stream.IOException
- if an I/O exception occurs.public static void stream(Reader in, Writer out) throws IOException
in
- reader to stream the characters from.out
- the writer to stream the characters to.IOException
- if an I/O exception occurs.Copyright © 2010-2018, ForgeRock All Rights Reserved.