Java Code Examples for org.apache.hadoop.io.file.tfile.BCFile.Writer.BlockAppender

The following examples show how to use org.apache.hadoop.io.file.tfile.BCFile.Writer.BlockAppender. 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 4 votes vote down vote up
/**
 * Close the Writer. Resources will be released regardless of the exceptions
 * being thrown. Future close calls will have no effect.
 * 
 * The underlying FSDataOutputStream is not closed.
 */
@Override
public void close() throws IOException {
  if ((state == State.CLOSED)) {
    return;
  }
  try {
    // First try the normal finish.
    // Terminate upon the first Exception.
    if (errorCount == 0) {
      if (state != State.READY) {
        throw new IllegalStateException(
            "Cannot close TFile in the middle of key-value insertion.");
      }

      finishDataBlock(true);

      // first, write out data:TFile.meta
      BlockAppender outMeta =
          writerBCF
              .prepareMetaBlock(TFileMeta.BLOCK_NAME, COMPRESSION_NONE);
      try {
        tfileMeta.write(outMeta);
      } finally {
        outMeta.close();
      }

      // second, write out data:TFile.index
      BlockAppender outIndex =
          writerBCF.prepareMetaBlock(TFileIndex.BLOCK_NAME);
      try {
        tfileIndex.write(outIndex);
      } finally {
        outIndex.close();
      }

      writerBCF.close();
    }
  } finally {
    IOUtils.cleanup(LOG, blkAppender, writerBCF);
    blkAppender = null;
    writerBCF = null;
    state = State.CLOSED;
  }
}
 
Example 2
Source Project: big-c   Source File: TFile.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Close the Writer. Resources will be released regardless of the exceptions
 * being thrown. Future close calls will have no effect.
 * 
 * The underlying FSDataOutputStream is not closed.
 */
@Override
public void close() throws IOException {
  if ((state == State.CLOSED)) {
    return;
  }
  try {
    // First try the normal finish.
    // Terminate upon the first Exception.
    if (errorCount == 0) {
      if (state != State.READY) {
        throw new IllegalStateException(
            "Cannot close TFile in the middle of key-value insertion.");
      }

      finishDataBlock(true);

      // first, write out data:TFile.meta
      BlockAppender outMeta =
          writerBCF
              .prepareMetaBlock(TFileMeta.BLOCK_NAME, COMPRESSION_NONE);
      try {
        tfileMeta.write(outMeta);
      } finally {
        outMeta.close();
      }

      // second, write out data:TFile.index
      BlockAppender outIndex =
          writerBCF.prepareMetaBlock(TFileIndex.BLOCK_NAME);
      try {
        tfileIndex.write(outIndex);
      } finally {
        outIndex.close();
      }

      writerBCF.close();
    }
  } finally {
    IOUtils.cleanup(LOG, blkAppender, writerBCF);
    blkAppender = null;
    writerBCF = null;
    state = State.CLOSED;
  }
}
 
Example 3
Source Project: RDFS   Source File: TFile.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Close the Writer. Resources will be released regardless of the exceptions
 * being thrown. Future close calls will have no effect.
 * 
 * The underlying FSDataOutputStream is not closed.
 */
public void close() throws IOException {
  if ((state == State.CLOSED)) {
    return;
  }
  try {
    // First try the normal finish.
    // Terminate upon the first Exception.
    if (errorCount == 0) {
      if (state != State.READY) {
        throw new IllegalStateException(
            "Cannot close TFile in the middle of key-value insertion.");
      }

      finishDataBlock(true);

      // first, write out data:TFile.meta
      BlockAppender outMeta =
          writerBCF
              .prepareMetaBlock(TFileMeta.BLOCK_NAME, COMPRESSION_NONE);
      try {
        tfileMeta.write(outMeta);
      } finally {
        outMeta.close();
      }

      // second, write out data:TFile.index
      BlockAppender outIndex =
          writerBCF.prepareMetaBlock(TFileIndex.BLOCK_NAME);
      try {
        tfileIndex.write(outIndex);
      } finally {
        outIndex.close();
      }

writerBCF.close();
    }
  } finally {
    IOUtils.cleanup(LOG, blkAppender, writerBCF);
    blkAppender = null;
    writerBCF = null;
    state = State.CLOSED;
  }
}
 
Example 4
Source Project: hadoop-gpu   Source File: TFile.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Close the Writer. Resources will be released regardless of the exceptions
 * being thrown. Future close calls will have no effect.
 * 
 * The underlying FSDataOutputStream is not closed.
 */
public void close() throws IOException {
  if ((state == State.CLOSED)) {
    return;
  }
  try {
    // First try the normal finish.
    // Terminate upon the first Exception.
    if (errorCount == 0) {
      if (state != State.READY) {
        throw new IllegalStateException(
            "Cannot close TFile in the middle of key-value insertion.");
      }

      finishDataBlock(true);

      // first, write out data:TFile.meta
      BlockAppender outMeta =
          writerBCF
              .prepareMetaBlock(TFileMeta.BLOCK_NAME, COMPRESSION_NONE);
      try {
        tfileMeta.write(outMeta);
      } finally {
        outMeta.close();
      }

      // second, write out data:TFile.index
      BlockAppender outIndex =
          writerBCF.prepareMetaBlock(TFileIndex.BLOCK_NAME);
      try {
        tfileIndex.write(outIndex);
      } finally {
        outIndex.close();
      }

writerBCF.close();
    }
  } finally {
    IOUtils.cleanup(LOG, blkAppender, writerBCF);
    blkAppender = null;
    writerBCF = null;
    state = State.CLOSED;
  }
}