private static byte[] serializeObjectToKryo(Serializable object) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Output output = new Output(baos); Kryo kryo = borrowKryo(); try { kryo.writeObject(output, object); } finally { releaseKryo(kryo); } output.close(); return baos.toByteArray(); }
public static byte[] serialize(Object object) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Output output = new Output(stream); Kryo kryo = SerializationUtilities.borrowKryo(); kryo.setClassLoader(Thread.currentThread().getContextClassLoader()); try { kryo.writeObject(output, object); } finally { SerializationUtilities.releaseKryo(kryo); } output.close(); // close() also calls flush() return stream.toByteArray(); }
/** * @param plan Usually of type MapredWork, MapredLocalWork etc. * @param out stream in which serialized plan is written into */ private static void serializeObjectByKryo(Kryo kryo, Object plan, OutputStream out) { Output output = new Output(out); kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader()); kryo.writeObject(output, plan); output.close(); }
@Override public void serialize(final OutputStream output, final Object object) throws IOException { Kryo kryo = pool.borrow(); Output out = new Output(output); kryo.writeClassAndObject(out, object); out.close(); output.close(); pool.release(kryo); }
output.close();
SerializationUtilities.releaseKryo(kryo); output.close(); return true; } catch (IOException e) {
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; } }
@Override public ByteBuf encode(Object in) throws IOException { Kryo kryo = null; ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream baos = new ByteBufOutputStream(out); Output output = new Output(baos); kryo = kryoPool.get(); kryo.writeClassAndObject(output, in); output.close(); return baos.buffer(); } catch (Exception e) { out.release(); if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RedissonKryoCodecException(e); } finally { if (kryo != null) { kryoPool.yield(kryo); } } } };
@Override public ByteBuf encode(Object in) throws IOException { Kryo kryo = null; ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream baos = new ByteBufOutputStream(out); Output output = new Output(baos); kryo = kryoPool.get(); kryo.writeClassAndObject(output, in); output.close(); return baos.buffer(); } catch (Exception e) { out.release(); if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RedissonKryoCodecException(e); } finally { if (kryo != null) { kryoPool.yield(kryo); } } } };
public static String toKryo(SearchArgument sarg) { Output out = new Output(4 * 1024, 10 * 1024 * 1024); new Kryo().writeObject(out, sarg); out.close(); return Base64.encodeBase64String(out.toBytes()); }
LOG.info("Trying to spill hash partition " + partitionId + " ..."); output.close(); outputStream.close(); } finally {
public void save(OutputStream outputStream) { Kryo kryo = makeKryo(); LOG.debug("Consolidating edges..."); Output output = new Output(outputStream); // this is not space efficient List<Edge> edges = new ArrayList<Edge>(this.countEdges()); for (Vertex v : getVertices()) { // there are assumed to be no edges in an incoming list that are not // in an outgoing list edges.addAll(v.getOutgoing()); if (v.getDegreeOut() + v.getDegreeIn() == 0) LOG.debug("vertex {} has no edges, it will not survive serialization.", v); } LOG.debug("Assigning vertex/edge ID numbers..."); this.rebuildVertexAndEdgeIndices(); LOG.debug("Writing edges..."); kryo.writeClassAndObject(output, this); kryo.writeClassAndObject(output, edges); output.close(); LOG.info("Graph written."); // Summarize serialized classes and associated serializers: // ((InstanceCountingClassResolver) kryo.getClassResolver()).summarize(); }
if (input == null && output != null) { output.close(); output = null;
if (input == null && output != null) { output.close(); output = null;
if (input == null && output != null) { output.close(); output = null;
@Override public void encode(final Object object, OutputStream outputStream) throws IOException { Assert.notNull(object, "cannot encode a null object"); Assert.notNull(outputStream, "'outputSteam' cannot be null"); final Output output = (outputStream instanceof Output ? (Output) outputStream : new Output(outputStream)); this.pool.run(kryo -> { doEncode(kryo, object, output); return Void.class; }); output.close(); }
@Override public byte[] toBytes(Object object) { Output output = new Output(1024,-1); kryo.get().writeObject(output, object); output.close(); return output.toBytes(); }
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();