class JimfsOutputStream extends OutputStream {

  @GuardedBy("this")
  @VisibleForTesting
  RegularFile file;

  @GuardedBy("this")
  private long pos;

  private final boolean append;
  private final FileSystemState fileSystemState;

  JimfsOutputStream(RegularFile file, boolean append, FileSystemState fileSystemState) {
    this.file = checkNotNull(file);
    this.append = append;
    this.fileSystemState = fileSystemState;
    fileSystemState.register(this);
  }

  @Override
  public synchronized void write(int b) throws IOException {
    checkNotClosed();

    file.writeLock().lock();
    try {
      if (append) {
        pos = file.sizeWithoutLocking();
      }
      file.write(pos++, (byte) b);

      file.setLastModifiedTime(fileSystemState.now());
    } finally {
      file.writeLock().unlock();
    }
  }

  @Override
  public void write(byte[] b) throws IOException {
    writeInternal(b, 0, b.length);
  }

  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    checkPositionIndexes(off, off + len, b.length);
    writeInternal(b, off, len);
  }

  private synchronized void writeInternal(byte[] b, int off, int len) throws IOException {<FILL_FUNCTION_BODY>}

  @GuardedBy("this")
  private void checkNotClosed() throws IOException {
    if (file == null) {
      throw new IOException("stream is closed");
    }
  }

  @Override
  public synchronized void close() throws IOException {
    if (isOpen()) {
      fileSystemState.unregister(this);
      file.closed();

      // file is set to null here and only here
      file = null;
    }
  }

  @GuardedBy("this")
  private boolean isOpen() {
    return file != null;
  }
}

    checkNotClosed();

    file.writeLock().lock();
    try {
      if (append) {
        pos = file.sizeWithoutLocking();
      }
      pos += file.write(pos, b, off, len);

      file.setLastModifiedTime(fileSystemState.now());
    } finally {
      file.writeLock().unlock();
    }
  
<methods>public void <init>() ,public void close() throws java.io.IOException,public void flush() throws java.io.IOException,public static java.io.OutputStream nullOutputStream() ,public abstract void write(int) throws java.io.IOException,public void write(byte[]) throws java.io.IOException,public void write(byte[], int, int) throws java.io.IOException<variables>