List of usage examples for org.apache.thrift TBase clear
public void clear();
From source file:com.facebook.buck.slb.ThriftUtil.java
License:Apache License
public static void deserialize(ThriftProtocol protocol, byte[] source, TBase<?, ?> dest) throws ThriftException { TDeserializer deserializer = new TDeserializer(getProtocolFactory(protocol)); dest.clear(); try {//ww w .j a va 2 s .co m deserializer.deserialize(dest, source); } catch (TException e) { throw new ThriftException(e); } }
From source file:org.diqube.data.serialize.DataDeserializer.java
License:Open Source License
/** * Deserialize the data available in a byte array into a {@link DataSerialization} object hierarchy. * /* w w w. j a va 2s . c om*/ * @param inputStream * the stream containign the data to be deserialized. It will be tried to close this input stream as soon as * possible to free any resources. * @throws DeserializationException * if anything went wrong. */ // we need to capture the generics here to make javac happy public <T extends TBase<?, ?>, M extends TBase<?, ?>, O extends DataSerialization<M>> O deserialize( Class<? extends O> targetClass, InputStream inputStream) throws DeserializationException { logger.trace("Deserializing to thrift..."); @SuppressWarnings("unchecked") T thrift = deserializeToThrift(inputStream, (Class<? extends T>) thriftClasses.get(targetClass)); try { inputStream.close(); } catch (IOException e) { // swallow. } inputStream = null; DataSerializationHelper helper = dataSerializationHelperFactory.apply(new Consumer<TBase<?, ?>>() { @Override public void accept(TBase<?, ?> t) { // cleanup action is to clear all field values to release memory as soon as possible. t.clear(); } }); logger.trace("Transforming into final objects..."); @SuppressWarnings("unchecked") Class<? extends O> targetClz = (Class<? extends O>) liveClasses.get(thrift.getClass()); O res = helper.deserializeChild(targetClz, thrift); logger.trace("Deserialization done."); return res; }