@Override
  public void write(int b) throws IOException {
    if (finished) {
      throw new IOException("Stream has been finished. Can not write any more data.");
    }
    if (count == 0) {
      os.write(b);
      return;
    }

    if (buffer.hasRemaining()) {
      buffer.put((byte) b);
    } else {
      outputBuffer();
      os.write(b);
    }
  }
@Test
  public void testWritingByteWhenFinishedThrows() throws Exception {
    expectedException.expect(IOException.class);
    expectedException.expectMessage("Stream has been finished.");
    testValues(toBytes("a")).write(1);
  }