Java 类org.apache.thrift.TByteArrayOutputStream 实例源码

项目:internet_of_things_simulator    文件:TJSONProtocol.java   
private byte[] readJSONBase64() throws TException {
  TByteArrayOutputStream arr = readJSONString(false);
  byte[] b = arr.get();
  int len = arr.len();
  int off = 0;
  int size = 0;
  while (len >= 4) {
    // Decode 4 bytes at a time
    TBase64Utils.decode(b, off, 4, b, size); // NB: decoded in place
    off += 4;
    len -= 4;
    size += 3;
  }
  // Don't decode if we hit the end or got a single leftover byte (invalid
  // base64 but legal for skip of regular string type)
  if (len > 1) {
    // Decode remainder
    TBase64Utils.decode(b, off, len, b, size); // NB: decoded in place
    size += len - 1;
  }
  // Sadly we must copy the byte[] (any way around this?)
  byte [] result = new byte[size];
  System.arraycopy(b, 0, result, 0, size);
  return result;
}
项目:internet_of_things_simulator    文件:AbstractNonblockingServer.java   
public FrameBuffer(final TNonblockingTransport trans,
    final SelectionKey selectionKey,
    final AbstractSelectThread selectThread) {
  trans_ = trans;
  selectionKey_ = selectionKey;
  selectThread_ = selectThread;
  buffer_ = ByteBuffer.allocate(4);

  frameTrans_ = new TMemoryInputTransport();
  response_ = new TByteArrayOutputStream();
  inTrans_ = inputTransportFactory_.getTransport(frameTrans_);
  outTrans_ = outputTransportFactory_.getTransport(new TIOStreamTransport(response_));
  inProt_ = inputProtocolFactory_.getProtocol(inTrans_);
  outProt_ = outputProtocolFactory_.getProtocol(outTrans_);

  if (eventHandler_ != null) {
    context_ = eventHandler_.createContext(inProt_, outProt_);
  } else {
    context_  = null;
  }
}
项目:CadalWorkspace    文件:TJSONProtocol.java   
private byte[] readJSONBase64() throws TException {
  TByteArrayOutputStream arr = readJSONString(false);
  byte[] b = arr.get();
  int len = arr.len();
  int off = 0;
  int size = 0;
  while (len >= 4) {
    // Decode 4 bytes at a time
    TBase64Utils.decode(b, off, 4, b, size); // NB: decoded in place
    off += 4;
    len -= 4;
    size += 3;
  }
  // Don't decode if we hit the end or got a single leftover byte (invalid
  // base64 but legal for skip of regular string type)
  if (len > 1) {
    // Decode remainder
    TBase64Utils.decode(b, off, len, b, size); // NB: decoded in place
    size += len - 1;
  }
  // Sadly we must copy the byte[] (any way around this?)
  byte [] result = new byte[size];
  System.arraycopy(b, 0, result, 0, size);
  return result;
}
项目:CadalWorkspace    文件:TJSONProtocol.java   
private byte[] readJSONBase64() throws TException {
  TByteArrayOutputStream arr = readJSONString(false);
  byte[] b = arr.get();
  int len = arr.len();
  int off = 0;
  int size = 0;
  while (len >= 4) {
    // Decode 4 bytes at a time
    TBase64Utils.decode(b, off, 4, b, size); // NB: decoded in place
    off += 4;
    len -= 4;
    size += 3;
  }
  // Don't decode if we hit the end or got a single leftover byte (invalid
  // base64 but legal for skip of regular string type)
  if (len > 1) {
    // Decode remainder
    TBase64Utils.decode(b, off, len, b, size); // NB: decoded in place
    size += len - 1;
  }
  // Sadly we must copy the byte[] (any way around this?)
  byte [] result = new byte[size];
  System.arraycopy(b, 0, result, 0, size);
  return result;
}
项目:internet_of_things_simulator    文件:TJSONProtocol.java   
/**
 * Reading methods.
 */

// Read in a JSON string, unescaping as appropriate.. Skip reading from the
// context if skipContext is true.
private TByteArrayOutputStream readJSONString(boolean skipContext)
  throws TException {
  TByteArrayOutputStream arr = new TByteArrayOutputStream(DEF_STRING_SIZE);
  if (!skipContext) {
    context_.read();
  }
  readJSONSyntaxChar(QUOTE);
  while (true) {
    byte ch = reader_.read();
    if (ch == QUOTE[0]) {
      break;
    }
    if (ch == ESCSEQ[0]) {
      ch = reader_.read();
      if (ch == ESCSEQ[1]) {
        readJSONSyntaxChar(ZERO);
        readJSONSyntaxChar(ZERO);
        trans_.readAll(tmpbuf_, 0, 2);
        ch = (byte)((hexVal((byte)tmpbuf_[0]) << 4) + hexVal(tmpbuf_[1]));
      }
      else {
        int off = ESCAPE_CHARS.indexOf(ch);
        if (off == -1) {
          throw new TProtocolException(TProtocolException.INVALID_DATA,
                                       "Expected control char");
        }
        ch = ESCAPE_CHAR_VALS[off];
      }
    }
    arr.write(ch);
  }
  return arr;
}
项目:CadalWorkspace    文件:TJSONProtocol.java   
/**
 * Reading methods.
 */

// Read in a JSON string, unescaping as appropriate.. Skip reading from the
// context if skipContext is true.
private TByteArrayOutputStream readJSONString(boolean skipContext)
  throws TException {
  TByteArrayOutputStream arr = new TByteArrayOutputStream(DEF_STRING_SIZE);
  if (!skipContext) {
    context_.read();
  }
  readJSONSyntaxChar(QUOTE);
  while (true) {
    byte ch = reader_.read();
    if (ch == QUOTE[0]) {
      break;
    }
    if (ch == ESCSEQ[0]) {
      ch = reader_.read();
      if (ch == ESCSEQ[1]) {
        readJSONSyntaxChar(ZERO);
        readJSONSyntaxChar(ZERO);
        trans_.readAll(tmpbuf_, 0, 2);
        ch = (byte)((hexVal((byte)tmpbuf_[0]) << 4) + hexVal(tmpbuf_[1]));
      }
      else {
        int off = ESCAPE_CHARS.indexOf(ch);
        if (off == -1) {
          throw new TProtocolException(TProtocolException.INVALID_DATA,
                                       "Expected control char");
        }
        ch = ESCAPE_CHAR_VALS[off];
      }
    }
    arr.write(ch);
  }
  return arr;
}
项目:CadalWorkspace    文件:TJSONProtocol.java   
/**
 * Reading methods.
 */

// Read in a JSON string, unescaping as appropriate.. Skip reading from the
// context if skipContext is true.
private TByteArrayOutputStream readJSONString(boolean skipContext)
  throws TException {
  TByteArrayOutputStream arr = new TByteArrayOutputStream(DEF_STRING_SIZE);
  if (!skipContext) {
    context_.read();
  }
  readJSONSyntaxChar(QUOTE);
  while (true) {
    byte ch = reader_.read();
    if (ch == QUOTE[0]) {
      break;
    }
    if (ch == ESCSEQ[0]) {
      ch = reader_.read();
      if (ch == ESCSEQ[1]) {
        readJSONSyntaxChar(ZERO);
        readJSONSyntaxChar(ZERO);
        trans_.readAll(tmpbuf_, 0, 2);
        ch = (byte)((hexVal((byte)tmpbuf_[0]) << 4) + hexVal(tmpbuf_[1]));
      }
      else {
        int off = ESCAPE_CHARS.indexOf(ch);
        if (off == -1) {
          throw new TProtocolException(TProtocolException.INVALID_DATA,
                                       "Expected control char");
        }
        ch = ESCAPE_CHAR_VALS[off];
      }
    }
    arr.write(ch);
  }
  return arr;
}
项目:CadalWorkspace    文件:AbstractNonblockingServer.java   
/**
 * Get the transport that should be used by the invoker for responding.
 */
private TTransport getOutputTransport() {
  response_ = new TByteArrayOutputStream();
  return outputTransportFactory_.getTransport(new TIOStreamTransport(response_));
}
项目:CadalWorkspace    文件:AbstractNonblockingServer.java   
/**
 * Get the transport that should be used by the invoker for responding.
 */
private TTransport getOutputTransport() {
  response_ = new TByteArrayOutputStream();
  return outputTransportFactory_.getTransport(new TIOStreamTransport(response_));
}
项目:internet_of_things_simulator    文件:TMemoryBuffer.java   
/**
 * Create a TMemoryBuffer with an initial buffer size of <i>size</i>. The
 * internal buffer will grow as necessary to accommodate the size of the data
 * being written to it.
 */
public TMemoryBuffer(int size) {
  arr_ = new TByteArrayOutputStream(size);
}
项目:CadalWorkspace    文件:TMemoryBuffer.java   
/**
 * Create a TMemoryBuffer with an initial buffer size of <i>size</i>. The
 * internal buffer will grow as necessary to accommodate the size of the data
 * being written to it.
 */
public TMemoryBuffer(int size) {
  arr_ = new TByteArrayOutputStream(size);
}
项目:CadalWorkspace    文件:TMemoryBuffer.java   
/**
 * Create a TMemoryBuffer with an initial buffer size of <i>size</i>. The
 * internal buffer will grow as necessary to accommodate the size of the data
 * being written to it.
 */
public TMemoryBuffer(int size) {
  arr_ = new TByteArrayOutputStream(size);
}