/** * Obtain an output stream for writing a value into TFile. This may only be * called right after a key appending operation (the key append stream must * be closed). * * @param length * The expected length of the value. If length of the value is not * known, set length = -1. Otherwise, the application must write * exactly as many bytes as specified here before calling close on * the returned output stream. Advertising the value size up-front * guarantees that the value is encoded in one chunk, and avoids * intermediate chunk buffering. * @throws IOException * */ public DataOutputStream prepareAppendValue(int length) throws IOException { if (state != State.END_KEY) { throw new IllegalStateException( "Incorrect state to start a new value: " + state.name()); } DataOutputStream ret; // unknown length if (length < 0) { if (valueBuffer == null) { valueBuffer = new byte[getChunkBufferSize(conf)]; } ret = new ValueRegister(new ChunkEncoder(blkAppender, valueBuffer)); } else { ret = new ValueRegister(new Chunk.SingleChunkEncoder(blkAppender, length)); } state = State.IN_VALUE; return ret; }