test_class.file: gcsio/src/test/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageReadChannelTest.java
test_class.identifier: GoogleCloudStorageReadChannelTest
test_case.body: @Test
    public void read_whenBufferIsEmpty() throws IOException {
      ByteBuffer emptyBuffer = ByteBuffer.wrap(new byte[0]);
  
      Storage storage = new Storage(HTTP_TRANSPORT, JSON_FACTORY, r -> {});
  
      GoogleCloudStorageReadChannel readChannel =
          createReadChannel(storage, newLazyReadOptionsBuilder().build());
  
      assertThat(readChannel.read(emptyBuffer)).isEqualTo(0);
    }
test_case.class_method_signature: GoogleCloudStorageReadChannelTest.read_whenBufferIsEmpty()
test_case.full_signature: @Test public void read_whenBufferIsEmpty()
test_case.identifier: read_whenBufferIsEmpty
test_case.invocations: wrap createReadChannel build newLazyReadOptionsBuilder isEqualTo assertThat read
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void read_whenBufferIsEmpty()
focal_class.declarator: logger = GoogleLogger.forEnclosingClass()
focal_class.modifier: private static final
focal_class.original_string: private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
focal_class.type: GoogleLogger
focal_class.var_name: logger
focal_class.declarator: SKIP_BUFFER_SIZE = 8192
focal_class.modifier: @VisibleForTesting static final
focal_class.original_string: @VisibleForTesting static final int SKIP_BUFFER_SIZE = 8192;
focal_class.type: int
focal_class.var_name: SKIP_BUFFER_SIZE
focal_class.declarator: GZIP_ENCODING = "gzip"
focal_class.modifier: private static final
focal_class.original_string: private static final String GZIP_ENCODING = "gzip";
focal_class.type: String
focal_class.var_name: GZIP_ENCODING
focal_class.declarator: gcs
focal_class.modifier: private final
focal_class.original_string: private final Storage gcs;
focal_class.type: Storage
focal_class.var_name: gcs
focal_class.declarator: resourceId
focal_class.modifier: private
focal_class.original_string: private StorageResourceId resourceId;
focal_class.type: StorageResourceId
focal_class.var_name: resourceId
focal_class.declarator: contentChannel
focal_class.modifier: @VisibleForTesting
focal_class.original_string: @VisibleForTesting ReadableByteChannel contentChannel;
focal_class.type: ReadableByteChannel
focal_class.var_name: contentChannel
focal_class.declarator: channelIsOpen = true
focal_class.modifier: private
focal_class.original_string: private boolean channelIsOpen = true;
focal_class.type: boolean
focal_class.var_name: channelIsOpen
focal_class.declarator: currentPosition = 0
focal_class.modifier: protected
focal_class.original_string: protected long currentPosition = 0;
focal_class.type: long
focal_class.var_name: currentPosition
focal_class.declarator: contentChannelPosition = -1
focal_class.modifier: protected
focal_class.original_string: protected long contentChannelPosition = -1;
focal_class.type: long
focal_class.var_name: contentChannelPosition
focal_class.declarator: size = -1
focal_class.modifier: private
focal_class.original_string: private long size = -1;
focal_class.type: long
focal_class.var_name: size
focal_class.declarator: contentChannelEnd = -1
focal_class.modifier: private
focal_class.original_string: private long contentChannelEnd = -1;
focal_class.type: long
focal_class.var_name: contentChannelEnd
focal_class.declarator: randomAccess
focal_class.modifier: @VisibleForTesting
focal_class.original_string: @VisibleForTesting boolean randomAccess;
focal_class.type: boolean
focal_class.var_name: randomAccess
focal_class.declarator: maxRetries = 10
focal_class.modifier: private
focal_class.original_string: private int maxRetries = 10;
focal_class.type: int
focal_class.var_name: maxRetries
focal_class.declarator: errorExtractor
focal_class.modifier: private final
focal_class.original_string: private final ApiErrorExtractor errorExtractor;
focal_class.type: ApiErrorExtractor
focal_class.var_name: errorExtractor
focal_class.declarator: clientRequestHelper
focal_class.modifier: private final
focal_class.original_string: private final ClientRequestHelper<StorageObject> clientRequestHelper;
focal_class.type: ClientRequestHelper<StorageObject>
focal_class.var_name: clientRequestHelper
focal_class.declarator: readOptions
focal_class.modifier: private final
focal_class.original_string: private final GoogleCloudStorageReadOptions readOptions;
focal_class.type: GoogleCloudStorageReadOptions
focal_class.var_name: readOptions
focal_class.declarator: sleeper = Sleeper.DEFAULT
focal_class.modifier: private
focal_class.original_string: private Sleeper sleeper = Sleeper.DEFAULT;
focal_class.type: Sleeper
focal_class.var_name: sleeper
focal_class.declarator: clock = NanoClock.SYSTEM
focal_class.modifier: private
focal_class.original_string: private NanoClock clock = NanoClock.SYSTEM;
focal_class.type: NanoClock
focal_class.var_name: clock
focal_class.declarator: readBackOff = Suppliers.memoize(this::createBackOff)
focal_class.modifier: private
focal_class.original_string: private Supplier<BackOff> readBackOff = Suppliers.memoize(this::createBackOff);
focal_class.type: Supplier<BackOff>
focal_class.var_name: readBackOff
focal_class.declarator: skipBuffer = null
focal_class.modifier: private
focal_class.original_string: private byte[] skipBuffer = null;
focal_class.type: byte[]
focal_class.var_name: skipBuffer
focal_class.declarator: gzipEncoded = false
focal_class.modifier: private
focal_class.original_string: private boolean gzipEncoded = false;
focal_class.type: boolean
focal_class.var_name: gzipEncoded
focal_class.declarator: footerContent
focal_class.modifier: private
focal_class.original_string: private byte[] footerContent;
focal_class.type: byte[]
focal_class.var_name: footerContent
focal_class.declarator: metadataInitialized = false
focal_class.modifier: @VisibleForTesting protected
focal_class.original_string: @VisibleForTesting protected boolean metadataInitialized = false;
focal_class.type: boolean
focal_class.var_name: metadataInitialized
focal_class.file: gcsio/src/main/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageReadChannel.java
focal_class.identifier: GoogleCloudStorageReadChannel
focal_class.interfaces: implements SeekableByteChannel
focal_class.class_method_signature: GoogleCloudStorageReadChannel.GoogleCloudStorageReadChannel(
        Storage gcs,
        String bucketName,
        String objectName,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper)
focal_class.full_signature: public  GoogleCloudStorageReadChannel(
        Storage gcs,
        String bucketName,
        String objectName,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper)
focal_class.identifier: GoogleCloudStorageReadChannel
focal_class.modifiers: public
focal_class.parameters: (
        Storage gcs,
        String bucketName,
        String objectName,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper)
focal_class.signature:  GoogleCloudStorageReadChannel(
        Storage gcs,
        String bucketName,
        String objectName,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.GoogleCloudStorageReadChannel(
        Storage gcs,
        String bucketName,
        String objectName,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper,
        @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.full_signature: public  GoogleCloudStorageReadChannel(
        Storage gcs,
        String bucketName,
        String objectName,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper,
        @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.identifier: GoogleCloudStorageReadChannel
focal_class.modifiers: public
focal_class.parameters: (
        Storage gcs,
        String bucketName,
        String objectName,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper,
        @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.signature:  GoogleCloudStorageReadChannel(
        Storage gcs,
        String bucketName,
        String objectName,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper,
        @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.GoogleCloudStorageReadChannel(
        Storage gcs,
        StorageResourceId resourceId,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper,
        @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.full_signature: public  GoogleCloudStorageReadChannel(
        Storage gcs,
        StorageResourceId resourceId,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper,
        @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.identifier: GoogleCloudStorageReadChannel
focal_class.modifiers: public
focal_class.parameters: (
        Storage gcs,
        StorageResourceId resourceId,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper,
        @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.signature:  GoogleCloudStorageReadChannel(
        Storage gcs,
        StorageResourceId resourceId,
        ApiErrorExtractor errorExtractor,
        ClientRequestHelper<StorageObject> requestHelper,
        @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.GoogleCloudStorageReadChannel(
        String bucketName, String objectName, @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.full_signature: protected  GoogleCloudStorageReadChannel(
        String bucketName, String objectName, @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.identifier: GoogleCloudStorageReadChannel
focal_class.modifiers: protected
focal_class.parameters: (
        String bucketName, String objectName, @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.signature:  GoogleCloudStorageReadChannel(
        String bucketName, String objectName, @Nonnull GoogleCloudStorageReadOptions readOptions)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.setSleeper(Sleeper sleeper)
focal_class.full_signature: @VisibleForTesting void setSleeper(Sleeper sleeper)
focal_class.identifier: setSleeper
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: (Sleeper sleeper)
focal_class.return: void
focal_class.signature: void setSleeper(Sleeper sleeper)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.setNanoClock(NanoClock clock)
focal_class.full_signature: @VisibleForTesting void setNanoClock(NanoClock clock)
focal_class.identifier: setNanoClock
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: (NanoClock clock)
focal_class.return: void
focal_class.signature: void setNanoClock(NanoClock clock)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.setReadBackOff(BackOff backOff)
focal_class.full_signature:  void setReadBackOff(BackOff backOff)
focal_class.identifier: setReadBackOff
focal_class.parameters: (BackOff backOff)
focal_class.return: void
focal_class.signature: void setReadBackOff(BackOff backOff)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.getReadBackOff()
focal_class.full_signature: @VisibleForTesting BackOff getReadBackOff()
focal_class.identifier: getReadBackOff
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: ()
focal_class.return: BackOff
focal_class.signature: BackOff getReadBackOff()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.createBackOff()
focal_class.full_signature: @VisibleForTesting ExponentialBackOff createBackOff()
focal_class.identifier: createBackOff
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: ()
focal_class.return: ExponentialBackOff
focal_class.signature: ExponentialBackOff createBackOff()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.getInitialMetadata()
focal_class.full_signature: @Nullable protected GoogleCloudStorageItemInfo getInitialMetadata()
focal_class.identifier: getInitialMetadata
focal_class.modifiers: @Nullable protected
focal_class.parameters: ()
focal_class.return: GoogleCloudStorageItemInfo
focal_class.signature: GoogleCloudStorageItemInfo getInitialMetadata()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.fetchInitialMetadata()
focal_class.full_signature: private GoogleCloudStorageItemInfo fetchInitialMetadata()
focal_class.identifier: fetchInitialMetadata
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: GoogleCloudStorageItemInfo
focal_class.signature: GoogleCloudStorageItemInfo fetchInitialMetadata()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.setMaxRetries(int maxRetries)
focal_class.full_signature: public void setMaxRetries(int maxRetries)
focal_class.identifier: setMaxRetries
focal_class.modifiers: public
focal_class.parameters: (int maxRetries)
focal_class.return: void
focal_class.signature: void setMaxRetries(int maxRetries)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.read(ByteBuffer buffer)
focal_class.full_signature: @Override public int read(ByteBuffer buffer)
focal_class.identifier: read
focal_class.modifiers: @Override public
focal_class.parameters: (ByteBuffer buffer)
focal_class.return: int
focal_class.signature: int read(ByteBuffer buffer)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.truncate(long size)
focal_class.full_signature: @Override public SeekableByteChannel truncate(long size)
focal_class.identifier: truncate
focal_class.modifiers: @Override public
focal_class.parameters: (long size)
focal_class.return: SeekableByteChannel
focal_class.signature: SeekableByteChannel truncate(long size)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.write(ByteBuffer src)
focal_class.full_signature: @Override public int write(ByteBuffer src)
focal_class.identifier: write
focal_class.modifiers: @Override public
focal_class.parameters: (ByteBuffer src)
focal_class.return: int
focal_class.signature: int write(ByteBuffer src)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.isOpen()
focal_class.full_signature: @Override public boolean isOpen()
focal_class.identifier: isOpen
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isOpen()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.closeContentChannel()
focal_class.full_signature: protected void closeContentChannel()
focal_class.identifier: closeContentChannel
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void closeContentChannel()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.resetContentChannel()
focal_class.full_signature: private void resetContentChannel()
focal_class.identifier: resetContentChannel
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void resetContentChannel()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.close()
focal_class.full_signature: @Override public void close()
focal_class.identifier: close
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void close()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.position()
focal_class.full_signature: @Override public long position()
focal_class.identifier: position
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: long
focal_class.signature: long position()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.position(long newPosition)
focal_class.full_signature: @Override public SeekableByteChannel position(long newPosition)
focal_class.identifier: position
focal_class.modifiers: @Override public
focal_class.parameters: (long newPosition)
focal_class.return: SeekableByteChannel
focal_class.signature: SeekableByteChannel position(long newPosition)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.isRandomAccessPattern(long oldPosition)
focal_class.full_signature: private boolean isRandomAccessPattern(long oldPosition)
focal_class.identifier: isRandomAccessPattern
focal_class.modifiers: private
focal_class.parameters: (long oldPosition)
focal_class.return: boolean
focal_class.signature: boolean isRandomAccessPattern(long oldPosition)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.shouldDetectRandomAccess()
focal_class.full_signature: private boolean shouldDetectRandomAccess()
focal_class.identifier: shouldDetectRandomAccess
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean shouldDetectRandomAccess()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.setRandomAccess()
focal_class.full_signature: private void setRandomAccess()
focal_class.identifier: setRandomAccess
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void setRandomAccess()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.skipInPlace(long seekDistance)
focal_class.full_signature: private void skipInPlace(long seekDistance)
focal_class.identifier: skipInPlace
focal_class.modifiers: private
focal_class.parameters: (long seekDistance)
focal_class.return: void
focal_class.signature: void skipInPlace(long seekDistance)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.size()
focal_class.full_signature: @Override public long size()
focal_class.identifier: size
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: long
focal_class.signature: long size()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.generation()
focal_class.full_signature: @VisibleForTesting long generation()
focal_class.identifier: generation
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: ()
focal_class.return: long
focal_class.signature: long generation()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.setSize(long size)
focal_class.full_signature: protected void setSize(long size)
focal_class.identifier: setSize
focal_class.modifiers: protected
focal_class.parameters: (long size)
focal_class.return: void
focal_class.signature: void setSize(long size)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.checkEncodingAndAccess()
focal_class.full_signature: private void checkEncodingAndAccess()
focal_class.identifier: checkEncodingAndAccess
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void checkEncodingAndAccess()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.validatePosition(long position)
focal_class.full_signature: protected void validatePosition(long position)
focal_class.identifier: validatePosition
focal_class.modifiers: protected
focal_class.parameters: (long position)
focal_class.return: void
focal_class.signature: void validatePosition(long position)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.performLazySeek(long bytesToRead)
focal_class.full_signature: @VisibleForTesting void performLazySeek(long bytesToRead)
focal_class.identifier: performLazySeek
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: (long bytesToRead)
focal_class.return: void
focal_class.signature: void performLazySeek(long bytesToRead)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.openContentChannel(long bytesToRead)
focal_class.full_signature: private void openContentChannel(long bytesToRead)
focal_class.identifier: openContentChannel
focal_class.modifiers: private
focal_class.parameters: (long bytesToRead)
focal_class.return: void
focal_class.signature: void openContentChannel(long bytesToRead)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.initMetadata(GoogleCloudStorageItemInfo info)
focal_class.full_signature: private void initMetadata(GoogleCloudStorageItemInfo info)
focal_class.identifier: initMetadata
focal_class.modifiers: private
focal_class.parameters: (GoogleCloudStorageItemInfo info)
focal_class.return: void
focal_class.signature: void initMetadata(GoogleCloudStorageItemInfo info)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.initMetadata(HttpHeaders headers)
focal_class.full_signature: @VisibleForTesting protected void initMetadata(HttpHeaders headers)
focal_class.identifier: initMetadata
focal_class.modifiers: @VisibleForTesting protected
focal_class.parameters: (HttpHeaders headers)
focal_class.return: void
focal_class.signature: void initMetadata(HttpHeaders headers)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.initMetadata(@Nullable String encoding, long sizeFromMetadata, long generation)
focal_class.full_signature: @VisibleForTesting protected void initMetadata(@Nullable String encoding, long sizeFromMetadata, long generation)
focal_class.identifier: initMetadata
focal_class.modifiers: @VisibleForTesting protected
focal_class.parameters: (@Nullable String encoding, long sizeFromMetadata, long generation)
focal_class.return: void
focal_class.signature: void initMetadata(@Nullable String encoding, long sizeFromMetadata, long generation)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.cacheFooter(HttpResponse response)
focal_class.full_signature: private void cacheFooter(HttpResponse response)
focal_class.identifier: cacheFooter
focal_class.modifiers: private
focal_class.parameters: (HttpResponse response)
focal_class.return: void
focal_class.signature: void cacheFooter(HttpResponse response)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.openFooterStream()
focal_class.full_signature: private InputStream openFooterStream()
focal_class.identifier: openFooterStream
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: InputStream
focal_class.signature: InputStream openFooterStream()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.openStream(long bytesToRead)
focal_class.full_signature: protected InputStream openStream(long bytesToRead)
focal_class.identifier: openStream
focal_class.modifiers: protected
focal_class.parameters: (long bytesToRead)
focal_class.return: InputStream
focal_class.signature: InputStream openStream(long bytesToRead)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.isFooterRead()
focal_class.full_signature: private boolean isFooterRead()
focal_class.identifier: isFooterRead
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isFooterRead()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.getContentChannelPositionForFirstRead(long bytesToRead)
focal_class.full_signature: private long getContentChannelPositionForFirstRead(long bytesToRead)
focal_class.identifier: getContentChannelPositionForFirstRead
focal_class.modifiers: private
focal_class.parameters: (long bytesToRead)
focal_class.return: long
focal_class.signature: long getContentChannelPositionForFirstRead(long bytesToRead)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.handleExecuteMediaException(IOException e)
focal_class.full_signature: private HttpResponse handleExecuteMediaException(IOException e)
focal_class.identifier: handleExecuteMediaException
focal_class.modifiers: private
focal_class.parameters: (IOException e)
focal_class.return: HttpResponse
focal_class.signature: HttpResponse handleExecuteMediaException(IOException e)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.createDataRequest(String rangeHeader)
focal_class.full_signature: private Get createDataRequest(String rangeHeader)
focal_class.identifier: createDataRequest
focal_class.modifiers: private
focal_class.parameters: (String rangeHeader)
focal_class.return: Get
focal_class.signature: Get createDataRequest(String rangeHeader)
focal_class.class_method_signature: GoogleCloudStorageReadChannel.createRequest()
focal_class.full_signature: protected Get createRequest()
focal_class.identifier: createRequest
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: Get
focal_class.signature: Get createRequest()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.throwIfNotOpen()
focal_class.full_signature: private void throwIfNotOpen()
focal_class.identifier: throwIfNotOpen
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void throwIfNotOpen()
focal_class.class_method_signature: GoogleCloudStorageReadChannel.checkIOPrecondition(boolean precondition, String errorMessage)
focal_class.full_signature: private void checkIOPrecondition(boolean precondition, String errorMessage)
focal_class.identifier: checkIOPrecondition
focal_class.modifiers: private
focal_class.parameters: (boolean precondition, String errorMessage)
focal_class.return: void
focal_class.signature: void checkIOPrecondition(boolean precondition, String errorMessage)
focal_method.body: @Override
    public int read(ByteBuffer buffer) throws IOException {
      throwIfNotOpen();
  
      // Don't try to read if the buffer has no space.
      if (buffer.remaining() == 0) {
        return 0;
      }
  
      logger.atFine().log(
          "Reading %s bytes at %s position from '%s'",
          buffer.remaining(), currentPosition, resourceId);
  
      // Do not perform any further reads if we already read everything from this channel.
      if (currentPosition == size) {
        return -1;
      }
  
      int totalBytesRead = 0;
      int retriesAttempted = 0;
  
      // We read from a streaming source. We may not get all the bytes we asked for
      // in the first read. Therefore, loop till we either read the required number of
      // bytes or we reach end-of-stream.
      do {
        int remainingBeforeRead = buffer.remaining();
        performLazySeek(remainingBeforeRead);
        checkState(
            contentChannelPosition == currentPosition,
            "contentChannelPosition (%s) should be equal to currentPosition (%s) after lazy seek",
            contentChannelPosition, currentPosition);
  
        try {
          int numBytesRead = contentChannel.read(buffer);
          checkIOPrecondition(numBytesRead != 0, "Read 0 bytes without blocking");
          if (numBytesRead < 0) {
            // Because we don't know decompressed object size for gzip-encoded objects,
            // assume that this is an object end.
            if (gzipEncoded) {
              size = currentPosition;
              contentChannelEnd = currentPosition;
            }
            // Check that we didn't get a premature End of Stream signal by checking the number of
            // bytes read against the stream size. Unfortunately we don't have information about the
            // actual size of the data stream when stream compression is used, so we can only ignore
            // this case here.
            checkIOPrecondition(
                currentPosition == contentChannelEnd || currentPosition == size,
                String.format(
                    "Received end of stream result before all the file data has been received; "
                        + "totalBytesRead: %d, currentPosition: %d,"
                        + " contentChannelEnd %d, size: %d, object: '%s'",
                    totalBytesRead, currentPosition, contentChannelEnd, size, resourceId));
  
            // If we have reached an end of a contentChannel but not an end of an object
            // then close contentChannel and continue reading an object if necessary.
            if (contentChannelEnd != size && currentPosition == contentChannelEnd) {
              closeContentChannel();
            } else {
              break;
            }
          }
  
          if (numBytesRead > 0) {
            totalBytesRead += numBytesRead;
            currentPosition += numBytesRead;
            contentChannelPosition += numBytesRead;
            checkState(
                contentChannelPosition == currentPosition,
                "contentChannelPosition (%s) should be equal to currentPosition (%s)"
                    + " after successful read",
                contentChannelPosition, currentPosition);
          }
  
          if (retriesAttempted != 0) {
            logger.atInfo().log(
                "Success after %s retries on reading '%s'", retriesAttempted, resourceId);
          }
          // The count of retriesAttempted is per low-level contentChannel.read call;
          // each time we make progress we reset the retry counter.
          retriesAttempted = 0;
        } catch (IOException ioe) {
          logger.atFine().log(
              "Closing contentChannel after %s exception for '%s'.", ioe.getMessage(), resourceId);
          closeContentChannel();
  
          if (buffer.remaining() != remainingBeforeRead) {
            int partialRead = remainingBeforeRead - buffer.remaining();
            logger.atInfo().log(
                "Despite exception, had partial read of %s bytes from '%s'; resetting retry count.",
                partialRead, resourceId);
            retriesAttempted = 0;
            totalBytesRead += partialRead;
            currentPosition += partialRead;
          }
  
          // TODO(user): Refactor any reusable logic for retries into a separate RetryHelper class.
          if (retriesAttempted == maxRetries) {
            logger.atSevere().log(
                "Throwing exception after reaching max read retries (%s) for '%s'.",
                maxRetries, resourceId);
            throw ioe;
          }
  
          if (retriesAttempted == 0) {
            // If this is the first of a series of retries, we also want to reset the readBackOff
            // to have fresh initial values.
            readBackOff.get().reset();
          }
  
          ++retriesAttempted;
          logger.atWarning().withCause(ioe).log(
              "Failed read retry #%s/%s for '%s'. Sleeping...",
              retriesAttempted, maxRetries, resourceId);
          try {
            boolean backOffSuccessful = BackOffUtils.next(sleeper, readBackOff.get());
            if (!backOffSuccessful) {
              logger.atSevere().log(
                  "BackOff returned false; maximum total elapsed time exhausted."
                      + " Giving up after %s/%s retries for '%s'",
                  retriesAttempted, maxRetries, resourceId);
              throw ioe;
            }
          } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
            logger.atSevere().log(
                "Interrupted while sleeping before retry. Giving up after %s/%s retries for '%s'",
                retriesAttempted, maxRetries, resourceId);
            ioe.addSuppressed(ie);
            throw ioe;
          }
  
          logger.atInfo().log(
              "Done sleeping before retry #%s/%s for '%s'", retriesAttempted, maxRetries, resourceId);
        } catch (RuntimeException r) {
          closeContentChannel();
          throw r;
        }
      } while (buffer.remaining() > 0 && currentPosition < size);
  
      // If this method was called when the stream was already at EOF
      // (indicated by totalBytesRead == 0) then return EOF else,
      // return the number of bytes read.
      boolean isEndOfStream = (totalBytesRead == 0);
      if (isEndOfStream) {
        // Check that we didn't get a premature End of Stream signal by checking the number of bytes
        // read against the stream size. Unfortunately we don't have information about the actual size
        // of the data stream when stream compression is used, so we can only ignore this case here.
        checkIOPrecondition(
            currentPosition == size,
            String.format(
                "Failed to read any data before all the file data has been received;"
                    + " currentPosition: %d, size: %d, object '%s'",
                currentPosition, size, resourceId));
        return -1;
      }
      return totalBytesRead;
    }
focal_method.class_method_signature: GoogleCloudStorageReadChannel.read(ByteBuffer buffer)
focal_method.full_signature: @Override public int read(ByteBuffer buffer)
focal_method.identifier: read
focal_method.invocations: throwIfNotOpen remaining log atFine remaining remaining performLazySeek checkState read checkIOPrecondition checkIOPrecondition format closeContentChannel checkState log atInfo log atFine getMessage closeContentChannel remaining remaining log atInfo log atSevere reset get log withCause atWarning next get log atSevere interrupt currentThread log atSevere addSuppressed log atInfo closeContentChannel remaining checkIOPrecondition format
focal_method.modifiers: @Override public
focal_method.parameters: (ByteBuffer buffer)
focal_method.return: int
focal_method.signature: int read(ByteBuffer buffer)