public static long skip(final InputStream inputStream, final long bytesCount) throws IOException {
    Preconditions.checkNotNull(inputStream);
    Preconditions.checkArgument(bytesCount >= 0);

    long toSkip = bytesCount;
    while (toSkip > 0) {
      final long skipped = inputStream.skip(toSkip);
      if (skipped > 0) {
        toSkip -= skipped;
        continue;
      }

      if (inputStream.read() != -1) {
        toSkip--;
        continue;
      }
      return bytesCount - toSkip;
    }

    return bytesCount;
  }
Skips exactly bytesCount bytes in inputStream unless end of stream is reached first.

@param inputStream input stream to skip bytes from
@param bytesCount number of bytes to skip
@return number of skipped bytes
@throws IOException
fbcore/src/main/java/com/facebook/common/util/StreamUtil.java