當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。