public int read(ByteBuffer buffer, long offset, int size) throws IOException {
    Validate.checkNotNull(buffer, "buffer");
    Validate.checkWithinRange(offset, "offset", 0, this.remoteObject.size());
    Validate.checkPositiveInteger(size, "size");

    if (this.closed) {
      return -1;
    }

    int reqSize = (int) Math.min(size, this.remoteObject.size() - offset);
    return readOneBlockWithRetries(buffer, offset, reqSize);
  }
@Test
  public void testArgChecks() throws Exception {
    // Should not throw.
    S3ARemoteObjectReader reader = new S3ARemoteObjectReader(remoteObject);

    // Verify it throws correctly.

    intercept(
        IllegalArgumentException.class,
        "'remoteObject' must not be null",
        () -> new S3ARemoteObjectReader(null));

    intercept(
        IllegalArgumentException.class,
        "'buffer' must not be null",
        () -> reader.read(null, 10, 2));

    ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);

    intercept(
        IllegalArgumentException.class,
        "'offset' (-1) must be within the range [0, 9]",
        () -> reader.read(buffer, -1, 2));

    intercept(
        IllegalArgumentException.class,
        "'offset' (11) must be within the range [0, 9]",
        () -> reader.read(buffer, 11, 2));

    intercept(
        IllegalArgumentException.class,
        "'size' must be a positive integer",
        () -> reader.read(buffer, 1, 0));

    intercept(
        IllegalArgumentException.class,
        "'size' must be a positive integer",
        () -> reader.read(buffer, 1, -1));
  }