public FSTObjectOutput getObjectOutput(OutputStream outputStream) { return conf.getObjectOutput(outputStream); }
public FSTObjectOutput getObjectOutput(OutputStream outputStream) { return conf.getObjectOutput(outputStream); }
/** * @return a recycled outputstream reusing its last recently used byte[] buffer */ public FSTObjectOutput getObjectOutput() { return getObjectOutput((OutputStream)null); }
/** * @return a recycled outputstream reusing its last recently used byte[] buffer */ public FSTObjectOutput getObjectOutput() { return getObjectOutput((OutputStream)null); }
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); FSTObjectOutput oos = config.getObjectOutput(os); oos.writeObject(in); oos.flush(); return os.buffer(); } catch (IOException e) { out.release(); throw e; } catch (Exception e) { out.release(); throw new IOException(e); } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); FSTObjectOutput oos = config.getObjectOutput(os); oos.writeObject(in); oos.flush(); return os.buffer(); } catch (IOException e) { out.release(); throw e; } catch (Exception e) { out.release(); throw new IOException(e); } } };
/** * helper to write series of objects to streams/files > Integer.MAX_VALUE. * it * - serializes the object * - writes the length of the serialized object to the stream * - the writes the serialized object data * * on reader side (e.g. from a blocking socketstream, the reader then * - reads the length * - reads [length] bytes from the stream * - deserializes * * @see decodeFromStream * * @param out * @param toSerialize * @throws IOException */ public void encodeToStream( OutputStream out, Object toSerialize ) throws IOException { FSTObjectOutput objectOutput = getObjectOutput(); // could also do new with minor perf impact objectOutput.writeObject(toSerialize); int written = objectOutput.getWritten(); out.write((written >>> 0) & 0xFF); out.write((written >>> 8) & 0xFF); out.write((written >>> 16) & 0xFF); out.write((written >>> 24) & 0xFF); // copy internal buffer to bufferedoutput out.write(objectOutput.getBuffer(), 0, written); objectOutput.flush(); }
/** * convenience. (object must be serializable) */ public byte[] asByteArray( Object object ) { FSTObjectOutput objectOutput = getObjectOutput(); try { objectOutput.writeObject(object); return objectOutput.getCopyOfWrittenBuffer(); } catch (IOException e) { try { // FSTConfiguration.prettyPrintJson(object); endless cycle ! } catch (Exception ee) { // } FSTUtil.<RuntimeException>rethrow(e); } return null; }
/** * helper to write series of objects to streams/files > Integer.MAX_VALUE. * it * - serializes the object * - writes the length of the serialized object to the stream * - the writes the serialized object data * * on reader side (e.g. from a blocking socketstream, the reader then * - reads the length * - reads [length] bytes from the stream * - deserializes * * @see decodeFromStream * * @param out * @param toSerialize * @throws IOException */ public void encodeToStream( OutputStream out, Object toSerialize ) throws IOException { FSTObjectOutput objectOutput = getObjectOutput(); // could also do new with minor perf impact objectOutput.writeObject(toSerialize); int written = objectOutput.getWritten(); out.write((written >>> 0) & 0xFF); out.write((written >>> 8) & 0xFF); out.write((written >>> 16) & 0xFF); out.write((written >>> 24) & 0xFF); // copy internal buffer to bufferedoutput out.write(objectOutput.getBuffer(), 0, written); objectOutput.flush(); }
/** * Warning: avoids allocation + copying. * The returned byteArray is a direct pointer to underlying buffer. * the int length[] is expected to have at least on element. * The buffer can be larger than written data, therefore length[0] will contain written length. * * The buffer content must be used (e.g. sent to network, copied to offheap) before doing another * asByteArray on the current Thread. */ public byte[] asSharedByteArray( Object object, int length[] ) { FSTObjectOutput objectOutput = getObjectOutput(); try { objectOutput.writeObject(object); length[0] = objectOutput.getWritten(); return objectOutput.getBuffer(); } catch (IOException e) { FSTUtil.<RuntimeException>rethrow(e); } return null; }
/** * convenience. (object must be serializable) */ public byte[] asByteArray( Object object ) { FSTObjectOutput objectOutput = getObjectOutput(); try { objectOutput.writeObject(object); return objectOutput.getCopyOfWrittenBuffer(); } catch (IOException e) { try { // FSTConfiguration.prettyPrintJson(object); endless cycle ! } catch (Exception ee) { // } FSTUtil.<RuntimeException>rethrow(e); } return null; }
out = conf.getObjectOutput(); in = conf.getObjectInput(); } else {
out = conf.getObjectOutput(); in = conf.getObjectInput(); } else {
/** * Warning: avoids allocation + copying. * The returned byteArray is a direct pointer to underlying buffer. * the int length[] is expected to have at least on element. * The buffer can be larger than written data, therefore length[0] will contain written length. * * The buffer content must be used (e.g. sent to network, copied to offheap) before doing another * asByteArray on the current Thread. */ public byte[] asSharedByteArray( Object object, int length[] ) { FSTObjectOutput objectOutput = getObjectOutput(); try { objectOutput.writeObject(object); length[0] = objectOutput.getWritten(); return objectOutput.getBuffer(); } catch (IOException e) { FSTUtil.<RuntimeException>rethrow(e); } return null; }
out = conf.getObjectOutput(); in = conf.getObjectInput(); } else {
out = conf.getObjectOutput(); in = conf.getObjectInput(); } else {
public FSTObjectOutput getObjectOutput(OutputStream outputStream) { return conf.getObjectOutput(outputStream); }
public FSTObjectOutput getObjectOutput(OutputStream outputStream) { return conf.getObjectOutput(outputStream); }
public FSTObjectOutput getObjectOutput(OutputStream outputStream) { return conf.getObjectOutput(outputStream); }
public static void writeObject(OutputStream output, Object obj) throws IOException { FSTObjectOutput out = getFST().getObjectOutput(output); out.writeObject(obj); out.flush(); }