code: public static long skipByReading(InputStream in, long byteCount) throws IOException {
          // acquire the shared skip buffer.
          byte[] buffer = skipBuffer.getAndSet(null);
          if (buffer == null) {
              buffer = new byte[4096];
          }
  
          long skipped = 0;
          while (skipped < byteCount) {
              int toRead = (int) Math.min(byteCount - skipped, buffer.length);
              int read = in.read(buffer, 0, toRead);
              if (read == -1) {
                  break;
              }
              skipped += read;
              if (read < toRead) {
                  break;
              }
          }
  
          // release the shared skip buffer.
          skipBuffer.set(buffer);
  
          return skipped;
      }
docs: Skip <b>at most</b> {@code byteCount} bytes from {@code in} by calling read
  repeatedly until either the stream is exhausted or we read fewer bytes than
  we ask for.
  
  <p>This method reuses the skip buffer but is careful to never use it at
  the same time that another stream is using it. Otherwise streams that use
  the caller's buffer for consistency checks like CRC could be clobbered by
  other threads. A thread-local buffer is also insufficient because some
  streams may call other streams in their skip() method, also clobbering the
  buffer.