Examples of ByteBufferOutputStream


Examples of org.apache.hadoop.hbase.io.ByteBufferOutputStream

    /**
     * No protobuf encoding of raw sasl messages
     */
    private void doRawSaslReply(SaslStatus status, Writable rv,
        String errorClass, String error) throws IOException {
      ByteBufferOutputStream saslResponse = null;
      DataOutputStream out = null;
      try {
        // In my testing, have noticed that sasl messages are usually
        // in the ballpark of 100-200. That's why the initial capacity is 256.
        saslResponse = new ByteBufferOutputStream(256);
        out = new DataOutputStream(saslResponse);
        out.writeInt(status.state); // write status
        if (status == SaslStatus.SUCCESS) {
          rv.write(out);
        } else {
          WritableUtils.writeString(out, errorClass);
          WritableUtils.writeString(out, error);
        }
        saslCall.setSaslTokenResponse(saslResponse.getByteBuffer());
        saslCall.responder = responder;
        saslCall.sendResponseIfReady();
      } finally {
        if (saslResponse != null) {
          saslResponse.close();
        }
        if (out != null) {
          out.close();
        }
      }
View Full Code Here

Examples of org.apache.hadoop.hbase.util.ByteBufferOutputStream

        } else {
          size = (int)hint;
        }
      }

      ByteBufferOutputStream buf = new ByteBufferOutputStream(size);
      DataOutputStream out = new DataOutputStream(buf);
      try {
        // Call id.
        out.writeInt(this.id);
        // Write flag.
        byte flag = (error != null)?
          ResponseFlag.getErrorAndLengthSet(): ResponseFlag.getLengthSetOnly();
        out.writeByte(flag);
        // Place holder for length set later below after we
        // fill the buffer with data.
        out.writeInt(0xdeadbeef);
        out.writeInt(status.state);
      } catch (IOException e) {
        errorClass = e.getClass().getName();
        error = StringUtils.stringifyException(e);
      }

      try {
        if (error == null) {
          result.write(out);
        } else {
          WritableUtils.writeString(out, errorClass);
          WritableUtils.writeString(out, error);
        }
      } catch (IOException e) {
        LOG.warn("Error sending response to call: ", e);
      }

      // Set the length into the ByteBuffer after call id and after
      // byte flag.
      ByteBuffer bb = buf.getByteBuffer();
      int bufSiz = bb.remaining();
      // Move to the size location in our ByteBuffer past call.id
      // and past the byte flag.
      bb.position(Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE);
      bb.putInt(bufSiz);
View Full Code Here

Examples of org.apache.hadoop.hbase.util.ByteBufferOutputStream

        } else {
          size = (int)hint;
        }
      }

      ByteBufferOutputStream buf = new ByteBufferOutputStream(size);
      DataOutputStream out = new DataOutputStream(buf);
      try {
        // Call id.
        out.writeInt(this.id);
        // Write flag.
        byte flag = (error != null)?
          ResponseFlag.getErrorAndLengthSet(): ResponseFlag.getLengthSetOnly();
        out.writeByte(flag);
        // Place holder for length set later below after we
        // fill the buffer with data.
        out.writeInt(0xdeadbeef);
        out.writeInt(status.state);
      } catch (IOException e) {
        errorClass = e.getClass().getName();
        error = StringUtils.stringifyException(e);
      }

      try {
        if (error == null) {
          result.write(out);
        } else {
          WritableUtils.writeString(out, errorClass);
          WritableUtils.writeString(out, error);
        }
      } catch (IOException e) {
        LOG.warn("Error sending response to call: ", e);
      }

      // Set the length into the ByteBuffer after call id and after
      // byte flag.
      ByteBuffer bb = buf.getByteBuffer();
      int bufSiz = bb.remaining();
      // Move to the size location in our ByteBuffer past call.id
      // and past the byte flag.
      bb.position(Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE);
      bb.putInt(bufSiz);
View Full Code Here

Examples of org.apache.hadoop.hbase.util.ByteBufferOutputStream

        } else {
          size = (int)hint;
        }
      }

      ByteBufferOutputStream buf = new ByteBufferOutputStream(size);
      DataOutputStream out = new DataOutputStream(buf);
      try {
        out.writeInt(this.id);                // write call id
        out.writeInt(status.state);           // write status
      } catch (IOException e) {
        errorClass = e.getClass().getName();
        error = StringUtils.stringifyException(e);
      }

      try {
        if (status == Status.SUCCESS) {
          result.write(out);
        } else {
          WritableUtils.writeString(out, errorClass);
          WritableUtils.writeString(out, error);
        }
        if (((SecureConnection)connection).useWrap) {
          wrapWithSasl(buf);
        }
      } catch (IOException e) {
        LOG.warn("Error sending response to call: ", e);
      }

      this.response = buf.getByteBuffer();
    }
View Full Code Here

Examples of org.apache.hadoop.hbase.util.ByteBufferOutputStream

        } else {
          size = (int)hint;
        }
      }

      ByteBufferOutputStream buf = new ByteBufferOutputStream(size);
      DataOutputStream out = new DataOutputStream(buf);
      try {
        out.writeInt(this.id);                // write call id
        out.writeInt(status.state);           // write status
      } catch (IOException e) {
        errorClass = e.getClass().getName();
        error = StringUtils.stringifyException(e);
      }

      try {
        if (status == Status.SUCCESS) {
          result.write(out);
        } else {
          WritableUtils.writeString(out, errorClass);
          WritableUtils.writeString(out, error);
        }
        if (((SecureConnection)connection).useWrap) {
          wrapWithSasl(buf);
        }
      } catch (IOException e) {
        LOG.warn("Error sending response to call: ", e);
      }

      this.response = buf.getByteBuffer();
    }
View Full Code Here

Examples of org.apache.hadoop.hbase.util.ByteBufferOutputStream

        } else {
          size = (int)hint;
        }
      }

      ByteBufferOutputStream buf = new ByteBufferOutputStream(size);
      DataOutputStream out = new DataOutputStream(buf);
      try {
        // Call id.
        out.writeInt(this.id);
        // Write flag.
        byte flag = (error != null)?
          ResponseFlag.getErrorAndLengthSet(): ResponseFlag.getLengthSetOnly();
        out.writeByte(flag);
        // Place holder for length set later below after we
        // fill the buffer with data.
        out.writeInt(0xdeadbeef);
        out.writeInt(status.state);
      } catch (IOException e) {
        errorClass = e.getClass().getName();
        error = StringUtils.stringifyException(e);
      }

      try {
        if (error == null) {
          result.write(out);
        } else {
          WritableUtils.writeString(out, errorClass);
          WritableUtils.writeString(out, error);
        }
      } catch (IOException e) {
        LOG.warn("Error sending response to call: ", e);
      }

      // Set the length into the ByteBuffer after call id and after
      // byte flag.
      ByteBuffer bb = buf.getByteBuffer();
      int bufSiz = bb.remaining();
      // Move to the size location in our ByteBuffer past call.id
      // and past the byte flag.
      bb.position(Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE);
      bb.putInt(bufSiz);
View Full Code Here

Examples of org.apache.hadoop.hbase.util.ByteBufferOutputStream

        } else {
          size = (int)hint;
        }
      }

      ByteBufferOutputStream buf = new ByteBufferOutputStream(size);
      DataOutputStream out = new DataOutputStream(buf);
      try {
        out.writeInt(this.id);                // write call id
        out.writeInt(status.state);           // write status
      } catch (IOException e) {
        errorClass = e.getClass().getName();
        error = StringUtils.stringifyException(e);
      }

      try {
        if (status == Status.SUCCESS) {
          result.write(out);
        } else {
          WritableUtils.writeString(out, errorClass);
          WritableUtils.writeString(out, error);
        }
        if (((SecureConnection)connection).useWrap) {
          wrapWithSasl(buf);
        }
      } catch (IOException e) {
        LOG.warn("Error sending response to call: ", e);
      }

      this.response = buf.getByteBuffer();
    }
View Full Code Here

Examples of org.apache.hadoop.hbase.util.ByteBufferOutputStream

        } else {
          size = (int)hint;
        }
      }

      ByteBufferOutputStream buf = new ByteBufferOutputStream(size);
      DataOutputStream out = new DataOutputStream(buf);
      try {
        // Call id.
        out.writeInt(this.id);
        // Write flag.
        byte flag = (error != null)?
          ResponseFlag.getErrorAndLengthSet(): ResponseFlag.getLengthSetOnly();
        out.writeByte(flag);
        // Place holder for length set later below after we
        // fill the buffer with data.
        out.writeInt(0xdeadbeef);
        out.writeInt(status.state);
      } catch (IOException e) {
        errorClass = e.getClass().getName();
        error = StringUtils.stringifyException(e);
      }

      try {
        if (error == null) {
          result.write(out);
        } else {
          WritableUtils.writeString(out, errorClass);
          WritableUtils.writeString(out, error);
        }
      } catch (IOException e) {
        LOG.warn("Error sending response to call: ", e);
      }

      // Set the length into the ByteBuffer after call id and after
      // byte flag.
      ByteBuffer bb = buf.getByteBuffer();
      int bufSiz = bb.remaining();
      // Move to the size location in our ByteBuffer past call.id
      // and past the byte flag.
      bb.position(Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE);
      bb.putInt(bufSiz);
View Full Code Here

Examples of org.apache.hadoop.hdfs.util.ByteBufferOutputStream

    assert proto.getSerializedSize() == PROTO_SIZE
      : "Expected " + (PROTO_SIZE) + " got: " + proto.getSerializedSize();
    try {
      buf.putInt(packetLen);
      buf.putShort((short) proto.getSerializedSize());
      proto.writeTo(new ByteBufferOutputStream(buf));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

Examples of org.apache.mina.util.ByteBufferOutputStream

        return serialize(message).remaining();
    }

    private ByteBuffer serialize(OUT message) {
        if (message != lastObject) {
            ByteBufferOutputStream ebbosa = new ByteBufferOutputStream();
            ebbosa.setElastic(true);
            try {
                ObjectOutputStream oos = new ObjectOutputStream(ebbosa);
                oos.writeObject(message);
                oos.close();
                lastObject = message;
                lastSerialized = ebbosa.getByteBuffer();
            } catch (IOException e) {
                throw new IllegalStateException("Serialization exception", e);
            }
        }
        return lastSerialized;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.