org.elasticsearch.common.io.stream
Class BytesStreamOutput

java.lang.Object
  extended by java.io.OutputStream
      extended by org.elasticsearch.common.io.stream.StreamOutput
          extended by org.elasticsearch.common.io.stream.BytesStreamOutput
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, BytesStream

public class BytesStreamOutput
extends StreamOutput
implements BytesStream


Field Summary
protected  byte[] buf
          The buffer where data is stored.
protected  int count
          The number of valid bytes in the buffer.
 
Constructor Summary
BytesStreamOutput()
           
BytesStreamOutput(int size)
           
 
Method Summary
 void close()
          Closes this stream to further operations.
 byte[] copiedByteArray()
          Creates a newly allocated byte array.
 void flush()
          Forces any buffered output to be written.
 void reset()
           
 void seek(int seekTo)
           
 int size()
          Returns the current size of the buffer.
 byte[] unsafeByteArray()
          Returns the underlying byte array.
 void writeByte(byte b)
          Writes a single byte.
 void writeBytes(byte[] b, int offset, int length)
          Writes an array of bytes.
 void writeUTF(java.lang.String str)
          Writes a string.
 
Methods inherited from class org.elasticsearch.common.io.stream.StreamOutput
write, write, writeBoolean, writeBytes, writeBytes, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeVInt, writeVLong
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

protected byte[] buf
The buffer where data is stored.


count

protected int count
The number of valid bytes in the buffer.

Constructor Detail

BytesStreamOutput

public BytesStreamOutput()

BytesStreamOutput

public BytesStreamOutput(int size)
Method Detail

writeByte

public void writeByte(byte b)
               throws java.io.IOException
Description copied from class: StreamOutput
Writes a single byte.

Specified by:
writeByte in class StreamOutput
Throws:
java.io.IOException

writeBytes

public void writeBytes(byte[] b,
                       int offset,
                       int length)
                throws java.io.IOException
Description copied from class: StreamOutput
Writes an array of bytes.

Specified by:
writeBytes in class StreamOutput
Parameters:
b - the bytes to write
offset - the offset in the byte array
length - the number of bytes to write
Throws:
java.io.IOException

seek

public void seek(int seekTo)

reset

public void reset()
Specified by:
reset in class StreamOutput

flush

public void flush()
           throws java.io.IOException
Description copied from class: StreamOutput
Forces any buffered output to be written.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class StreamOutput
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Description copied from class: StreamOutput
Closes this stream to further operations.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class StreamOutput
Throws:
java.io.IOException

copiedByteArray

public byte[] copiedByteArray()
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.

Specified by:
copiedByteArray in interface BytesStream
Returns:
the current contents of this output stream, as a byte array.
See Also:
ByteArrayOutputStream.size()

unsafeByteArray

public byte[] unsafeByteArray()
Returns the underlying byte array. Note, use size() in order to know the length of it.

Specified by:
unsafeByteArray in interface BytesStream

size

public int size()
Returns the current size of the buffer.

Specified by:
size in interface BytesStream
Returns:
the value of the count field, which is the number of valid bytes in this output stream.
See Also:
ByteArrayOutputStream.count

writeUTF

public void writeUTF(java.lang.String str)
              throws java.io.IOException
Writes a string.

Overrides:
writeUTF in class StreamOutput
Throws:
java.io.IOException