/** * if out == null => automatically create/reuse a bytebuffer * * @param out */ public void resetForReUse(OutputStream out) { if (closed) throw new RuntimeException("Can't reuse closed stream"); codec.reset(); if (out != null) { codec.setOutstream(out); } objects.clearForWrite(); }
/** * Creates a new FSTObjectOutput stream to write data to the specified underlying output stream. * The counter <code>written</code> is set to zero. Don't create a FSTConfiguration with each * stream, just create one global static configuration and reuse it. FSTConfiguration is * threadsafe. * * @param out the underlying output stream, to be saved for later use. */ public FSTObjectOutput(OutputStream out, FSTConfiguration conf) { this.conf = conf; codec = conf.createStreamEncoder(); codec.setOutstream(out); objects = (FSTObjectRegistry) conf.getCachedObject(FSTObjectRegistry.class); if (objects == null) { objects = new FSTObjectRegistry(conf); objects.disabled = !conf.isShareReferences(); } else { objects.clearForWrite(); } }
/** * serialize without an underlying stream, the resulting byte array of writing to this * FSTObjectOutput can be accessed using getBuffer(), the size using getWritten(). * * <p>Don't create a FSTConfiguration with each stream, just create one global static * configuration and reuse it. FSTConfiguration is threadsafe. * * @param conf * @throws IOException */ public FSTObjectOutput(FSTConfiguration conf) { this(null, conf); codec.setOutstream(null); }
/** * serialize without an underlying stream, the resulting byte array of writing to this * FSTObjectOutput can be accessed using getBuffer(), the size using getWritten(). Note once you * call close or flush, the tmp byte array is lost. (grab array before flushing/closing) * * <p>uses default configuration singleton * * @throws IOException */ public FSTObjectOutput() { this(null, FSTConfiguration.getDefaultConfiguration()); codec.setOutstream(null); }