Java Code Examples for com.esotericsoftware.kryo.io.Input#close()
The following examples show how to use
com.esotericsoftware.kryo.io.Input#close() .
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: SparkValueRowSerializerTest.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testEncodingDecodingSeveralRows() throws IOException, StandardException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Output output = new Output(out); for (int i = 0; i < 100; i++) { kryo.writeClassAndObject(output, getExecRow(i, 13)); } output.close(); InputStream in = new ByteArrayInputStream(out.toByteArray()); Input input = new Input(in); for (int i = 0; i < 100; i++) { ExecRow row = (ExecRow) kryo.readClassAndObject(input); assertEquals(i, row.getRowArray()[0].getInt()); assertEquals(""+i, row.getRowArray()[1].getString()); } input.close(); }
Example 2
Source File: AbstractFileOutputOperatorTest.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
/** * This method checkpoints the given writer. * @param writer The writer to checkpoint. * @return new writer. */ public static AbstractFileOutputOperator checkpoint(AbstractFileOutputOperator writer, long windowId) { if (windowId >= Stateless.WINDOW_ID) { writer.beforeCheckpoint(windowId); } Kryo kryo = new Kryo(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Output loutput = new Output(bos); kryo.writeObject(loutput, writer); loutput.close(); Input lInput = new Input(bos.toByteArray()); @SuppressWarnings("unchecked") AbstractFileOutputOperator checkPointedWriter = kryo.readObject(lInput, writer.getClass()); lInput.close(); return checkPointedWriter; }
Example 3
Source File: KryoSerialize.java From search-spring-boot-starter with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings({ "unchecked" }) public <T> T decode(byte[] bytes, Class<T> clazz) { Kryo kryo = new Kryo(); kryo.setReferences(false); kryo.register(clazz, new JavaSerializer()); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); Input input = new Input(byteArrayInputStream); try { return (T) kryo.readClassAndObject(input); } finally { input.close(); try { byteArrayInputStream.close(); } catch (IOException e) { } } }
Example 4
Source File: AbstractFileInputOperatorTest.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
/** * This method checkpoints the given operator. * @param oper The operator to checkpoint. * @param bos The ByteArrayOutputStream which saves the checkpoint data temporarily. * @return new operator. */ public static <T> T checkpoint(T oper, ByteArrayOutputStream bos) throws Exception { Kryo kryo = new Kryo(); Output loutput = new Output(bos); kryo.writeObject(loutput, oper); loutput.close(); Input lInput = new Input(bos.toByteArray()); @SuppressWarnings("unchecked") T checkPointedOper = kryo.readObject(lInput, (Class<T>)oper.getClass()); lInput.close(); return checkPointedOper; }
Example 5
Source File: SparkValueRowSerializerTest.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testDecimalBufferedSumAggregator() throws IOException, StandardException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Output output = new Output(out); DecimalBufferedSumAggregator lbsa = new DecimalBufferedSumAggregator(64); lbsa.add(new SQLDecimal(new BigDecimal(23.0))); lbsa.add(new SQLDecimal(new BigDecimal(23.0))); kryo.writeClassAndObject(output, lbsa); output.close(); InputStream in = new ByteArrayInputStream(out.toByteArray()); Input input = new Input(in); DecimalBufferedSumAggregator lbsa2 = (DecimalBufferedSumAggregator) kryo.readClassAndObject(input); assertEquals(lbsa.getResult(), lbsa2.getResult()); input.close(); }
Example 6
Source File: SamzaKryoSerdeFactory.java From samoa with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public V fromBytes(byte[] byteArr) { Input input = new Input(byteArr); Object obj = kryo.readClassAndObject(input); input.close(); return (V)obj; }
Example 7
Source File: KryoSerialization.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Object deserializeFrom(final byte[] data) throws SerializationException { final ByteArrayInputStream stream = new ByteArrayInputStream(data); final Kryo kryo = new Kryo(); final Input input = new Input(stream); kryo.setInstantiatorStrategy(new SerializingInstantiatorStrategy()); final Object obj = kryo.readClassAndObject(input); input.close(); return obj; }
Example 8
Source File: SparkValueRowSerializerTest.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testLongBufferedSumAggregator() throws IOException, StandardException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Output output = new Output(out); LongBufferedSumAggregator lbsa = new LongBufferedSumAggregator(64); lbsa.add(new SQLLongint(100)); lbsa.add(new SQLLongint(200)); kryo.writeClassAndObject(output, lbsa); output.close(); InputStream in = new ByteArrayInputStream(out.toByteArray()); Input input = new Input(in); LongBufferedSumAggregator lbsa2 = (LongBufferedSumAggregator) kryo.readClassAndObject(input); assertEquals(lbsa.getResult(), lbsa2.getResult()); input.close(); }
Example 9
Source File: KryoTest.java From RoaringBitmap with Apache License 2.0 | 5 votes |
public static RoaringBitmap readRoaringFromFile(File f, Serializer<RoaringBitmap> serializer) throws FileNotFoundException { Kryo kryo = createKryo(); Input inputMap = new Input(new FileInputStream(f)); RoaringBitmap roaring = kryo.readObjectOrNull(inputMap, RoaringBitmap.class, serializer); inputMap.close(); return roaring; }
Example 10
Source File: KryoSerializer.java From hmily with Apache License 2.0 | 5 votes |
@Override public <T> T deSerialize(final byte[] param, final Class<T> clazz) throws HmilyException { T object; try (ByteArrayInputStream inputStream = new ByteArrayInputStream(param)) { Kryo kryo = new Kryo(); Input input = new Input(inputStream); object = kryo.readObject(input, clazz); input.close(); } catch (IOException e) { throw new HmilyException("kryo deSerialize error" + e.getMessage()); } return object; }
Example 11
Source File: KryoSerialization.java From craft-atom with MIT License | 5 votes |
@Override public RpcBody deserialize(byte[] bytes, int off) { try { Assert.notNull(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(bytes, off, bytes.length - off); Input input = new Input(bais); RpcBody rb = kryo().readObject(input, RpcBody.class); input.close(); return rb; } catch (Exception e) { throw new ProtocolException(e); } }
Example 12
Source File: KryoSerializer.java From Raincat with GNU Lesser General Public License v3.0 | 5 votes |
@Override public <T> T deSerialize(final byte[] param, final Class<T> clazz) throws TransactionException { T object; try (ByteArrayInputStream inputStream = new ByteArrayInputStream(param)) { Kryo kryo = new Kryo(); Input input = new Input(inputStream); object = kryo.readObject(input, clazz); input.close(); } catch (IOException e) { throw new TransactionException("kryo deSerialize error" + e.getMessage()); } return object; }
Example 13
Source File: SerializeUtils.java From blockchain with Apache License 2.0 | 5 votes |
/** * 反序列化 * * @param bytes 对象对应的字节数组 * @return */ public static Object unSerialize(byte[] bytes) { Input input = new Input(bytes); Object obj = new Kryo().readClassAndObject(input); input.close(); return obj; }
Example 14
Source File: AbstractFileInputOperatorTest.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * Restores the checkpointed operator. * @param checkPointOper The checkpointed operator. * @param bos The ByteArrayOutputStream which saves the checkpoint data temporarily. */ @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> T restoreCheckPoint(T checkPointOper, ByteArrayOutputStream bos) throws Exception { Kryo kryo = new Kryo(); Input lInput = new Input(bos.toByteArray()); T oper = kryo.readObject(lInput, (Class<T>)checkPointOper.getClass()); lInput.close(); return oper; }
Example 15
Source File: TestSerDeserPer.java From eagle with Apache License 2.0 | 5 votes |
@Test public void testSerDeserPerf2() throws Exception { Kryo kryo = new Kryo(); String outputPath = temporaryFolder.newFile().toString(); Output output = new Output(new FileOutputStream(outputPath)); for (int i = 0; i < 1000; i++) { kryo.writeObject(output, constructNewPE()); } output.close(); Input input = new Input(new FileInputStream(outputPath)); NewPartitionedEvent someObject = kryo.readObject(input, NewPartitionedEvent.class); input.close(); Assert.assertTrue(someObject.getData().length == 1); }
Example 16
Source File: TestSiteToSiteClient.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testSerialization() { final SiteToSiteClientConfig clientConfig = new SiteToSiteClient.Builder() .url("http://localhost:8080/nifi") .portName("input") .buildConfig(); final Kryo kryo = new Kryo(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final Output output = new Output(out); try { kryo.writeObject(output, clientConfig); } finally { output.close(); } final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final Input input = new Input(in); try { SiteToSiteClientConfig clientConfig2 = kryo.readObject(input, SiteToSiteClient.StandardSiteToSiteClientConfig.class); Assert.assertEquals(clientConfig.getUrls(), clientConfig2.getUrls()); } finally { input.close(); } }
Example 17
Source File: SamzaKryoSerdeFactory.java From incubator-samoa with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public V fromBytes(byte[] byteArr) { Input input = new Input(byteArr); Object obj = kryo.readClassAndObject(input); input.close(); return (V) obj; }
Example 18
Source File: SamoaSerializer.java From samoa with Apache License 2.0 | 5 votes |
@Override public Object deserialize(ByteBuffer rawMessage) { Input input = new Input(rawMessage.array()); try { return kryoThreadLocal.get().readClassAndObject(input); } finally { input.close(); } }
Example 19
Source File: SerializeUtils.java From blockchain-java with Apache License 2.0 | 5 votes |
/** * 反序列化 * * @param bytes 对象对应的字节数组 * @return */ public static Object deserialize(byte[] bytes) { Input input = new Input(bytes); Object obj = new Kryo().readClassAndObject(input); input.close(); return obj; }
Example 20
Source File: KryoDocumentDeserializer.java From datawave with Apache License 2.0 | 5 votes |
@Override public Document deserialize(InputStream data) { Input input = new Input(data); Document document = kryo.readObject(input, Document.class); if (null == document) { throw new RuntimeException("Deserialized null Document"); } input.close(); return document; }