private void checkFileInputStream(int size) throws IOException {
    byte[] bytesToWrite = new byte[size];
    for (int i = 0; i < size; i++) {
      bytesToWrite[i] = (byte) i; // It's okay to truncate
    }

    File tmpFile = File.createTempFile("streamUtil", "test");
    InputStream input = null;
    OutputStream output = null;
    try {
      output = new FileOutputStream(tmpFile);
      output.write(bytesToWrite);
      output.close();

      input = new FileInputStream(tmpFile);
      byte[] bytesRead = StreamUtil.getBytesFromStream(input);
      assertTrue(Arrays.equals(bytesToWrite, bytesRead));
    } finally {
      Closeables.close(input, true);
      Closeables.close(output, false);
      assertTrue(tmpFile.delete());
    }
  }
Verify getting a byte array from a FileInputStream.
fbcore/src/test/java/com/facebook/common/util/StreamUtilTest.java