/** * Creates a <code>ReadAheadInputStream</code> with the specified buffer size and read-ahead * threshold * * @param inputStream The underlying input stream. * @param bufferSizeInBytes The buffer size. */ public ReadAheadInputStream( InputStream inputStream, int bufferSizeInBytes) { Preconditions.checkArgument(bufferSizeInBytes > 0, "bufferSizeInBytes should be greater than 0, but the value is " + bufferSizeInBytes); activeBuffer = ByteBuffer.allocate(bufferSizeInBytes); readAheadBuffer = ByteBuffer.allocate(bufferSizeInBytes); this.underlyingInputStream = inputStream; activeBuffer.flip(); readAheadBuffer.flip(); }
/** * Creates a <code>ReadAheadInputStream</code> with the specified buffer size and read-ahead * threshold * * @param inputStream The underlying input stream. * @param bufferSizeInBytes The buffer size. */ public ReadAheadInputStream( InputStream inputStream, int bufferSizeInBytes) { Preconditions.checkArgument(bufferSizeInBytes > 0, "bufferSizeInBytes should be greater than 0, but the value is " + bufferSizeInBytes); activeBuffer = ByteBuffer.allocate(bufferSizeInBytes); readAheadBuffer = ByteBuffer.allocate(bufferSizeInBytes); this.underlyingInputStream = inputStream; activeBuffer.flip(); readAheadBuffer.flip(); }
/** Checks that the "test" array is in the data array starting at the given offset. */ private void checkSubArray(byte[] test, byte[] data, int offset) { Preconditions.checkArgument(data.length >= test.length + offset); for (int i = 0; i < test.length; i++) { Preconditions.checkArgument(test[i] == data[i + offset]); } }
/** Checks that the "test" array is in the data array starting at the given offset. */ private void checkSubArray(byte[] test, byte[] data, int offset) { Preconditions.checkArgument(data.length >= test.length + offset); for (int i = 0; i < test.length; i++) { Preconditions.checkArgument(test[i] == data[i + offset]); } }
/** Checks that the "test" array is in the data array starting at the given offset. */ private void checkSubArray(byte[] test, byte[] data, int offset) { Preconditions.checkArgument(data.length >= test.length + offset); for (int i = 0; i < test.length; i++) { Preconditions.checkArgument(test[i] == data[i + offset]); } }
/** * Stops iteration after a number of elements has been retrieved. */ public KVStoreView<T> max(long max) { Preconditions.checkArgument(max > 0L, "max must be positive."); this.max = max; return this; }
Accessor getAccessor(String indexName) { Accessor a = accessors.get(indexName); Preconditions.checkArgument(a != null, "No index %s.", indexName); return a; }
Accessor getAccessor(String indexName) { Accessor a = accessors.get(indexName); Preconditions.checkArgument(a != null, "No index %s.", indexName); return a; }
EncryptedMessage(SaslEncryptionBackend backend, Object msg, int maxOutboundBlockSize) { Preconditions.checkArgument(msg instanceof ByteBuf || msg instanceof FileRegion, "Unrecognized message type: %s", msg.getClass().getName()); this.backend = backend; this.isByteBuf = msg instanceof ByteBuf; this.buf = isByteBuf ? (ByteBuf) msg : null; this.region = isByteBuf ? null : (FileRegion) msg; this.maxOutboundBlockSize = maxOutboundBlockSize; }
Index index(String name) { Index i = indices.get(name); Preconditions.checkArgument(i != null, "Index %s does not exist for type %s.", name, type.getName()); return i; }
EncryptedMessage(SaslEncryptionBackend backend, Object msg, int maxOutboundBlockSize) { Preconditions.checkArgument(msg instanceof ByteBuf || msg instanceof FileRegion, "Unrecognized message type: %s", msg.getClass().getName()); this.backend = backend; this.isByteBuf = msg instanceof ByteBuf; this.buf = isByteBuf ? (ByteBuf) msg : null; this.region = isByteBuf ? null : (FileRegion) msg; this.maxOutboundBlockSize = maxOutboundBlockSize; }
EncryptedMessage(SaslEncryptionBackend backend, Object msg, int maxOutboundBlockSize) { Preconditions.checkArgument(msg instanceof ByteBuf || msg instanceof FileRegion, "Unrecognized message type: %s", msg.getClass().getName()); this.backend = backend; this.isByteBuf = msg instanceof ByteBuf; this.buf = isByteBuf ? (ByteBuf) msg : null; this.region = isByteBuf ? null : (FileRegion) msg; this.byteChannel = new ByteArrayWritableChannel(maxOutboundBlockSize); }
EncryptedMessage(CryptoOutputStream cos, Object msg, ByteArrayWritableChannel ch) { Preconditions.checkArgument(msg instanceof ByteBuf || msg instanceof FileRegion, "Unrecognized message type: %s", msg.getClass().getName()); this.isByteBuf = msg instanceof ByteBuf; this.buf = isByteBuf ? (ByteBuf) msg : null; this.region = isByteBuf ? null : (FileRegion) msg; this.transferred = 0; this.byteRawChannel = new ByteArrayWritableChannel(STREAM_BUFFER_SIZE); this.cos = cos; this.byteEncChannel = ch; }
EncryptedMessage(CryptoOutputStream cos, Object msg, ByteArrayWritableChannel ch) { Preconditions.checkArgument(msg instanceof ByteBuf || msg instanceof FileRegion, "Unrecognized message type: %s", msg.getClass().getName()); this.isByteBuf = msg instanceof ByteBuf; this.buf = isByteBuf ? (ByteBuf) msg : null; this.region = isByteBuf ? null : (FileRegion) msg; this.transferred = 0; this.byteRawChannel = new ByteArrayWritableChannel(STREAM_BUFFER_SIZE); this.cos = cos; this.byteEncChannel = ch; }
EncryptedMessage(CryptoOutputStream cos, Object msg, ByteArrayWritableChannel ch) { Preconditions.checkArgument(msg instanceof ByteBuf || msg instanceof FileRegion, "Unrecognized message type: %s", msg.getClass().getName()); this.isByteBuf = msg instanceof ByteBuf; this.buf = isByteBuf ? (ByteBuf) msg : null; this.region = isByteBuf ? null : (FileRegion) msg; this.transferred = 0; this.byteRawChannel = new ByteArrayWritableChannel(STREAM_BUFFER_SIZE); this.cos = cos; this.byteEncChannel = ch; }
public void put(Object value) throws Exception { Preconditions.checkArgument(ti.type().equals(value.getClass()), "Unexpected type: %s", value.getClass()); if (data.put(asKey(naturalKey.get(value)), value) == null) { size++; } }
public void put(Object value) throws Exception { Preconditions.checkArgument(ti.type().equals(value.getClass()), "Unexpected type: %s", value.getClass()); if (data.put(asKey(naturalKey.get(value)), value) == null) { size++; } }
@SuppressWarnings("unchecked") public <T> InMemoryView<T> view(Class<T> type) { Preconditions.checkArgument(ti.type().equals(type), "Unexpected type: %s", type); Collection<T> all = (Collection<T>) data.values(); return new InMemoryView<>(type, all, ti); }
private void checkIndex(KVIndex idx, Map<String, KVIndex> indices) { Preconditions.checkArgument(idx.value() != null && !idx.value().isEmpty(), "No name provided for index in type %s.", type.getName()); Preconditions.checkArgument( !idx.value().startsWith("_") || idx.value().equals(KVIndex.NATURAL_INDEX_NAME), "Index name %s (in type %s) is not allowed.", idx.value(), type.getName()); Preconditions.checkArgument(idx.parent().isEmpty() || !idx.parent().equals(idx.value()), "Index %s cannot be parent of itself.", idx.value()); Preconditions.checkArgument(!indices.containsKey(idx.value()), "Duplicate index %s for type %s.", idx.value(), type.getName()); }
private void put(byte[] key, Object value) throws Exception { Preconditions.checkArgument(value != null, "Null values are not allowed."); db().put(key, serializer.serialize(value)); }