org.apache.hadoop.hbase.io
Class ByteBufferOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.apache.hadoop.hbase.io.ByteBufferOutputStream
All Implemented Interfaces:
Closeable, Flushable

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class ByteBufferOutputStream
extends OutputStream

Not thread safe!


Field Summary
protected  ByteBuffer buf
           
 
Constructor Summary
ByteBufferOutputStream(ByteBuffer bb)
           
ByteBufferOutputStream(int capacity)
           
ByteBufferOutputStream(int capacity, boolean useDirectByteBuffer)
           
 
Method Summary
 void close()
           
 void flush()
           
 ByteBuffer getByteBuffer()
          This flips the underlying BB so be sure to use it _last_!
 int size()
           
 byte[] toByteArray(int offset, int length)
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeTo(OutputStream out)
          Writes the complete contents of this byte buffer output stream to the specified output stream argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

protected ByteBuffer buf
Constructor Detail

ByteBufferOutputStream

public ByteBufferOutputStream(int capacity)

ByteBufferOutputStream

public ByteBufferOutputStream(int capacity,
                              boolean useDirectByteBuffer)

ByteBufferOutputStream

public ByteBufferOutputStream(ByteBuffer bb)
Parameters:
bb - ByteBuffer to use. If too small, will be discarded and a new one allocated in its place; i.e. the passed in BB may NOT BE RETURNED!! Minimally it will be altered. SIDE EFFECT!! If you want to get the newly allocated ByteBuffer, you'll need to pick it up when done with this instance by calling getByteBuffer(). All this encapsulation violation is so we can recycle buffers rather than allocate each time; it can get expensive especially if the buffers are big doing allocations each time or having them undergo resizing because initial allocation was small.
See Also:
getByteBuffer()
Method Detail

size

public int size()

getByteBuffer

public ByteBuffer getByteBuffer()
This flips the underlying BB so be sure to use it _last_!

Returns:
ByteBuffer

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

writeTo

public void writeTo(OutputStream out)
             throws IOException
Writes the complete contents of this byte buffer output stream to the specified output stream argument.

Parameters:
out - the output stream to which to write the data.
Throws:
IOException - if an I/O error occurs.

write

public void write(byte[] b)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException

toByteArray

public byte[] toByteArray(int offset,
                          int length)


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.