Package org.apache.hadoop.hbase.io
Class ByteBufferWriterOutputStream
java.lang.Object
java.io.OutputStream
org.apache.hadoop.hbase.io.ByteBufferWriterOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,ByteBufferWriter
When deal with OutputStream which is not ByteBufferWriter type, wrap it with this class. We will
have to write offheap ByteBuffer (DBB) data into the OS. This class is having a temp byte array
to which we can copy the DBB data for writing to the OS.
This is used while writing Cell data to WAL. In case of AsyncWAL, the OS created there is ByteBufferWriter. But in case of FSHLog, the OS passed by DFS client, is not of type ByteBufferWriter. We will need this temp solution until DFS client supports writing ByteBuffer directly to the OS it creates.
Note: This class is not thread safe.
This is used while writing Cell data to WAL. In case of AsyncWAL, the OS created there is ByteBufferWriter. But in case of FSHLog, the OS passed by DFS client, is not of type ByteBufferWriter. We will need this temp solution until DFS client supports writing ByteBuffer directly to the OS it creates.
Note: This class is not thread safe.
-
Field Summary
Modifier and TypeFieldDescriptionprivate byte[]
private final int
private static final int
private final OutputStream
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
void
write
(byte[] b, int off, int len) void
write
(int b) void
write
(ByteBuffer b, int off, int len) Writes len bytes from the specified ByteBuffer starting at offset off to this OutputStream.void
writeInt
(int i) Writes anint
to the underlying output stream as four bytes, high byte first.Methods inherited from class java.io.OutputStream
write
-
Field Details
-
DEFAULT_BUFFER_SIZE
- See Also:
-
os
-
bufSize
-
buf
-
-
Constructor Details
-
ByteBufferWriterOutputStream
-
ByteBufferWriterOutputStream
-
-
Method Details
-
write
Writes len bytes from the specified ByteBuffer starting at offset off to this OutputStream. If b is null, a NullPointerException is thrown. If off is negative or larger than the ByteBuffer then an ArrayIndexOutOfBoundsException is thrown. If len is greater than the length of the ByteBuffer, then an ArrayIndexOutOfBoundsException is thrown. This method does not change the position of the ByteBuffer.- Specified by:
write
in interfaceByteBufferWriter
- Parameters:
b
- the ByteBufferoff
- the start offset in the datalen
- the number of bytes to write if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.- Throws:
IOException
- if an I/O error occurs.
-
writeInt
Description copied from interface:ByteBufferWriter
Writes anint
to the underlying output stream as four bytes, high byte first.- Specified by:
writeInt
in interfaceByteBufferWriter
- Parameters:
i
- theint
to write- Throws:
IOException
- if an I/O error occurs.
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-