GoogleCloudStorageGrpcReadChannel implements SeekableByteChannel { @Override public long size() throws IOException { if (!isOpen()) { throw new ClosedChannelException(); } return objectSize; } private  GoogleCloudStorageGrpcReadChannel(
      StorageBlockingStub gcsGrpcBlockingStub,
      String bucketName,
      String objectName,
      long objectGeneration,
      long objectSize,
      GoogleCloudStorageReadOptions readOptions); static GoogleCloudStorageGrpcReadChannel open(
      StorageBlockingStub stub,
      String bucketName,
      String objectName,
      GoogleCloudStorageReadOptions readOptions); @Override int read(ByteBuffer byteBuffer); @Override int write(ByteBuffer byteBuffer); @Override long position(); @Override SeekableByteChannel position(long newPosition); @Override long size(); @Override SeekableByteChannel truncate(long l); @Override boolean isOpen(); @Override void close(); @Override String toString();  }
@Test public void sizeReturnsObjectSize() throws Exception { fakeService.setObject(DEFAULT_OBJECT.toBuilder().setSize(1234).build()); GoogleCloudStorageGrpcReadChannel readChannel = newReadChannel(); assertEquals(1234L, readChannel.size()); verify(fakeService, times(1)).getObject(eq(GET_OBJECT_REQUEST), any()); }
@Test public void sizeIsCached() throws Exception { fakeService.setObject(DEFAULT_OBJECT.toBuilder().setSize(1234).build()); GoogleCloudStorageGrpcReadChannel readChannel = newReadChannel(); assertEquals(1234L, readChannel.size()); assertEquals(1234L, readChannel.size()); verify(fakeService, times(1)).getObject(eq(GET_OBJECT_REQUEST), any()); }