ByteBufferInputStream extends InputStream { @Override public long skip(long n) { int bytes; if (n > Integer.MAX_VALUE) { bytes = buffer.remaining(); } else { bytes = Math.min(buffer.remaining(), (int) n); } buffer.position(buffer.position() + bytes); return bytes; } ByteBufferInputStream(ByteBuffer buffer); @Override int available(); @Override synchronized void mark(int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(byte[] b, int off, int len); @Override synchronized void reset(); @Override long skip(long n);  }
@Test public void testSkip() throws IOException { byte[] src = "HELLO MINA!".getBytes(); ByteBuffer bb = ByteBuffer.wrap(src); InputStream is = new ByteBufferInputStream(bb); is.skip(6); assertEquals(5, is.available()); assertEquals('M', is.read()); assertEquals('I', is.read()); assertEquals('N', is.read()); assertEquals('A', is.read()); is.skip((long) Integer.MAX_VALUE + 1); assertEquals(-1, is.read()); is.close(); }