org.apache.hadoop.hbase.io.hfile
Class HFileBlock.Writer

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.HFileBlock.Writer
Enclosing class:
HFileBlock

public static class HFileBlock.Writer
extends Object

Unified version 2 HFile block writer. The intended usage pattern is as follows:

  1. Construct an HFileBlock.Writer, providing a compression algorithm.
  2. Call startWriting(org.apache.hadoop.hbase.io.hfile.BlockType) and get a data stream to write to.
  3. Write your data into the stream.
  4. Call writeHeaderAndData(FSDataOutputStream) as many times as you need to. store the serialized block into an external stream.
  5. Repeat to write more blocks.


Constructor Summary
HFileBlock.Writer(HFileDataBlockEncoder dataBlockEncoder, HFileContext fileContext)
           
 
Method Summary
 int blockSizeWritten()
          Returns the number of bytes written into the current block so far, or zero if not writing the block at the moment.
 HFileBlock getBlockForCaching(CacheConfig cacheConf)
          Creates a new HFileBlock.
 boolean isWriting()
           
 void release()
          Releases resources used by this writer.
 DataOutputStream startWriting(BlockType newBlockType)
          Starts writing into the block.
 void writeBlock(HFileBlock.BlockWritable bw, org.apache.hadoop.fs.FSDataOutputStream out)
          Takes the given HFileBlock.BlockWritable instance, creates a new block of its appropriate type, writes the writable into this block, and flushes the block into the output stream.
 void writeHeaderAndData(org.apache.hadoop.fs.FSDataOutputStream out)
          Similar to writeHeaderAndData(FSDataOutputStream), but records the offset of this block so that it can be referenced in the next block of the same type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HFileBlock.Writer

public HFileBlock.Writer(HFileDataBlockEncoder dataBlockEncoder,
                         HFileContext fileContext)
Parameters:
dataBlockEncoder - data block encoding algorithm to use
Method Detail

startWriting

public DataOutputStream startWriting(BlockType newBlockType)
                              throws IOException
Starts writing into the block. The previous block's data is discarded.

Returns:
the stream the user can write their data into
Throws:
IOException

writeHeaderAndData

public void writeHeaderAndData(org.apache.hadoop.fs.FSDataOutputStream out)
                        throws IOException
Similar to writeHeaderAndData(FSDataOutputStream), but records the offset of this block so that it can be referenced in the next block of the same type.

Parameters:
out -
Throws:
IOException

release

public void release()
Releases resources used by this writer.


isWriting

public boolean isWriting()
Returns:
true if a block is being written

blockSizeWritten

public int blockSizeWritten()
Returns the number of bytes written into the current block so far, or zero if not writing the block at the moment. Note that this will return zero in the "block ready" state as well.

Returns:
the number of bytes written

writeBlock

public void writeBlock(HFileBlock.BlockWritable bw,
                       org.apache.hadoop.fs.FSDataOutputStream out)
                throws IOException
Takes the given HFileBlock.BlockWritable instance, creates a new block of its appropriate type, writes the writable into this block, and flushes the block into the output stream. The writer is instructed not to buffer uncompressed bytes for cache-on-write.

Parameters:
bw - the block-writable object to write as a block
out - the file system output stream
Throws:
IOException

getBlockForCaching

public HFileBlock getBlockForCaching(CacheConfig cacheConf)
Creates a new HFileBlock. Checksums have already been validated, so the byte buffer passed into the constructor of this newly created block does not have checksum data even though the header minor version is MINOR_VERSION_WITH_CHECKSUM. This is indicated by setting a 0 value in bytesPerChecksum.



Copyright © 2015 The Apache Software Foundation. All rights reserved.