本文整理匯總了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();
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
示例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());
}
示例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);
}
}
示例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());
}
示例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();
}
}
}
示例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);
}
}
示例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);
}
示例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();
}