Java Code Examples for net.jpountz.util.SafeUtils#checkRange()
The following examples show how to use
net.jpountz.util.SafeUtils#checkRange() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LZ4BlockInputStream.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public int read(byte[] b, int off, int len) throws IOException { SafeUtils.checkRange(b, off, len); if (finished) { return -1; } if (o == originalLen) { refill(); } if (finished) { return -1; } len = Math.min(len, originalLen - o); System.arraycopy(buffer, o, b, off, len); o += len; return len; }
Example 2
Source File: LZ4BlockOutputStream.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public void write(byte[] b, int off, int len) throws IOException { SafeUtils.checkRange(b, off, len); ensureNotFinished(); while (o + len > blockSize) { final int l = blockSize - o; System.arraycopy(b, off, buffer, o, blockSize - o); o = blockSize; flushBufferedData(); off += l; len -= l; } System.arraycopy(b, off, buffer, o, len); o += len; }
Example 3
Source File: CloverDataStream.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
@Override public int read(byte[] b, int off, int len) throws IOException { SafeUtils.checkRange(b, off, len); int count = 0; while (buffer.remaining() < len) { final int l = buffer.remaining(); buffer.get(b, off, l); count += l; off += l; len -= l; if (!readDataBlock()) return -1; //end of stream; } buffer.get(b, off, len); count += len; return count; }
Example 4
Source File: LZ4JNISafeDecompressor.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public final int decompress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) { SafeUtils.checkRange(src, srcOff, srcLen); SafeUtils.checkRange(dest, destOff, maxDestLen); final int result = LZ4JNI.LZ4_decompress_safe(src, null, srcOff, srcLen, dest, null, destOff, maxDestLen); if (result < 0) { throw new LZ4Exception("Error decoding offset " + (srcOff - result) + " of input buffer"); } return result; }
Example 5
Source File: LZ4JNIFastDecompressor.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public final int decompress(byte[] src, int srcOff, byte[] dest, int destOff, int destLen) { SafeUtils.checkRange(src, srcOff); SafeUtils.checkRange(dest, destOff, destLen); final int result = LZ4JNI.LZ4_decompress_fast(src, null, srcOff, dest, null, destOff, destLen); if (result < 0) { throw new LZ4Exception("Error decoding offset " + (srcOff - result) + " of input buffer"); } return result; }
Example 6
Source File: LZ4HCJNICompressor.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public int compress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) { SafeUtils.checkRange(src, srcOff, srcLen); SafeUtils.checkRange(dest, destOff, maxDestLen); final int result = LZ4JNI.LZ4_compressHC(src, null, srcOff, srcLen, dest, null, destOff, maxDestLen, compressionLevel); if (result <= 0) { throw new LZ4Exception(); } return result; }