Package org.apache.hadoop.io

Examples of org.apache.hadoop.io.DataOutputBuffer


    /* Write the protocol header for each connection
     * Out is not synchronized because only the first thread does this.
     */
    private void writeHeader() throws IOException {
      // Write out the ConnectionHeader
      DataOutputBuffer buf = new DataOutputBuffer();
      header.write(buf);
     
      // Write out the payload length
      int bufLen = buf.getLength();
      out.writeInt(bufLen);
      out.write(buf.getData(), 0, bufLen);
    }
View Full Code Here


    public void sendParam(Call call) {
      if (shouldCloseConnection.get()) {
        return;
      }

      DataOutputBuffer d=null;
      try {
        synchronized (this.out) {
          if (LOG.isDebugEnabled())
            LOG.debug(getName() + " sending #" + call.id);
         
          //for serializing the
          //data to be written
          d = new DataOutputBuffer();
          d.writeInt(0); // placeholder for data length
          d.writeInt(call.id);
          call.param.write(d);
          byte[] data = d.getData();
          int dataLength = d.getLength() - 4;
          data[0] = (byte)((dataLength >>> 24) & 0xff);
          data[1] = (byte)((dataLength >>> 16) & 0xff);
          data[2] = (byte)((dataLength >>> 8) & 0xff);
          data[3] = (byte)(dataLength & 0xff);
          out.write(data, 0, dataLength + 4);//write the data
View Full Code Here

     */
    private void writeHeader() throws IOException {
      out.write(HBaseServer.HEADER.array());
      out.write(HBaseServer.CURRENT_VERSION);
      //When there are more fields we can have ConnectionHeader Writable.
      DataOutputBuffer buf = new DataOutputBuffer();
      header.write(buf);

      int bufLen = buf.getLength();
      out.writeInt(bufLen);
      out.write(buf.getData(), 0, bufLen);
    }
View Full Code Here

        return;
      }

      // For serializing the data to be written.

      final DataOutputBuffer d = new DataOutputBuffer();
      try {
        if (LOG.isDebugEnabled())
          LOG.debug(getName() + " sending #" + call.id);

        d.writeInt(0xdeadbeef); // placeholder for data length
        d.writeInt(call.id);
        call.param.write(d);
        byte[] data = d.getData();
        int dataLength = d.getLength();
        // fill in the placeholder
        Bytes.putInt(data, 0, dataLength - 4);
        //noinspection SynchronizeOnNonFinalField
        synchronized (this.out) { // FindBugs IS2_INCONSISTENT_SYNC
          out.write(data, 0, dataLength);
View Full Code Here

   * Tests the that {@link org.apache.hadoop.hbase.WritableHelper#writeInstance(java.io.DataOutput,
   * org.apache.hadoop.io.Writable)} fails as expected when null is provided.
   * @throws IOException if an error occurs
   */
  public void testWriteInstanceFailsWithNull() throws IOException {
    DataOutputBuffer dataOutputBuffer = new DataOutputBuffer();
    try {
      WritableHelper.writeInstance(dataOutputBuffer, null);
      Assert.fail("Expected an exception");
    } catch (Exception e) {
      Assert.assertEquals("Wrong exception thrown when null was provided", IllegalArgumentException.class, e.getClass());
View Full Code Here

   * @throws IOException if an error occurs
   */
  public void testWriteReadInstance() throws IOException {
    Expression expression = Expression.comparison("columnName1", "qualifier1", Comparison.Operator.EQ, Bytes.toBytes("value"));

    DataOutputBuffer dataOutputBuffer = new DataOutputBuffer();
    WritableHelper.writeInstance(dataOutputBuffer, expression);

    DataInputBuffer dataInputBuffer = new DataInputBuffer();
    dataInputBuffer.reset(dataOutputBuffer.getData(), dataOutputBuffer.getLength());

    Expression clonedExpression = WritableHelper.readInstance(dataInputBuffer, Expression.class);

    Assert.assertEquals("The expression was not the same after being written and read", expression, clonedExpression);
  }
View Full Code Here

   * @throws IOException if an error occurs
   */
  public void testWriteReadInstanceNullable() throws IOException {
    Expression expression = Expression.comparison("columnName1", "qualifier1", Comparison.Operator.EQ, Bytes.toBytes("value"));

    DataOutputBuffer dataOutputBuffer = new DataOutputBuffer();
    WritableHelper.writeInstanceNullable(dataOutputBuffer, expression);

    DataInputBuffer dataInputBuffer = new DataInputBuffer();
    dataInputBuffer.reset(dataOutputBuffer.getData(), dataOutputBuffer.getLength());

    Expression clonedExpression = WritableHelper.readInstanceNullable(dataInputBuffer, Expression.class);

    Assert.assertEquals("The expression was not the same after being written and read", expression, clonedExpression);
  }
View Full Code Here

   * org.apache.hadoop.io.Writable)} and {@link org.apache.hadoop.hbase.WritableHelper#readInstanceNullable(java.io.DataInput,
   * Class)} works as expected when null is provided.
   * @throws IOException if an error occurs
   */
  public void testWriteReadInstanceNullableWithNull() throws IOException {
    DataOutputBuffer dataOutputBuffer = new DataOutputBuffer();
    WritableHelper.writeInstanceNullable(dataOutputBuffer, null);

    DataInputBuffer dataInputBuffer = new DataInputBuffer();
    dataInputBuffer.reset(dataOutputBuffer.getData(), dataOutputBuffer.getLength());

    Expression clonedExpression = WritableHelper.readInstanceNullable(dataInputBuffer, Expression.class);

    Assert.assertNull("A null value was expected", clonedExpression);
  }
View Full Code Here

   */
  public void testWritable() throws IOException {
    Expression expression = Expression.comparison("columnName", "qualifier", Comparison.Operator.EQ, Bytes.toBytes("value"));

    IdxScan idxScan = new IdxScan(expression);
    DataOutputBuffer dataOutputBuffer = new DataOutputBuffer();
    idxScan.write(dataOutputBuffer);

    DataInputBuffer dataInputBuffer = new DataInputBuffer();
    dataInputBuffer.reset(dataOutputBuffer.getData(), dataOutputBuffer.getLength());

    IdxScan clonedScan = new IdxScan();
    clonedScan.readFields(dataInputBuffer);

    Assert.assertEquals("The expression was not the same after being written and read", idxScan.getExpression(), clonedScan.getExpression());
View Full Code Here

   *
   * @throws java.io.IOException if an IO error occurs
   */
  public void testWritableNullExpression() throws IOException {
    IdxScan idxScan = new IdxScan();
    DataOutputBuffer dataOutputBuffer = new DataOutputBuffer();
    idxScan.write(dataOutputBuffer);

    DataInputBuffer dataInputBuffer = new DataInputBuffer();
    dataInputBuffer.reset(dataOutputBuffer.getData(), dataOutputBuffer.getLength());

    IdxScan clonedScan = new IdxScan();
    clonedScan.readFields(dataInputBuffer);

    Assert.assertEquals("The expression was not the same after being written and read", idxScan.getExpression(), clonedScan.getExpression());
View Full Code Here

TOP

Related Classes of org.apache.hadoop.io.DataOutputBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.