@Override
  public void write(int datum)
  {
    if (this._bufferList.peekLast() == null || this._bufferList.getLast().length == this._index)
    {
      // If there's no buffer or its capacity is full, add a new one to the list.
      addBuffer(1);
    }
    this._bufferList.getLast()[this._index++] = (byte) datum;
  }
@Test
  public void testWrite() throws Exception
  {
    FastByteArrayOutputStream testStream1 = new FastByteArrayOutputStream();
    testStream1.write(1);
    Assert.assertEquals(testStream1.size(), 1);
    Assert.assertEquals(testStream1.toByteArray().length, 1);
    Assert.assertEquals(testStream1.toByteArray()[0], 0b1);

    FastByteArrayOutputStream testStream2 = new FastByteArrayOutputStream();
    byte[] inputArray = new byte[] {0b1, 0b1, 0b1, 0b1, 0b0, 0b0, 0b0, 0b0};
    testStream2.write(inputArray, 0, inputArray.length);
    Assert.assertEquals(testStream2.size(), inputArray.length);
    Assert.assertEquals(testStream2.toByteArray(), inputArray);

    FastByteArrayOutputStream testStream3 = new FastByteArrayOutputStream();
    Field maxSizeField = FastByteArrayOutputStream.class.getDeclaredField("MAX_STREAM_SIZE");
    maxSizeField.setAccessible(true);
    int maxSize = (int) maxSizeField.get(null);
    byte[] maxArray = new byte[0];  // Don't allocate a real array with maxSize to avoid OOM in test environment.
    Assert.assertThrows(IndexOutOfBoundsException.class, () -> testStream3.write(maxArray, 0, maxSize + 1));
  }