List of usage examples for org.apache.thrift TDeserializer TDeserializer
public TDeserializer(TProtocolFactory protocolFactory)
From source file:org.apache.jena.riot.thrift.ThriftConvert.java
License:Apache License
/** * Deserialize from a byte array into an {@link RDF_Term}. * <p>/*w w w . j av a2 s . com*/ * Where possible, to is better to deserialize from a stream, directly using {@code term.read(TProtocol)}. */ public static void termFromBytes(RDF_Term term, byte[] bytes) { TDeserializer deserializer = new TDeserializer(new TCompactProtocol.Factory()); try { deserializer.deserialize(term, bytes); } catch (TException e) { throw new RiotThriftException(e); } }
From source file:org.apache.sentry.hdfs.TestHMSPathsFullDump.java
License:Apache License
@Test public void testThrftSerialization() throws TException { HMSPathsDumper serDe = genHMSPathsDumper(); long t1 = System.currentTimeMillis(); TPathsDump pathsDump = serDe.createPathsDump(); TProtocolFactory protoFactory = useCompact ? new TCompactProtocol.Factory( ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT, ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT) : new TBinaryProtocol.Factory(true, true, ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT, ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT); byte[] ser = new TSerializer(protoFactory).serialize(pathsDump); long serTime = System.currentTimeMillis() - t1; System.out.println("Serialization Time: " + serTime + ", " + ser.length); t1 = System.currentTimeMillis(); TPathsDump tPathsDump = new TPathsDump(); new TDeserializer(protoFactory).deserialize(tPathsDump, ser); HMSPaths fromDump = serDe.initializeFromDump(tPathsDump); System.out.println("Deserialization Time: " + (System.currentTimeMillis() - t1)); Assert.assertEquals("db9.tbl999", fromDump.findAuthzObject(new String[] { "user", "hive", "warehouse", "db9", "tbl999" }, false)); Assert.assertEquals("db9.tbl999", fromDump .findAuthzObject(new String[] { "user", "hive", "warehouse", "db9", "tbl999", "part99" }, false)); }
From source file:org.apache.sentry.hdfs.ThriftSerializer.java
License:Apache License
@SuppressWarnings("rawtypes") public static TBase deserialize(TBase baseObject, byte[] serialized) throws IOException { TDeserializer deserializer = new TDeserializer( new TCompactProtocol.Factory(maxMessageSize, maxMessageSize)); try {// w ww . ja v a 2 s . c o m deserializer.deserialize(baseObject, serialized); } catch (TException e) { throw new IOException("Error deserializing thrift object " + baseObject, e); } return baseObject; }
From source file:org.jhk.pulsing.storm.kryo.serializer.ThriftDataSerializer.java
License:Apache License
@Override public Data read(Kryo kryo, Input input, Class<Data> type) { _LOGGER.info("ThriftDataSerializer.read name={}, length={}", type.getName(), input.getBuffer().length); TDeserializer dSerializer = new TDeserializer(new TBinaryProtocol.Factory()); Data data = new Data(); try {//www. j av a2s . c om //TODO make sure that it comes in read (meaning the buffer), at the moment //since single machine won't be serializing and deserializing dSerializer.deserialize(data, input.getBuffer()); } catch (TException tException) { tException.printStackTrace(); } return data; }
From source file:org.kie.server.remote.rest.extension.ThriftMessageReader.java
License:Apache License
public static TDeserializer pollTDeserializer() { TDeserializer tDeserializer = T_DESERIALIZER_QUEUE.poll(); if (tDeserializer == null) { tDeserializer = new TDeserializer(T_PROTOCOL_FACTORY); }//from ww w . ja va 2s .com return tDeserializer; }
From source file:tech.sirwellington.alchemy.thrift.ThriftObjects.java
License:Apache License
/** * Inflates the prototype object from the supplied JSON. * * @param <T> The type of the Thrift Object * @param prototype The prototype Object to deserialize into * @param json The Simple JSON generated from {@link #toJson(org.apache.thrift.TBase) } * * @return The Deserialized Prototype Object. * * @throws TException/*from w w w .ja v a 2 s.c om*/ */ public static <T extends TBase> T fromJson(@NonNull T prototype, @NonEmpty String json) throws TException { checkThat(prototype).usingMessage("missing prototype").is(notNull()); if (isNullOrEmpty(json)) { LOG.warn("JSON String is empty"); return prototype; } TProtocolFactory protocol = new TJSONProtocol.Factory(); TDeserializer deserializer = new TDeserializer(protocol); deserializer.deserialize(prototype, json, UTF_8.name()); LOG.debug("Prototype TObject inflated to {} from json {}", prototype, json); return prototype; }
From source file:tech.sirwellington.alchemy.thrift.ThriftObjects.java
License:Apache License
public static <T extends TBase> T fromBinary(@NonNull T prototype, @NonEmpty byte[] binary) throws TException { checkThat(prototype).usingMessage("missing prototype").is(notNull()); if (binary == null || binary.length == 0) { LOG.warn("missing binary: {}", binary); return prototype; }//w ww . ja v a 2 s . com TProtocolFactory protocol = new TBinaryProtocol.Factory(true, true); TDeserializer deserializer = new TDeserializer(protocol); deserializer.deserialize(prototype, binary); LOG.debug("Binary with length {} deserialized into TObject {}", binary.length, protocol); return prototype; }
From source file:zipkin.benchmarks.CodecBenchmarks.java
License:Apache License
private static com.twitter.zipkin.thriftjava.Span deserialize(byte[] serialized) { com.twitter.zipkin.thriftjava.Span result = new com.twitter.zipkin.thriftjava.Span(); try {// w w w .j a v a 2 s. com // TDeserializer isn't thread-safe new TDeserializer(TBINARY_PROTOCOL_FACTORY).deserialize(result, serialized); } catch (TException e) { throw new AssertionError(e); } return result; }