@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; }
@Override public <T> T deSerialize(final byte[] param, final Class<T> clazz) throws MythException { 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 MythException("kryo deSerialize error" + e.getMessage()); } return object; }
private static <T extends Serializable> T deserializeObjectFromKryo(byte[] bytes, Class<T> clazz) { Input inp = new Input(new ByteArrayInputStream(bytes)); Kryo kryo = borrowKryo(); T func = null; try { func = kryo.readObject(inp, clazz); } finally { releaseKryo(kryo); } inp.close(); return func; }
/** * 反序列化. * * @param param 需要反序列化的byte [] * @return 序列化对象 * @throws HmilyException 异常 */ @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; }
private static <T> T deserializeObjectByKryo(Kryo kryo, InputStream in, Class<T> clazz ) { Input inp = new Input(in); kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader()); T t = kryo.readObject(inp,clazz); inp.close(); return t; }
in.close();
public synchronized void clear() { writeCursor = readCursor = rowsInReadBuffer = 0; readBufferUsed = false; if (parentFile != null) { if (input != null) { try { input.close(); } catch (Throwable ignored) { } input = null; } if (output != null) { try { output.close(); } catch (Throwable ignored) { } output = null; } try { FileUtil.fullyDelete(parentFile); } catch (Throwable ignored) { } parentFile = null; tmpFile = null; } }
public void clear() { readCursor = rowsInReadBuffer = rowsOnDisk = 0; readBufferUsed = false; if (parentDir != null) { if (input != null) { try { input.close(); } catch (Throwable ignored) { } input = null; } if (output != null) { try { output.close(); } catch (Throwable ignored) { } output = null; } try { FileUtil.fullyDelete(parentDir); } catch (Throwable ignored) { } parentDir = null; tmpFile = null; } }
public void clear() { readCursor = rowsInReadBuffer = rowsOnDisk = 0; readBufferUsed = false; if (parentDir != null) { if (input != null) { try { input.close(); } catch (Throwable ignored) { } input = null; } if (output != null) { try { output.close(); } catch (Throwable ignored) { } output = null; } try { FileUtil.fullyDelete(parentDir); } catch (Throwable ignored) { } parentDir = null; tmpFile = null; } }
public BytesBytesMultiHashMap getHashMapFromDisk(int rowCount) throws IOException, ClassNotFoundException { if (hashMapSpilledOnCreation) { return new BytesBytesMultiHashMap(rowCount, loadFactor, wbSize, -1); } else { InputStream inputStream = Files.newInputStream(hashMapLocalPath); com.esotericsoftware.kryo.io.Input input = new com.esotericsoftware.kryo.io.Input(inputStream); Kryo kryo = SerializationUtilities.borrowKryo(); BytesBytesMultiHashMap restoredHashMap = null; try { restoredHashMap = kryo.readObject(input, BytesBytesMultiHashMap.class); } finally { SerializationUtilities.releaseKryo(kryo); } if (rowCount > 0) { restoredHashMap.expandAndRehashToTarget(rowCount); } // some bookkeeping rowsOnDisk = 0; hashMapOnDisk = false; input.close(); inputStream.close(); Files.delete(hashMapLocalPath); return restoredHashMap; } }
input.close(); input = null;
input.close(); input = null;
input.close(); input = null;
@Override public <T> T toObject(byte[] bytes, Class<T> type) { Input input = new Input(bytes); T result = kryo.get().readObject(input, type); input.close(); return result; } }
@Override public <T> T decode(byte[] bytes, Class<T> type) throws IOException { Assert.notNull(bytes, "'bytes' cannot be null"); final Input input = new Input(bytes); try { return decode(input, type); } finally { input.close(); } }
@Override public Object deserialize(final byte[] bytes) throws ZkMarshallingError { Object object; try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { Kryo kryo = new Kryo(); Input input = new Input(inputStream); object = kryo.readClassAndObject(input); input.close(); } catch (IOException e) { throw new SerializerException("kryo deSerialize error" + e.getMessage()); } return object; }
@Override public <T> T decode(InputStream inputStream, final Class<T> type) throws IOException { Assert.notNull(inputStream, "'inputStream' cannot be null"); Assert.notNull(type, "'type' cannot be null"); final Input input = (inputStream instanceof Input ? (Input) inputStream : new Input(inputStream)); T result = null; try { result = this.pool.run(kryo -> doDecode(kryo, input, type)); } finally { input.close(); } return result; }
Kryo kryo = new Kryo(); // #### Store to disk... Output output = new Output(new FileOutputStream("file.bin")); SomeClass someObject = ... kryo.writeObject(output, someObject); output.close(); // ### Restore from disk... Input input = new Input(new FileInputStream("file.bin")); SomeClass someObject = kryo.readObject(input, SomeClass.class); input.close();
@Override public Object fromByteArray(Slice fragment) { final Input input = new Input(fragment.buffer, fragment.offset, fragment.length); try { return kryo.readClassAndObject(input); } finally { input.close(); } }
@Override public void close() { output.close(); input.close(); input.setBuffer(park); // clean input output.setBuffer(park, Integer.MAX_VALUE); // clear output kryopool.offer(this); } }