当前位置: 首页>>代码示例>>Java>>正文


Java TBase.write方法代码示例

本文整理汇总了Java中org.apache.thrift.TBase.write方法的典型用法代码示例。如果您正苦于以下问题:Java TBase.write方法的具体用法?Java TBase.write怎么用?Java TBase.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.thrift.TBase的用法示例。


在下文中一共展示了TBase.write方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deflateNonNull

import org.apache.thrift.TBase; //导入方法依赖的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

示例2: writeResult

import org.apache.thrift.TBase; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private void writeResult(final TProtocol out, final TMessage msg, final WriterHandler onComplete, TBase args,
		final TBase result) {
	try {
		onComplete.beforeWrite(msg, args, result);
		// if (!isOneway()) {
		out.writeMessageBegin(new TMessage(msg.name, TMessageType.REPLY, msg.seqid));
		if (result != null) {
			result.write(out);
		} else {
			out.writeStructBegin(null);
			out.writeFieldStop();
			out.writeStructEnd();
		}
		out.writeMessageEnd();
		out.getTransport().flush();
		// }
		onComplete.afterWrite(msg, null, TMessageType.REPLY, args, result);
	} catch (Throwable e) {
		onComplete.afterWrite(msg, e, TMessageType.EXCEPTION, args, result);
	}
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:23,代码来源:DefaultNettyProcessor.java

示例3: write

import org.apache.thrift.TBase; //导入方法依赖的package包/类
private void write(final TBase<?, ?> base, final String fieldName, final List<ByteArrayOutput> list) throws TException {
    final TReplaceListProtocol protocol = new TReplaceListProtocol(protocolFactory.getProtocol(transport));

    // write chunk header
    writeChunkHeader(protocol);

    // write header
    writeHeader(protocol, locator.headerLookup(base));
    if (list != null && list.size() > 0) {
        protocol.addReplaceField(fieldName, list);
    }

    base.write(protocol);

    if (isNeedFlush()) {
        flush();
    }
}
 
开发者ID:masonmei,项目名称:apm-agent,代码行数:19,代码来源:ChunkHeaderBufferedTBaseSerializer.java

示例4: write

import org.apache.thrift.TBase; //导入方法依赖的package包/类
/**
 * Write the object to disk.
 */
public void write(TBase t) throws IOException {
  try {
    t.write(binaryOut);
    dataOutputStream.flush();
  } catch (TException e) {
    throw new IOException(e);
  }
}
 
开发者ID:carbondata,项目名称:carbondata,代码行数:12,代码来源:ThriftWriter.java

示例5: serializeUserData

import org.apache.thrift.TBase; //导入方法依赖的package包/类
private byte[] serializeUserData(TProtocolFactory protocolFactory, TBase userData) throws TException {
    TMemoryBufferWithLength memoryBuffer = new TMemoryBufferWithLength(MEMORY_BUFFER_LENGTH);

    TProtocol protocol = protocolFactory.getProtocol(memoryBuffer);

    if (protocol instanceof TJSONProtocol) {
        memoryBuffer.write(COLON, 0, 1);
    }
    userData.write(protocol);

    return Arrays.copyOf(memoryBuffer.getArray(), memoryBuffer.length());
}
 
开发者ID:aatarasoff,项目名称:thrift-api-gateway-core,代码行数:13,代码来源:MessageTransalator.java

示例6: write

import org.apache.thrift.TBase; //导入方法依赖的package包/类
/**
  * Write the object to disk.
  */
public void write(TBase t) throws IOException {
  try {
    t.write(protocolOut);
    bufferedOut.flush();
  } catch (TException e) {
    throw new IOException(e);
  }
}
 
开发者ID:mspertus,项目名称:Big-Data-tutorial,代码行数:12,代码来源:ThriftWriter.java

示例7: save

import org.apache.thrift.TBase; //导入方法依赖的package包/类
@Nonnull
public static byte[] save(@Nonnull TBase<?, ?> object) throws TException {
    // AutoExpandingBufferWriteTransport transport = new AutoExpandingBufferWriteTransport(4096, 1.4);
    TMemoryBuffer transport = new TMemoryBuffer(4096);
    TProtocol protocol = new TCompactProtocol(transport);
    object.write(protocol);
    // return new ByteArray(transport.getBuf().array(), 0, transport.getPos());
    return Arrays.copyOf(transport.getArray(), transport.length());
}
 
开发者ID:shevek,项目名称:simple-xml-serializers,代码行数:10,代码来源:ThriftUtils.java

示例8: encodeSuccess

import org.apache.thrift.TBase; //导入方法依赖的package包/类
private static HttpData encodeSuccess(ServiceRequestContext ctx,
                                      RpcResponse reply,
                                      SerializationFormat serializationFormat,
                                      String methodName, int seqId,
                                      TBase<?, ?> result) {

    final ByteBuf buf = ctx.alloc().buffer(128);
    boolean success = false;
    try {
        final TTransport transport = new TByteBufTransport(buf);
        final TProtocol outProto = ThriftProtocolFactories.get(serializationFormat).getProtocol(transport);
        final TMessage header = new TMessage(methodName, TMessageType.REPLY, seqId);
        outProto.writeMessageBegin(header);
        result.write(outProto);
        outProto.writeMessageEnd();

        ctx.logBuilder().responseContent(reply, new ThriftReply(header, result));

        final HttpData encoded = new ByteBufHttpData(buf, false);
        success = true;
        return encoded;
    } catch (TException e) {
        throw new Error(e); // Should never reach here.
    } finally {
        if (!success) {
            buf.release();
        }
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:30,代码来源:THttpService.java

示例9: serialize

import org.apache.thrift.TBase; //导入方法依赖的package包/类
/**
 * Serialize a {@link DataSerialization} object into an output stream and flush that stream.
 * 
 * @param obj
 *          The object to serialize.
 * @param outputStream
 *          The output stream to fill.
 * @param objectDoneConsumer
 *          Will be called when single objects (referenced transitively from obj) have been "serialized" and can be
 *          freed by the caller, if needed.
 * @throws SerializationException
 *           If anything went wrong.
 */
public void serialize(DataSerialization<?> obj, OutputStream outputStream, ObjectDoneConsumer objectDoneConsumer)
    throws SerializationException {
  DataSerializationHelper helper = dataSerializationHelperFactory.apply(objectDoneConsumer);
  TBase<?, ?> res = helper.serializeChild(thriftClasses.get(obj.getClass()), obj);
  TIOStreamTransport transport = new TIOStreamTransport(outputStream);
  TProtocol compactProt = new TCompactProtocol(transport);
  try {
    res.write(compactProt);
    outputStream.flush();
  } catch (TException | IOException e) {
    throw new SerializationException("Could not serialize", e);
  }
}
 
开发者ID:diqube,项目名称:diqube,代码行数:27,代码来源:DataSerializer.java

示例10: write

import org.apache.thrift.TBase; //导入方法依赖的package包/类
public void write(final TBase<?, ?> base) throws TException {
    final TBaseStreamNode node = new TBaseStreamNode(transport);
    node.setClassName(base.getClass().getName());
    node.setBeginPosition(transport.getBufferPosition());

    final TProtocol protocol = protocolFactory.getProtocol(transport);
    base.write(protocol);

    node.setEndPosition(transport.getBufferPosition());
    nodes.add(node);
}
 
开发者ID:masonmei,项目名称:apm-agent,代码行数:12,代码来源:TBaseStream.java

示例11: serialize

import org.apache.thrift.TBase; //导入方法依赖的package包/类
/**
 * Serialize the Thrift object into a byte array. The process is simple,
 * just clear the byte array output, write the object into it, and grab the
 * raw bytes.
 *
 * @param base The object to serialize
 * @return Serialized object in byte[] format
 */
public byte[] serialize(TBase<?, ?> base) throws TException {
    final Header header = locator.headerLookup(base);
    baos.reset();
    writeHeader(header);
    base.write(protocol);
    return baos.toByteArray();
}
 
开发者ID:masonmei,项目名称:apm-agent,代码行数:16,代码来源:HeaderTBaseSerializer.java


注:本文中的org.apache.thrift.TBase.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。