28package com.jogamp.common.nio;
30import java.io.BufferedInputStream;
31import java.io.IOException;
32import java.io.InputStream;
33import java.nio.ByteBuffer;
34import java.nio.MappedByteBuffer;
35import java.nio.channels.FileChannel;
36import java.nio.channels.FileChannel.MapMode;
51 private final ByteBuffer buf;
66 return buf.remaining();
88 public final synchronized void mark(
final int unused) {
89 mark = buf.position();
100 public final synchronized void reset() throws IOException {
102 throw new IOException();
108 public final long skip(
final long n)
throws IOException {
112 final int s = (int) Math.min( buf.remaining(), n );
113 buf.position(buf.position() + s);
119 if ( ! buf.hasRemaining() ) {
122 return buf.get() & 0xFF;
126 public final int read(
final byte[] b,
final int off,
final int len) {
128 throw new NullPointerException();
129 }
else if( off < 0 ||
132 off + len > b.length ||
135 throw new IndexOutOfBoundsException(
"offset "+off+
", length "+len+
", b.length "+b.length);
136 }
else if ( 0 == len ) {
139 final int totalRem = buf.remaining();
140 if ( 0 == totalRem ) {
143 final int maxLen = Math.min(totalRem, len);
144 if( buf.hasArray() ) {
145 System.arraycopy(buf.array(), buf.arrayOffset() + buf.position(), b, off, maxLen);
146 buf.position( buf.position() + maxLen );
148 buf.get(b, off, maxLen);
154 public final int read(
final ByteBuffer b,
final int len) {
156 throw new NullPointerException();
157 }
else if (len < 0 || len > b.remaining()) {
158 throw new IndexOutOfBoundsException(
"length "+len+
", b "+b);
159 }
else if ( 0 == len ) {
162 final int remaining = buf.remaining();
163 if ( 0 == remaining ) {
166 final int maxLen = Math.min(remaining, len);
167 if( buf.hasArray() && b.hasArray() ) {
168 System.arraycopy(buf.array(), buf.arrayOffset() + buf.position(), b.array(), b.arrayOffset() + b.position(), maxLen);
169 buf.position( buf.position() + maxLen );
170 b.position( b.position() + maxLen );
171 }
else if( maxLen == remaining ) {
174 final int _limit = buf.limit();