Package com.google.code.hs4j.network.buffer

Examples of com.google.code.hs4j.network.buffer.IoBuffer


      if (message.getWriteFuture() != null) {
        message.getWriteFuture().setResult(Boolean.TRUE);
      }
      return message.getMessage();
    }
    IoBuffer writeBuffer = message.getWriteBuffer();
    // begin writing
    message.writing();
    if (useBlockingWrite) {
      return blockingWrite(selectableChannel, message, writeBuffer);
    } else {
      while (true) {
        long n = doRealWrite(selectableChannel, writeBuffer);
        if (n > 0) {
          statistics.statisticsWrite(n);
          scheduleWritenBytes.addAndGet(0 - n);
        }
        if (writeBuffer == null || !writeBuffer.hasRemaining()) {
          if (message.getWriteFuture() != null) {
            message.getWriteFuture().setResult(Boolean.TRUE);
          }
          return message.getMessage();
        } else if (n == 0) {
View Full Code Here


        + this.operator.length() + 1 + kenLen.length() + 1
        + this.length(keyBytes) + this.keys.length + limitStr.length()
        + 1 + offsetStr.length() + 1
        + filterAllLength+1;

    IoBuffer buf = IoBuffer.allocate(capacity);
    buf.setAutoExpand(true);
    // id
    this.writeToken(buf, this.id);
    this.writeTokenSeparator(buf);
    // operator
    this.writeToken(buf, this.operator);
    this.writeTokenSeparator(buf);
    // value nums

    this.writeToken(buf, kenLen);
    this.writeTokenSeparator(buf);

    for (byte[] data : keyBytes) {
      this.writeToken(buf, data);
      this.writeTokenSeparator(buf);
    }
    // limit
    this.writeToken(buf, limitStr);
    this.writeTokenSeparator(buf);
    // offset
    this.writeToken(buf, offsetStr);

    // filter
    for(int i=0; i< flen;i++) {
      this.writeTokenSeparator(buf);
      // filter type
      this.writeToken(buf, ftype[i]);
      this.writeTokenSeparator(buf);
      // filter operator
      this.writeToken(buf, fop[i]);
      this.writeTokenSeparator(buf);
      // filter column
      this.writeToken(buf, fcol[i]);
      this.writeTokenSeparator(buf);
      // filter value
      this.writeToken(buf, fval[i]);
    }
    this.writeCommandTerminate(buf);

    buf.flip();
    this.buffer = buf;
  }
View Full Code Here

  public void encode() {
    String valueLen = String.valueOf(this.values.length);
    int capacity = this.id.length() + 1 + OPERATOR_INSERT.length() + 1
        + this.length(this.values) + this.values.length
        + valueLen.length() + 2;
    IoBuffer buf = IoBuffer.allocate(capacity);
    buf.setAutoExpand(true);

    // id
    this.writeToken(buf, this.id);
    this.writeTokenSeparator(buf);
    // operator
    this.writeToken(buf, OPERATOR_INSERT);
    this.writeTokenSeparator(buf);
    // key nums

    this.writeToken(buf, valueLen);
    this.writeTokenSeparator(buf);
    for (int i = 0; i < this.values.length; i++) {
      this
          .writeToken(buf, this.values[i] == null ? null
              : this.values[i]);
      if (i == this.values.length - 1) {
        this.writeCommandTerminate(buf);
      } else {
        this.writeTokenSeparator(buf);
      }
    }
    buf.flip();
    this.buffer = buf;

  }
View Full Code Here

    int capacity = this.id.length() + 1 + this.operator.length() + 1
        + this.length(this.values) + this.length(keyBytes)
        + this.values.length + 1 + this.keys.length + limitStr.length()
        + 1 + kenLen.length() + 1 + offsetStr.length() + 2;
    IoBuffer buf = IoBuffer.allocate(capacity);
    buf.setAutoExpand(true);

    // id
    this.writeToken(buf, this.id);
    this.writeTokenSeparator(buf);
    // operator
    this.writeToken(buf, this.operator);
    this.writeTokenSeparator(buf);
    // key nums
    this.writeToken(buf, kenLen);
    this.writeTokenSeparator(buf);
    for (byte[] data : keyBytes) {
      this.writeToken(buf, data);
      this.writeTokenSeparator(buf);
    }
    // limit
    this.writeToken(buf, limitStr);
    this.writeTokenSeparator(buf);
    // offset
    this.writeToken(buf, offsetStr);
    this.writeTokenSeparator(buf);
    // modify operator
    this.writeToken(buf, this.modOperation);
    this.writeTokenSeparator(buf);

    // modify values

    for (int i = 0; i < this.values.length; i++) {
      this.writeToken(buf, this.values[i]);
      if (i == this.values.length - 1) {
        this.writeCommandTerminate(buf);
      } else {
        this.writeTokenSeparator(buf);
      }
    }

    buf.flip();
    this.buffer = buf;
  }
View Full Code Here

  }

  public void encode() {
    byte [][]fieldBytes=HSUtils.getByteArrayFromStringArray(this.fieldList, this.encoding);
   
    IoBuffer buf = IoBuffer.allocate(2 + this.id.length() + 1
        + this.db.length() + 1 + this.tableName.length() + 1
        + this.indexName.length() + 1 + this.length(fieldBytes)
        + this.fieldList.length+ this.fieldList.length);
    buf.setAutoExpand(true);

    // header
    this.writeToken(buf, OPERATOR_OPEN_INDEX);
    this.writeTokenSeparator(buf);
    // id
    this.writeToken(buf, this.id);
    this.writeTokenSeparator(buf);
    // db name
    this.writeToken(buf, this.db);
    this.writeTokenSeparator(buf);
    // tableName
    this.writeToken(buf, this.tableName);
    this.writeTokenSeparator(buf);
    // indexName
    this.writeToken(buf, this.indexName);
    this.writeTokenSeparator(buf);
    // field list
    this.writeToken(buf, join(this.fieldList));

    // filter field list
    if(filterFieldList.length != 0) {
      this.writeTokenSeparator(buf);
      this.writeToken(buf, join(this.filterFieldList));
      this.writeCommandTerminate(buf);
    }else{
      this.writeCommandTerminate(buf);

    }

    buf.flip();

    this.buffer = buf;
  }
View Full Code Here

            if (msg == null) {
                return null;
            }
            String message = (String) msg;
            ByteBuffer buff = TextLineCodecFactory.this.charset.encode(message);
            IoBuffer resultBuffer = IoBuffer.allocate(buff.remaining() + SPLIT.remaining());
            resultBuffer.put(buff);
            resultBuffer.put(SPLIT.slice());
            resultBuffer.flip();
            return resultBuffer;
        }
View Full Code Here

TOP

Related Classes of com.google.code.hs4j.network.buffer.IoBuffer

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.