當前位置: 首頁>>代碼示例>>Java>>正文


Java TIOStreamTransport類代碼示例

本文整理匯總了Java中org.apache.thrift.transport.TIOStreamTransport的典型用法代碼示例。如果您正苦於以下問題:Java TIOStreamTransport類的具體用法?Java TIOStreamTransport怎麽用?Java TIOStreamTransport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TIOStreamTransport類屬於org.apache.thrift.transport包,在下文中一共展示了TIOStreamTransport類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: benchSetup

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.addToField1(createElement("1"));
    testObject.addToField1(createElement("2"));
    testObject.addToField1(createElement("3"));
    testObject.addToField1(createElement("4"));

    testObject.addToField1(createElement("1"));
    testObject.addToField1(createElement("2"));
    testObject.addToField1(createElement("3"));
    testObject.addToField1(createElement("4"));

    testObject.addToField1(createElement("1"));
    testObject.addToField1(createElement("2"));
    testObject.addToField1(createElement("3"));
    testObject.addToField1(createElement("4"));

    testObject.addToField1(createElement("1"));
    testObject.addToField1(createElement("2"));
    testObject.addToField1(createElement("3"));
    testObject.addToField1(createElement("4"));
    byteArrayOutputStream = new ByteArrayOutputStream();
    TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory();
    protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream));
}
 
開發者ID:json-iterator,項目名稱:java-benchmark,代碼行數:27,代碼來源:SerThrift.java

示例2: benchSetup

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.addToField1(31.415926);
    testObject.addToField1(61.415923);
    testObject.addToField1(31.415269);
    testObject.addToField1(53.141926);
    testObject.addToField1(13.145926);
    testObject.addToField1(43.115926);
    testObject.addToField1(31.419265);
    testObject.addToField1(23.141596);
    testObject.addToField1(43.161592);
    testObject.addToField1(0.112);
    byteArrayOutputStream = new ByteArrayOutputStream();
    TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory();
    protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream));
}
 
開發者ID:json-iterator,項目名稱:java-benchmark,代碼行數:18,代碼來源:SerThrift.java

示例3: benchSetup

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1("1");
    testObject.setField2("2");
    testObject.setField3("3");
    testObject.setField4("4");
    testObject.setField5("5");
    testObject.setField6("6");
    testObject.setField7("7");
    testObject.setField8("8");
    testObject.setField9("9");
    testObject.setField10("10");
    byteArrayOutputStream = new ByteArrayOutputStream();
    TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory();
    protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream));
}
 
開發者ID:json-iterator,項目名稱:java-benchmark,代碼行數:18,代碼來源:SerThrift.java

示例4: benchSetup

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1(31.415926);
    testObject.setField2(61.415923);
    testObject.setField3(31.415269);
    testObject.setField4(53.141926);
    testObject.setField5(13.145926);
    testObject.setField6(43.115926);
    testObject.setField7(31.419265);
    testObject.setField8(23.141596);
    testObject.setField9(43.161592);
    testObject.setField10(0.112);
    byteArrayOutputStream = new ByteArrayOutputStream();
    TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory();
    protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream));
}
 
開發者ID:json-iterator,項目名稱:java-benchmark,代碼行數:18,代碼來源:SerThrift.java

示例5: benchSetup

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.addToField1(321);
    testObject.addToField1(123);
    testObject.addToField1(132);
    testObject.addToField1(312);
    testObject.addToField1(321);
    testObject.addToField1(123);
    testObject.addToField1(132);
    testObject.addToField1(312);
    testObject.addToField1(321);
    testObject.addToField1(123);
    testObject.addToField1(132);
    testObject.addToField1(312);
    testObject.addToField1(321);
    testObject.addToField1(123);
    testObject.addToField1(132);
    testObject.addToField1(312);
    byteArrayOutputStream = new ByteArrayOutputStream();
    TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory();
    protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream));
}
 
開發者ID:json-iterator,項目名稱:java-benchmark,代碼行數:24,代碼來源:SerThrift.java

示例6: benchSetup

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1(31415926);
    testObject.setField2(61415923);
    testObject.setField3(31415269);
    testObject.setField4(53141926);
    testObject.setField5(13145926);
    testObject.setField6(43115926);
    testObject.setField7(31419265);
    testObject.setField8(23141596);
    testObject.setField9(43161592);
    testObject.setField10(112);
    byteArrayOutputStream = new ByteArrayOutputStream();
    TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory();
    protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream));
}
 
開發者ID:json-iterator,項目名稱:java-benchmark,代碼行數:18,代碼來源:SerThrift.java

示例7: decode

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Override
protected final Object decode(ChannelHandlerContext ctx,
                        ByteBuf buffer) throws Exception {
    /* This is initialized to null because the decode function must return
     * null if the buffer does not contain a complete frame and cannot be
     * decoded.
     */
    List<T> ms = null;
    ByteBuf frame = null;
    while (null != (frame = (ByteBuf) super.decode(ctx, buffer))) {
        if (ms == null) ms = new ArrayList<T>();
        ByteBufInputStream is = new ByteBufInputStream(frame);
        TCompactProtocol thriftProtocol =
                new TCompactProtocol(new TIOStreamTransport(is));
        T message = allocateMessage();
        message.read(thriftProtocol);
        ms.add(message);
    }
    return ms;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:21,代碼來源:ThriftFrameDecoder.java

示例8: encode

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, T msg, ByteBuf out)
        throws Exception {

    int lengthIndex = out.writerIndex();
    // length field, will be filled in later.
    out.writeInt(0);

    int startIndex = out.writerIndex();
    ByteBufOutputStream os = new ByteBufOutputStream(out);
    TCompactProtocol thriftProtocol =
            new TCompactProtocol(new TIOStreamTransport(os));
    msg.write(thriftProtocol);
    os.close();
    int endIndex = out.writerIndex();

    // update the length field
    int length = endIndex - startIndex;
    out.setInt(lengthIndex, length);
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:21,代碼來源:ThriftFrameEncoder.java

示例9: decode

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx,
                        Channel channel,
                        ChannelBuffer buffer) throws Exception {
    List<SyncMessage> ms = null;
    ChannelBuffer frame = null;
    while (null != (frame = (ChannelBuffer) super.decode(ctx, channel, 
                                                         buffer))) {
        if (ms == null) ms = new ArrayList<SyncMessage>();
        ChannelBufferInputStream is = new ChannelBufferInputStream(frame);
        TCompactProtocol thriftProtocol =
                new TCompactProtocol(new TIOStreamTransport(is));
        SyncMessage bsm = new SyncMessage();
        bsm.read(thriftProtocol);
        ms.add(bsm);
    }
    return ms;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:19,代碼來源:ThriftFrameDecoder.java

示例10: encode

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
                        Object message) throws Exception {
    if (message instanceof SyncMessage) {
        ChannelBuffer buf = new DynamicChannelBuffer(512);
        ChannelBufferOutputStream os = new ChannelBufferOutputStream(buf);
        TCompactProtocol thriftProtocol =
                new TCompactProtocol(new TIOStreamTransport(os));
        ((SyncMessage) message).write(thriftProtocol);

        ChannelBuffer len = ChannelBuffers.buffer(4);
        len.writeInt(buf.readableBytes());
        return ChannelBuffers.wrappedBuffer(len, buf);
    }
    return message;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:17,代碼來源:ThriftFrameEncoder.java

示例11: deflateNonNull

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
/**
 * Encodes a thrift object into a DEFLATE-compressed binary array.
 *
 * @param tBase Object to encode.
 * @return Deflated, encoded object.
 * @throws CodingException If the object could not be encoded.
 */
public static byte[] deflateNonNull(TBase<?, ?> tBase) throws CodingException {
  requireNonNull(tBase);

  // NOTE: Buffering is needed here for performance.
  // There are actually 2 buffers in play here - the BufferedOutputStream prevents thrift from
  // causing a call to deflate() on every encoded primitive. The DeflaterOutputStream buffer
  // allows the underlying Deflater to operate on a larger chunk at a time without stopping to
  // copy the intermediate compressed output to outBytes.
  // See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4986239
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  TTransport transport = new TIOStreamTransport(
      new BufferedOutputStream(
          new DeflaterOutputStream(outBytes, new Deflater(DEFLATE_LEVEL), DEFLATER_BUFFER_SIZE),
          DEFLATER_BUFFER_SIZE));
  try {
    TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
    tBase.write(protocol);
    transport.close(); // calls finish() on the underlying stream, completing the compression
    return outBytes.toByteArray();
  } catch (TException e) {
    throw new CodingException("Failed to serialize: " + tBase, e);
  } finally {
    transport.close();
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:33,代碼來源:ThriftBinaryCodec.java

示例12: inflateNonNull

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
/**
 * Decodes a thrift object from a DEFLATE-compressed byte array into a target type.
 *
 * @param clazz Class to instantiate and deserialize to.
 * @param buffer Compressed buffer to decode.
 * @return A populated message.
 * @throws CodingException If the message could not be decoded.
 */
public static <T extends TBase<T, ?>> T inflateNonNull(Class<T> clazz, byte[] buffer)
    throws CodingException {

  requireNonNull(clazz);
  requireNonNull(buffer);

  T tBase = newInstance(clazz);
  TTransport transport = new TIOStreamTransport(
        new InflaterInputStream(new ByteArrayInputStream(buffer)));
  try {
    TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
    tBase.read(protocol);
    return tBase;
  } catch (TException e) {
    throw new CodingException("Failed to deserialize: " + e, e);
  } finally {
    transport.close();
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:28,代碼來源:ThriftBinaryCodec.java

示例13: doPost

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
public static Result doPost() throws Exception {
    RequestBody requestBody = request().body();
    byte[] requestContent = null;
    RawBuffer rawBuffer = requestBody.asRaw();
    if (rawBuffer != null) {
        requestContent = rawBuffer.asBytes();
    } else {
        requestContent = requestBody.asText().getBytes(Constants.UTF8);
    }

    InputStream in = new ByteArrayInputStream(requestContent);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    TTransport transport = new TIOStreamTransport(in, out);
    TProtocol inProtocol = protocolFactory.getProtocol(transport);
    TProtocol outProtocol = protocolFactory.getProtocol(transport);
    processor.process(inProtocol, outProtocol);
    response().setHeader(CONTENT_TYPE, "application/x-thrift");
    return ok(out.toByteArray());
}
 
開發者ID:btnguyen2k,項目名稱:queue-server,代碼行數:20,代碼來源:ThriftController.java

示例14: serialize

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Override
public <Message extends PMessage<Message, Field>, Field extends PField>
int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<Message, Field> call)
        throws IOException {
    CountingOutputStream wrapper = new CountingOutputStream(output);
    TTransport transport = new TIOStreamTransport(wrapper);
    try {
        TProtocol protocol = protocolFactory.getProtocol(transport);
        TMessage tm = new TMessage(call.getMethod(), (byte) call.getType().asInteger(), call.getSequence());

        protocol.writeMessageBegin(tm);
        writeMessage(call.getMessage(), protocol);
        protocol.writeMessageEnd();

        transport.flush();
        wrapper.flush();
        return wrapper.getByteCount();
    } catch (TException e) {
        throw new SerializerException(e, e.getMessage());
    }
}
 
開發者ID:morimekta,項目名稱:providence,代碼行數:22,代碼來源:TProtocolSerializer.java

示例15: serialize

import org.apache.thrift.transport.TIOStreamTransport; //導入依賴的package包/類
@Override
public <Message extends PMessage<Message, Field>, Field extends PField>
int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<Message, Field> call)
        throws IOException {
    CountingOutputStream wrapper = new CountingOutputStream(output);
    TTransport transport = new TIOStreamTransport(wrapper);
    try {
        TTupleProtocol protocol = (TTupleProtocol) protocolFactory.getProtocol(transport);
        TMessage tm = new TMessage(call.getMethod(), (byte) call.getType().asInteger(), call.getSequence());

        protocol.writeMessageBegin(tm);
        writeMessage(call.getMessage(), protocol);
        protocol.writeMessageEnd();

        transport.flush();
        wrapper.flush();
        return wrapper.getByteCount();
    } catch (TException e) {
        throw new SerializerException(e, e.getMessage());
    }
}
 
開發者ID:morimekta,項目名稱:providence,代碼行數:22,代碼來源:TTupleProtocolSerializer.java


注:本文中的org.apache.thrift.transport.TIOStreamTransport類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。