org.apache.hadoop.hbase.io
Class ByteBufferOutputStream
java.lang.Object
java.io.OutputStream
org.apache.hadoop.hbase.io.ByteBufferOutputStream
- All Implemented Interfaces:
- Closeable, Flushable
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class ByteBufferOutputStream
- extends OutputStream
Not thread safe!
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
buf
protected ByteBuffer buf
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()
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-2015 The Apache Software Foundation. All Rights Reserved.