Java Code Examples for org.apache.hadoop.io.file.tfile.Chunk.ChunkEncoder

The following examples show how to use org.apache.hadoop.io.file.tfile.Chunk.ChunkEncoder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: TFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source Project: big-c   Source File: TFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source Project: attic-apex-malhar   Source File: DTFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source Project: RDFS   Source File: TFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source Project: hadoop-gpu   Source File: TFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}