Java Code Examples for org.apache.thrift.transport.TMemoryBuffer#write()
The following examples show how to use
org.apache.thrift.transport.TMemoryBuffer#write() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemTrans.java From ThriftBook with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException, TTransportException, ClassNotFoundException { TMemoryBuffer transport = new TMemoryBuffer(4096); Trade trade = new Trade(); trade.symbol = "F"; trade.price = 13.10; trade.size = 2500; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(trade); transport.write(baos.toByteArray()); byte[] buf = new byte[128]; int bytes_read = transport.read(buf, 0, buf.length); ByteArrayInputStream bais = new ByteArrayInputStream(buf); ObjectInputStream ois = new ObjectInputStream(bais); Trade trade_read = (Trade) ois.readObject(); System.out.println("Trade(" + bytes_read + "): " + trade_read.symbol + " " + trade_read.size + " @ " + trade_read.price); }
Example 2
Source File: TestZipkinSpanReceiver.java From incubator-retired-htrace with Apache License 2.0 | 5 votes |
@Override public void send(List<byte[]> spans) throws IOException { for (byte[] message : spans) { TMemoryBuffer transport = new TMemoryBuffer(message.length); try { transport.write(message); com.twitter.zipkin.gen.Span zSpan = new com.twitter.zipkin.gen.Span(); zSpan.read(new TBinaryProtocol(transport)); receivedSpans.add(zSpan); } catch (TException e) { throw new IOException(e); } } }
Example 3
Source File: TradeReader.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] argv) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException, TException, TTransportException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, true, consumer); System.out.println("Waiting for trade reports..."); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); byte[] data = delivery.getBody(); TMemoryBuffer trans = new TMemoryBuffer(data.length); trans.write(data, 0, data.length); TCompactProtocol proto = new TCompactProtocol(trans); TradeReport tr = new TradeReport(); tr.read(proto); System.out.println("[" + tr.seq_num + "] " + tr.symbol + " @ " + tr.price + " x " + tr.size); } }