List of utility methods to do File Read via ByteBuffer
String | readZipComment(File file) read Zip Comment RandomAccessFile raf = null; try { raf = new RandomAccessFile(file, "r"); long index = raf.length(); byte[] buffer = new byte[COMMENT_SIGN.length]; index -= COMMENT_SIGN.length; raf.seek(index); raf.readFully(buffer); ... |
long | skip(final ReadableByteChannel input, final long toSkip) Skips bytes from a ReadableByteChannel. final int SKIP_BUFFER_SIZE = 2048; if (toSkip < 0) { throw new IllegalArgumentException("Skip count must be non-negative, actual: " + toSkip); final ByteBuffer skipByteBuffer = ByteBuffer.allocate((int) Math.min(toSkip, SKIP_BUFFER_SIZE)); long remain = toSkip; while (remain > 0) { skipByteBuffer.position(0); ... |
byte[] | streamRead(SocketChannel in) stream Read ByteBuffer buf = ByteBuffer.allocate(4096); int len = in.read(buf); if (len == -1) return null; byte ret[] = new byte[len]; buf.get(ret); return (ret); |