/**
  * 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();
    }
  }
 public void resetForReUse(byte[] out) {
   if (closed) throw new RuntimeException("Can't reuse closed stream");
   codec.reset();
   codec.reset(out);
   objects.clearForWrite();
 }
 void resetAndClearRefs() {
   codec.reset();
   objects.clearForWrite();
 }