Java Code Examples for org.apache.hadoop.hdfs.client.HdfsDataOutputStream#write()

The following examples show how to use org.apache.hadoop.hdfs.client.HdfsDataOutputStream#write() . 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 File: WriteCtx.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public void writeData(HdfsDataOutputStream fos) throws IOException {
  Preconditions.checkState(fos != null);

  ByteBuffer dataBuffer;
  try {
    dataBuffer = getData();
  } catch (Exception e1) {
    LOG.error("Failed to get request data offset:" + offset + " count:"
        + count + " error:" + e1);
    throw new IOException("Can't get WriteCtx.data");
  }

  byte[] data = dataBuffer.array();
  int position = dataBuffer.position();
  int limit = dataBuffer.limit();
  Preconditions.checkState(limit - position == count);
  // Modified write has a valid original count
  if (position != 0) {
    if (limit != getOriginalCount()) {
      throw new IOException("Modified write has differnt original size."
          + "buff position:" + position + " buff limit:" + limit + ". "
          + toString());
    }
  }
  
  // Now write data
  fos.write(data, position, count);
}
 
Example 2
Source File: TestFSImageWithSnapshot.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** Append a file without closing the output stream */
private HdfsDataOutputStream appendFileWithoutClosing(Path file, int length)
    throws IOException {
  byte[] toAppend = new byte[length];
  Random random = new Random();
  random.nextBytes(toAppend);
  HdfsDataOutputStream out = (HdfsDataOutputStream) hdfs.append(file);
  out.write(toAppend);
  return out;
}
 
Example 3
Source File: TestINodeFileUnderConstructionWithSnapshot.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private HdfsDataOutputStream appendFileWithoutClosing(Path file, int length)
    throws IOException {
  byte[] toAppend = new byte[length];
  Random random = new Random();
  random.nextBytes(toAppend);
  HdfsDataOutputStream out = (HdfsDataOutputStream) hdfs.append(file);
  out.write(toAppend);
  return out;
}
 
Example 4
Source File: TestSnapshot.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
void modify() throws Exception {
  assertTrue(fs.exists(file));
  byte[] toAppend = new byte[appendLen];
  random.nextBytes(toAppend);

  out = (HdfsDataOutputStream)fs.append(file);
  out.write(toAppend);
  out.hsync(EnumSet.of(HdfsDataOutputStream.SyncFlag.UPDATE_LENGTH));
}
 
Example 5
Source File: WriteCtx.java    From big-c with Apache License 2.0 5 votes vote down vote up
public void writeData(HdfsDataOutputStream fos) throws IOException {
  Preconditions.checkState(fos != null);

  ByteBuffer dataBuffer;
  try {
    dataBuffer = getData();
  } catch (Exception e1) {
    LOG.error("Failed to get request data offset:" + offset + " count:"
        + count + " error:" + e1);
    throw new IOException("Can't get WriteCtx.data");
  }

  byte[] data = dataBuffer.array();
  int position = dataBuffer.position();
  int limit = dataBuffer.limit();
  Preconditions.checkState(limit - position == count);
  // Modified write has a valid original count
  if (position != 0) {
    if (limit != getOriginalCount()) {
      throw new IOException("Modified write has differnt original size."
          + "buff position:" + position + " buff limit:" + limit + ". "
          + toString());
    }
  }
  
  // Now write data
  fos.write(data, position, count);
}
 
Example 6
Source File: TestFSImageWithSnapshot.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Append a file without closing the output stream */
private HdfsDataOutputStream appendFileWithoutClosing(Path file, int length)
    throws IOException {
  byte[] toAppend = new byte[length];
  Random random = new Random();
  random.nextBytes(toAppend);
  HdfsDataOutputStream out = (HdfsDataOutputStream) hdfs.append(file);
  out.write(toAppend);
  return out;
}
 
Example 7
Source File: TestINodeFileUnderConstructionWithSnapshot.java    From big-c with Apache License 2.0 5 votes vote down vote up
private HdfsDataOutputStream appendFileWithoutClosing(Path file, int length)
    throws IOException {
  byte[] toAppend = new byte[length];
  Random random = new Random();
  random.nextBytes(toAppend);
  HdfsDataOutputStream out = (HdfsDataOutputStream) hdfs.append(file);
  out.write(toAppend);
  return out;
}
 
Example 8
Source File: TestSnapshot.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
void modify() throws Exception {
  assertTrue(fs.exists(file));
  byte[] toAppend = new byte[appendLen];
  random.nextBytes(toAppend);

  out = (HdfsDataOutputStream)fs.append(file);
  out.write(toAppend);
  out.hsync(EnumSet.of(HdfsDataOutputStream.SyncFlag.UPDATE_LENGTH));
}