@Override
  public int read(byte[] buffer, int offset, int count) throws IOException {
    final int readResult = in.read(buffer, offset, count);
    if (readResult != -1) {
      return readResult;
    }

    if (count == 0) {
      return 0;
    }

    int bytesRead = 0;
    while (bytesRead < count) {
      final int nextByte = readNextTailByte();
      if (nextByte == -1) {
        break;
      }
      buffer[offset + bytesRead] = (byte) nextByte;
      bytesRead++;
    }
    return bytesRead > 0 ? bytesRead : -1;
  }
InputStream that returns all bytes from another stream, then appends the specified 'tail' bytes.
fbcore/src/main/java/com/facebook/common/streams/TailAppendingInputStream.java