|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream net.wimpi.modbus.io.FastByteArrayOutputStream
public class FastByteArrayOutputStream
This class is a clean room implementation of the ByteArrayOutputStream, with enhancements for speed (no synchronization for example).
The idea for such an implementation was originally obtained from Berkeley DB JE, however, this represents a clean-room implementation that is NOT derived from their implementation for license reasons and differs in implementation considerably. For compatibility reasons we have tried to conserve the interface as much as possible.
Field Summary | |
---|---|
static int |
DEFAULT_SIZE
|
Constructor Summary | |
---|---|
FastByteArrayOutputStream()
Create a new FastByteArrayOutputStream. |
|
FastByteArrayOutputStream(byte[] buf)
Create a new FastByteArrayOutputStream with a given initial buffer. |
|
FastByteArrayOutputStream(int bufferSize)
Create a new FastByteArrayOutputStream with a given initial buffer size. |
Method Summary | |
---|---|
void |
close()
Closing a FastByteArrayOutputStream has no effect. |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this FastByteArrayOutputStreams buffer, if necessary, to ensure that it can hold at least the number of bytes specified by the minimum capacity argument. |
byte[] |
getBuffer()
Returns a reference to the buffer of this FastByteArrayOutputStream. |
void |
reset()
Resets the count of this FastByteArrayOutputStream to zero, so that all currently accumulated output in the ouput stream is discarded when overwritten. |
int |
size()
Returns the current number of bytes in the buffer of this FastByteArrayOutputStream. |
byte[] |
toByteArray()
Returns a newly allocated byte[] with the actual content of the buffer of this FastByteArrayOutputStream. |
void |
toByteArray(byte[] b,
int offset)
Copies the content of this FastByteArrayOutputStream into the given byte array, starting from the given offset. |
String |
toString()
Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding. |
String |
toString(String enc)
Converts the buffer's contents into a string, translating bytes into characters according to the specified character encoding. |
void |
write(byte[] buf)
Convenience method that writes all bytes from the specified byte array to this FastByteArrayOutputStream. |
void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array starting at offset off to this FastByteArrayOutputStream. |
void |
write(int b)
Writes the specified byte to this byte array output stream. |
void |
writeTo(OutputStream out)
Writes the complete contents of this FastByteArrayOutputStream to the specified output stream argument. |
Methods inherited from class java.io.OutputStream |
---|
flush |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_SIZE
Constructor Detail |
---|
public FastByteArrayOutputStream()
DEFAULT_SIZE
will be used.
public FastByteArrayOutputStream(int bufferSize)
bufferSize
- the initial size of the buffer as int.public FastByteArrayOutputStream(byte[] buf)
buf
- the buffer as byte[].Method Detail |
---|
public void close()
close
in interface Closeable
close
in class OutputStream
public void reset()
public int size()
public byte[] toByteArray()
size()
public String toString()
toString
in class Object
public String toString(String enc) throws UnsupportedEncodingException
enc
- a character-encoding name.
UnsupportedEncodingException
- If the named encoding is not supported.public void write(byte[] b, int off, int len)
write
in class OutputStream
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.public void write(int b)
write
in class OutputStream
b
- the byte to be written.public void writeTo(OutputStream out) throws IOException
out
- the output stream to which to write the data.
IOException
- if an I/O error occurs.public void write(byte[] buf) throws IOException
write
in class OutputStream
buf
-
IOException
public final void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public void toByteArray(byte[] b, int offset)
b
- the buffer to hold a copy of the data.offset
- the offset at which to start copying.public byte[] getBuffer()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |