class ExposedByteArrayOutputStream extends ByteArrayOutputStream {

  @Override
  public synchronized byte[] toByteArray() {
    // Note: count == buf.length is not a correct criteria to "return buf;", because the internal
    // buf may be reused after reset().
    if (!isFallback && count > 0) {
      return buf;
    } else {
      return super.toByteArray();
    }
  }

}