/** Constructs an NIOInputStream around the given file. */ public NIOInputStream(String filename) throws IOException { this.filename = filename; file = new File(filename); raf = new FileHandle(file, "r"); }
@Override public int read(ByteBuffer buffer, int off, int len) throws IOException { byte[] b = new byte[len]; int n = read(b); buffer.put(b, off, len); return n; }
@Override public void write(ByteBuffer buf) throws IOException { write(buf, 0, buf.capacity()); }
@Override public long skipBytes(long n) throws IOException { if (n < 1) { return 0; } final long currentPosition = getFilePointer(); n = Math.min(n, length() - currentPosition); if (n <= Integer.MAX_VALUE) { /* use standard library if possible */ return skipBytes((int) n); } seek(currentPosition + n); return n; }
if (ira instanceof FileHandle) { FileHandle fh = (FileHandle) ira; r.setVar("file", fh.getRandomAccessFile());
@Override public boolean exists() throws IOException { return length() >= 0; }
if (ira instanceof FileHandle) { FileHandle fh = (FileHandle) ira; r.setVar("file", fh.getRandomAccessFile());
@Override public int read(ByteBuffer buffer, int off, int len) throws IOException { byte[] b = new byte[len]; int n = read(b); buffer.put(b, off, len); return n; }
@Override public void write(ByteBuffer buf) throws IOException { write(buf, 0, buf.capacity()); }
/** * Constructs an NIOInputStream around the given file. * * @param filename the path to a readable file on disk * @throws IOException if the path is invalid or unreadable */ public NIOInputStream(String filename) throws IOException { this.filename = filename; file = new File(filename); raf = new FileHandle(file, "r"); }
@Override public int read(ByteBuffer buffer) throws IOException { return read(buffer, 0, buffer.capacity()); }
@Override public int read(ByteBuffer buffer) throws IOException { return read(buffer, 0, buffer.capacity()); }