public class RandomAccessOutputStream extends OutputStream
Instead of allocating a single large byte array this implementation tracks a group of (increasing in size) buffers. This should reduce the runtime cost of buffer reallocations since it avoids the copy of contents from one buffer to another.
Modifier and Type | Field and Description |
---|---|
static Charset |
UTF8
UTF-8 Character set for encoding strings.
|
Constructor and Description |
---|
RandomAccessOutputStream()
Creates a new
RandomAccessOutputStream . |
RandomAccessOutputStream(StringEncoderCache cache)
Creates a new
RandomAccessOutputStream . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
int |
getMaxCachedStringEntries()
Deprecated.
The cache
StringEncoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
int |
getMaxCachedStringLength()
Deprecated.
The cache
StringEncoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
long |
getPosition()
Returns the current position in the stream.
|
long |
getSize()
Returns the number of bytes written to the stream.
|
protected void |
nextBuffer()
Allocates a new buffer to use.
|
void |
reset()
Resets the
size of the buffer to zero. |
void |
setMaxCachedStringEntries(int maxCacheEntries)
Deprecated.
The cache
StringEncoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
void |
setMaxCachedStringLength(int maxlength)
Deprecated.
The cache
StringEncoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
void |
write(byte[] buffer) |
void |
write(byte[] buffer,
int offset,
int length) |
void |
write(int b) |
void |
writeAt(long position,
byte[] buffer)
Similar to
write(byte[]) but allows a portion of the already
written buffer to be re-written. |
void |
writeAt(long position,
byte[] buffer,
int offset,
int length)
Similar to
write(byte[], int, int) but allows a portion of the
already written buffer to be re-written. |
void |
writeAt(long position,
int b)
Similar to
write(int) but allows a portion of the already
written buffer to be re-written. |
void |
writeByte(byte b)
Writes a single byte to the stream.
|
void |
writeBytes(byte[] data)
Writes a sequence of bytes to the under lying stream.
|
void |
writeCString(String... strings)
Writes a "Cstring" to the stream.
|
void |
writeInt(int value)
Write the integer value in little-endian byte order.
|
void |
writeIntAt(long position,
int value)
Write the integer value in little-endian byte order at the specified
position in the stream.
|
void |
writeLong(long value)
Write the long value in little-endian byte order.
|
void |
writeString(String string)
Writes a "string" to the stream.
|
void |
writeTo(OutputStream out)
Writes the complete contents of this byte array output stream to the
specified output stream argument, as if by calling the output stream's
write method using
out.write(buf, 0, count) . |
public static final Charset UTF8
public RandomAccessOutputStream()
RandomAccessOutputStream
.public RandomAccessOutputStream(StringEncoderCache cache)
RandomAccessOutputStream
.cache
- The cache for encoding string.public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
public void flush()
flush
in interface Flushable
flush
in class OutputStream
@Deprecated public int getMaxCachedStringEntries()
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.@Deprecated public int getMaxCachedStringLength()
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.public long getPosition()
getSize()
.public long getSize()
public void reset()
size
of the buffer to zero. All buffers can be
re-used.@Deprecated public void setMaxCachedStringEntries(int maxCacheEntries)
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.maxCacheEntries
- The new value for the maximum number of strings that may have
their encoded form cached.@Deprecated public void setMaxCachedStringLength(int maxlength)
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.maxlength
- The new value for the length for a string that the encoder is
allowed to cache.public void write(byte[] buffer)
write
in class OutputStream
buffer
- the data.public void write(byte[] buffer, int offset, int length)
write
in class OutputStream
buffer
- the data.offset
- the start offset in the data.length
- the number of bytes to write.public void write(int b)
write
in class OutputStream
public void writeAt(long position, byte[] buffer)
write(byte[])
but allows a portion of the already
written buffer to be re-written.
Equivalent to writeAt(position, buffer, 0, buffer.length);
.
position
- The position to write at. This location should have already
been written.buffer
- the data.public void writeAt(long position, byte[] buffer, int offset, int length)
write(byte[], int, int)
but allows a portion of the
already written buffer to be re-written.position
- The position to write at. This location should have already
been written.buffer
- the data.offset
- the start offset in the data.length
- the number of bytes to write.public void writeAt(long position, int b)
write(int)
but allows a portion of the already
written buffer to be re-written.position
- The position to write at. This location should have already
been written.b
- The byte value to write.public void writeByte(byte b)
b
- The byte to write.public void writeBytes(byte[] data)
data
- The bytes to write.public void writeCString(String... strings)
strings
- The CString to write. The strings are concatenated into a
single CString value.public void writeInt(int value)
value
- The integer to write.public void writeIntAt(long position, int value)
position
- The position in the stream to write the integer.value
- The long to write.public void writeLong(long value)
value
- The long to write.public void writeString(String string)
string
- The String to write.public void writeTo(OutputStream out) throws IOException
out.write(buf, 0, count)
.out
- the output stream to which to write the data.IOException
- if an I/O error occurs.protected void nextBuffer()
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.