Example usage for org.apache.thrift.transport TIOStreamTransport flush

List of usage examples for org.apache.thrift.transport TIOStreamTransport flush

Introduction

In this page you can find the example usage for org.apache.thrift.transport TIOStreamTransport flush.

Prototype

public void flush() throws TTransportException 

Source Link

Document

Flushes the underlying output stream if not null.

Usage

From source file:io.mandrel.OtherTest.java

License:Apache License

@Test
@SneakyThrows//from w  w  w  .j a v a  2  s .co m
public void dummy() {
    Event event = Event.forSpider();
    event.setText("pouet");
    event.getSpider().setSpiderId(1);
    event.getSpider().setSpiderName("tesss");
    event.getSpider().setType(SpiderEventType.SPIDER_CREATED);

    ObjectMapper mapper = new ObjectMapper();
    BindConfiguration.configure(mapper);

    String res = mapper.writeValueAsString(event);
    System.err.println(res);

    // ThriftCodec<LocalDateTime> codec = new ThriftCodec<LocalDateTime>() {
    // @Override
    // public void write(LocalDateTime value, TProtocol protocol) throws
    // Exception {
    // protocol.writeI64(value.toInstant(ZoneOffset.UTC).toEpochMilli());
    // }
    //
    // @Override
    // public LocalDateTime read(TProtocol protocol) throws Exception {
    // return
    // LocalDateTime.ofInstant(Instant.ofEpochMilli(protocol.readI64()),
    // ZoneOffset.UTC);
    // }
    //
    // @Override
    // public ThriftType getType() {
    // return ThriftType.I64;
    // }
    // };

    ThriftCatalog catalog = new ThriftCatalog();

    catalog.addDefaultCoercions(Dummy.class);
    ThriftCodecManager manager = new ThriftCodecManager(
            new CompilerThriftCodecFactory(ThriftCodecManager.class.getClassLoader()), catalog,
            Collections.emptySet());
    TIOStreamTransport trans = new TIOStreamTransport(System.err);
    TJSONProtocol protocol = new TJSONProtocol(trans);

    manager.write(Event.class, event, protocol);
    manager.write(Uri.class, new Uri("scheme", "userInfo", "host", 0, "path", "query"), protocol);

    trans.flush();
}