@Override
  public void close() throws IOException {
    if (isClosed) {
      throw new EOFException();
    }
    flush();
    writeInt(nextSequenceNumber);
    outputStream.write(ZERO_HASH);
    writeInt(0);
    isClosed = true;
    outputStream.close();
  }
@Override
  public void close()