|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
org.elasticsearch.common.io.FastByteArrayOutputStream
public class FastByteArrayOutputStream
Similar to ByteArrayOutputStream
just not synced.
Nested Class Summary | |
---|---|
static class |
FastByteArrayOutputStream.Cached
A thread local based cache of FastByteArrayOutputStream . |
Field Summary | |
---|---|
protected byte[] |
buf
The buffer where data is stored. |
protected int |
count
The number of valid bytes in the buffer. |
Constructor Summary | |
---|---|
FastByteArrayOutputStream()
Creates a new byte array output stream. |
|
FastByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. |
Method Summary | |
---|---|
void |
close()
Closing a ByteArrayOutputStream has no effect. |
byte[] |
copiedByteArray()
Creates a newly allocated byte array. |
void |
reset()
Resets the count field of this byte array output
stream to zero, so that all currently accumulated output in the
output stream is discarded. |
void |
seek(int position)
Seeks back to the given position. |
int |
size()
Returns the current size of the buffer. |
java.lang.String |
toString()
Converts the buffer's contents into a string decoding bytes using the platform's default character set. |
java.lang.String |
toString(java.lang.String charsetName)
Converts the buffer's contents into a string by decoding the bytes using the specified charsetName . |
byte[] |
unsafeByteArray()
Returns the underlying byte array. |
void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array
starting at offset off to this byte array output stream. |
void |
write(int b)
Writes the specified byte to this byte array output stream. |
void |
writeTo(java.io.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) . |
Methods inherited from class java.io.OutputStream |
---|
flush, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected byte[] buf
protected int count
Constructor Detail |
---|
public FastByteArrayOutputStream()
public FastByteArrayOutputStream(int size)
size
- the initial size.
java.lang.IllegalArgumentException
- if size is negative.Method Detail |
---|
public void write(int b)
write
in class java.io.OutputStream
b
- the byte to be written.public void write(byte[] b, int off, int len)
len
bytes from the specified byte array
starting at offset off
to this byte array output stream.
NO checks for bounds, parameters must be ok!
write
in class java.io.OutputStream
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.public void writeTo(java.io.OutputStream out) throws java.io.IOException
out.write(buf, 0, count)
.
out
- the output stream to which to write the data.
java.io.IOException
- if an I/O error occurs.public void reset()
count
field of this byte array output
stream to zero, so that all currently accumulated output in the
output stream is discarded. The output stream can be used again,
reusing the already allocated buffer space.
ByteArrayInputStream.count
public byte[] copiedByteArray()
ByteArrayOutputStream.size()
public byte[] unsafeByteArray()
size()
in order to know
the length of it.
public int size()
count
field, which is the number
of valid bytes in this output stream.ByteArrayOutputStream.count
public void seek(int position)
public java.lang.String toString()
This method always replaces malformed-input and unmappable-character sequences with the default replacement string for the platform's default character set. The CharsetDecoder class should be used when more control over the decoding process is required.
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String charsetName) throws java.io.UnsupportedEncodingException
charsetName
. The length of
the new String is a function of the charset, and hence may not be
equal to the length of the byte array.
This method always replaces malformed-input and unmappable-character
sequences with this charset's default replacement string. The CharsetDecoder
class should be used when more control
over the decoding process is required.
charsetName
- the name of a supported
charset
- Returns:
- String decoded from the buffer's contents.
- Throws:
java.io.UnsupportedEncodingException
- If the named charset is not supported- Since:
- JDK1.1
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.OutputStream
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |