@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();
    }
  }
@Test
  public void testWrite_partialArray_invalidInput() throws IOException {
    JimfsOutputStream out = newOutputStream(false);

    try {
      out.write(new byte[3], -1, 1);
      fail();
    } catch (IndexOutOfBoundsException expected) {
    }

    try {
      out.write(new byte[3], 0, 4);
      fail();
    } catch (IndexOutOfBoundsException expected) {
    }

    try {
      out.write(new byte[3], 1, 3);
      fail();
    } catch (IndexOutOfBoundsException expected) {
    }
  }