int read(long channelPosition, byte[] dst, int pos, int cnt) throws IOException { long block = channelPosition / blockSize; byte[] bytes = readFromChannel(block); if (bytes == null) { return -1; } int offs = (int) (channelPosition - block * blockSize); int bytesToCopy = Math.min(cnt, bytes.length - offs); if (bytesToCopy < 1) { return -1; } System.arraycopy(bytes, offs, dst, pos, bytesToCopy); return bytesToCopy; }
int read(long channelPosition, byte[] dst, int pos, int cnt) throws IOException { long block = channelPosition / blockSize; byte[] bytes = readFromChannel(block); if (bytes == null) { return -1; } int offs = (int) (channelPosition - block * blockSize); int bytesToCopy = Math.min(cnt, bytes.length - offs); if (bytesToCopy < 1) { return -1; } System.arraycopy(bytes, offs, dst, pos, bytesToCopy); return bytesToCopy; }