/** * @return the value wrapped by this {@code Optional} * @throws NullPointerException if this is empty (contains no value) */ public T get() { Preconditions.checkNotNull(value); return value; }
/** * 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(); }
/** * Create a LimitedInputStream that will read {@code limit} bytes from {@code in}. * <p> * If {@code closeWrappedStream} is true, this will close {@code in} when it is closed. * Otherwise, the stream is left open for reading its remaining content. * * @param in a {@link InputStream} to read from * @param limit the number of bytes to read * @param closeWrappedStream whether to close {@code in} when {@link #close} is called */ public LimitedInputStream(InputStream in, long limit, boolean closeWrappedStream) { super(in); this.closeWrappedStream = closeWrappedStream; Preconditions.checkNotNull(in); Preconditions.checkArgument(limit >= 0, "limit must be non-negative"); left = limit; } @Override public int available() throws IOException {
/** * Sets the authenticated client ID. This is meant to be used by the authentication layer. * * Trying to set a different client ID after it's been set will result in an exception. */ public void setClientId(String id) { Preconditions.checkState(clientId == null, "Client ID has already been set."); this.clientId = id; }
/** * Create a LimitedInputStream that will read {@code limit} bytes from {@code in}. * <p> * If {@code closeWrappedStream} is true, this will close {@code in} when it is closed. * Otherwise, the stream is left open for reading its remaining content. * * @param in a {@link InputStream} to read from * @param limit the number of bytes to read * @param closeWrappedStream whether to close {@code in} when {@link #close} is called */ public LimitedInputStream(InputStream in, long limit, boolean closeWrappedStream) { super(in); this.closeWrappedStream = closeWrappedStream; Preconditions.checkNotNull(in); Preconditions.checkArgument(limit >= 0, "limit must be non-negative"); left = limit; } @Override public int available() throws IOException {
private void checkParent(byte[] prefix) { if (prefix != null) { Preconditions.checkState(parent != null, "Parent prefix provided for parent index."); } else { Preconditions.checkState(parent == null, "Parent prefix missing for child index."); } }
/** * 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(); }
/** * @return the value wrapped by this {@code Optional} * @throws NullPointerException if this is empty (contains no value) */ public T get() { Preconditions.checkNotNull(value); return value; }
/** * Create a LimitedInputStream that will read {@code limit} bytes from {@code in}. * <p> * If {@code closeWrappedStream} is true, this will close {@code in} when it is closed. * Otherwise, the stream is left open for reading its remaining content. * * @param in a {@link InputStream} to read from * @param limit the number of bytes to read * @param closeWrappedStream whether to close {@code in} when {@link #close} is called */ public LimitedInputStream(InputStream in, long limit, boolean closeWrappedStream) { super(in); this.closeWrappedStream = closeWrappedStream; Preconditions.checkNotNull(in); Preconditions.checkArgument(limit >= 0, "limit must be non-negative"); left = limit; } @Override public int available() throws IOException {
/** * Sets the authenticated client ID. This is meant to be used by the authentication layer. * * Trying to set a different client ID after it's been set will result in an exception. */ public void setClientId(String id) { Preconditions.checkState(clientId == null, "Client ID has already been set."); this.clientId = id; }
/** 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]); } }
private Optional(T value) { Preconditions.checkNotNull(value); this.value = value; }
/** * Sets the authenticated client ID. This is meant to be used by the authentication layer. * * Trying to set a different client ID after it's been set will result in an exception. */ public void setClientId(String id) { Preconditions.checkState(clientId == null, "Client ID has already been set."); this.clientId = id; }
/** 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]); } }
private Optional(T value) { Preconditions.checkNotNull(value); this.value = value; }
private void checkParent(byte[] prefix) { if (prefix != null) { Preconditions.checkState(parent != null, "Parent prefix provided for parent index."); } else { Preconditions.checkState(parent == null, "Parent prefix missing for child index."); } }
/** 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]); } }
/** * @return the value wrapped by this {@code Optional} * @throws NullPointerException if this is empty (contains no value) */ public T get() { Preconditions.checkNotNull(value); return value; }
public void setInterceptor(Interceptor interceptor) { Preconditions.checkState(this.interceptor == null, "Already have an interceptor."); this.interceptor = interceptor; }
/** * 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; }