private void sanityCheckConfigs() { Preconditions.checkArgument(acceptableFactor <= 1 && acceptableFactor >= 0, ACCEPT_FACTOR_CONFIG_NAME + " must be between 0.0 and 1.0"); Preconditions.checkArgument(minFactor <= 1 && minFactor >= 0, MIN_FACTOR_CONFIG_NAME + " must be between 0.0 and 1.0"); Preconditions.checkArgument(minFactor <= acceptableFactor, MIN_FACTOR_CONFIG_NAME + " must be <= " + ACCEPT_FACTOR_CONFIG_NAME); Preconditions.checkArgument(extraFreeFactor >= 0, EXTRA_FREE_FACTOR_CONFIG_NAME + " must be greater than 0.0"); Preconditions.checkArgument(singleFactor <= 1 && singleFactor >= 0, SINGLE_FACTOR_CONFIG_NAME + " must be between 0.0 and 1.0"); Preconditions.checkArgument(multiFactor <= 1 && multiFactor >= 0, MULTI_FACTOR_CONFIG_NAME + " must be between 0.0 and 1.0"); Preconditions.checkArgument(memoryFactor <= 1 && memoryFactor >= 0, MEMORY_FACTOR_CONFIG_NAME + " must be between 0.0 and 1.0"); Preconditions.checkArgument((singleFactor + multiFactor + memoryFactor) == 1, SINGLE_FACTOR_CONFIG_NAME + ", " + MULTI_FACTOR_CONFIG_NAME + ", and " + MEMORY_FACTOR_CONFIG_NAME + " segments must add up to 1.0"); }
public ColumnValueFilter(final byte[] family, final byte[] qualifier, final CompareOperator op, final ByteArrayComparable comparator) { this.family = Preconditions.checkNotNull(family, "family should not be null."); this.qualifier = qualifier == null ? new byte[0] : qualifier; this.op = Preconditions.checkNotNull(op, "CompareOperator should not be null"); this.comparator = Preconditions.checkNotNull(comparator, "Comparator should not be null"); }
/** * Upon construction, this method will be called with the region * to be governed. It will be called once and only once. */ protected void configureForRegion(HRegion region) { Preconditions.checkState( this.region == null, "Policy already configured for region {}", this.region); this.region = region; }
@Override public void setIv(byte[] iv) { Preconditions.checkNotNull(iv, "IV cannot be null"); Preconditions.checkArgument(iv.length == AES.IV_LENGTH, "Invalid IV length"); this.iv = iv; }
/** * Fill given array with zeros at the specified position. * @param b * @param offset * @param length */ public static void zero(byte[] b, int offset, int length) { checkPositionIndex(offset, b.length, "offset"); checkArgument(length > 0, "length must be greater than 0"); checkPositionIndex(offset + length, b.length, "offset + length"); Arrays.fill(b, offset, offset + length, (byte) 0); }
@Override public byte[][] split(int n) { Preconditions.checkArgument(lastRowInt.compareTo(firstRowInt) > 0, "last row (%s) is configured less than first row (%s)", lastRow, firstRow); // +1 to range because the last row is inclusive BigInteger range = lastRowInt.subtract(firstRowInt).add(BigInteger.ONE); Preconditions.checkState(range.compareTo(BigInteger.valueOf(n)) >= 0, "split granularity (%s) is greater than the range (%s)", n, range); BigInteger[] splits = new BigInteger[n - 1]; BigInteger sizeOfEachSplit = range.divide(BigInteger.valueOf(n)); for (int i = 1; i < n; i++) { // NOTE: this means the last region gets all the slop. // This is not a big deal if we're assuming n << MAXHEX splits[i - 1] = firstRowInt.add(sizeOfEachSplit.multiply(BigInteger .valueOf(i))); } return convertToBytes(splits); }
@Override public OutputStream createEncryptionStream(OutputStream out, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Encryptor e = getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); return e.createEncryptionStream(out); }
void reconfigure(int sizeIndex, int[] bucketSizes, long bucketCapacity) { Preconditions.checkElementIndex(sizeIndex, bucketSizes.length); this.sizeIndex = sizeIndex; itemAllocationSize = bucketSizes[sizeIndex]; itemCount = (int) (bucketCapacity / (long) itemAllocationSize); freeCount = itemCount; usedCount = 0; freeList = new int[itemCount]; for (int i = 0; i < freeCount; ++i) freeList[i] = i; }
@Override public void setIv(byte[] iv) { Preconditions.checkNotNull(iv, "IV cannot be null"); Preconditions.checkArgument(iv.length == CommonsCryptoAES.IV_LENGTH, "Invalid IV length"); this.iv = iv; }
@Override public byte[][] split(int numRegions) { Preconditions.checkArgument( Bytes.compareTo(lastRowBytes, firstRowBytes) > 0, "last row (%s) is configured less than first row (%s)", Bytes.toStringBinary(lastRowBytes), Bytes.toStringBinary(firstRowBytes)); byte[][] splits = Bytes.split(firstRowBytes, lastRowBytes, true, numRegions - 1); Preconditions.checkState(splits != null, "Could not split region with given user input: " + this); // remove endpoints, which are included in the splits list return splits == null? null: Arrays.copyOfRange(splits, 1, splits.length - 1); }
@Override public OutputStream createEncryptionStream(OutputStream out, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Encryptor e = getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); return e.createEncryptionStream(out); }
/** * Fill given array with random bytes at the specified position. * @param b * @param offset * @param length */ public static void random(byte[] b, int offset, int length) { checkPositionIndex(offset, b.length, "offset"); checkArgument(length > 0, "length must be greater than 0"); checkPositionIndex(offset + length, b.length, "offset + length"); byte[] buf = new byte[length]; RNG.nextBytes(buf); System.arraycopy(buf, 0, b, offset, length); }
private byte[] get(short idx) { Preconditions.checkElementIndex(idx, currSize); moveToHead(indexToNode[idx]); return indexToNode[idx].getContents(); }
@Override public AsyncBufferedMutatorBuilder setWriteBufferSize(long writeBufferSize) { Preconditions.checkArgument(writeBufferSize > 0, "writeBufferSize %d must be >= 0", writeBufferSize); this.writeBufferSize = writeBufferSize; return this; }
@Override public void setKey(Key key) { Preconditions.checkNotNull(key, "Key cannot be null"); this.key = key; }
@Override public void setIv(byte[] iv) { Preconditions.checkNotNull(iv, "IV cannot be null"); Preconditions.checkArgument(iv.length == CommonsCryptoAES.IV_LENGTH, "Invalid IV length"); this.iv = iv; }
@Override public byte[][] split(byte[] start, byte[] end, int numSplits, boolean inclusive) { if (Arrays.equals(start, HConstants.EMPTY_BYTE_ARRAY)) { start = firstRowBytes; } if (Arrays.equals(end, HConstants.EMPTY_BYTE_ARRAY)) { end = lastRowBytes; } Preconditions.checkArgument( Bytes.compareTo(end, start) > 0, "last row (%s) is configured less than first row (%s)", Bytes.toStringBinary(end), Bytes.toStringBinary(start)); byte[][] splits = Bytes.split(start, end, true, numSplits - 1); Preconditions.checkState(splits != null, "Could not calculate input splits with given user input: " + this); if (inclusive) { return splits; } else { // remove endpoints, which are included in the splits list return Arrays.copyOfRange(splits, 1, splits.length - 1); } }
@Override public InputStream createDecryptionStream(InputStream in, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Decryptor d = getDecryptor(); d.setKey(context.getKey()); d.setIv(iv); return d.createDecryptionStream(in); }
private void preCheck() { Preconditions.checkState(Thread.currentThread() == callerThread, "The current thread is %s, expected thread is %s, " + "you should not call this method outside onNext or onHeartbeat", Thread.currentThread(), callerThread); Preconditions.checkState(state.equals(ScanControllerState.INITIALIZED), "Invalid Stopper state %s", state); }
static short toShort(byte hi, byte lo) { short s = (short) (((hi & 0xFF) << 8) | (lo & 0xFF)); Preconditions.checkArgument(s >= 0); return s; } }