Following the official documentation I've been trying to read a sample file I stored within GCS, but so far the only thing I've got is a NullPointerException
InputStream sampleStream() {
String bucketName = "sample";
String fileName = "sample";
log.info("Loading file from GCS [bucket: {}, key: {}]", bucketName, fileName);
try {
GcsInputChannel readChannel = gcsService().openReadChannel(new GcsFilename(bucketName, fileName), 0);
return Channels.newInputStream(readChannel);
} catch(Exception ex) {
log.error("Error loading file...", ex);
}
}
private GcsService gcsService() {
return GcsServiceFactory
.createGcsService(new RetryParams.Builder()
.initialRetryDelayMillis(10).retryMaxAttempts(10)
.totalRetryPeriodMillis(15000)
.build()
);
}
But still retrying all the time...
RetryHelper(14.16 ms, 1 attempts, com.google.appengine.tools.cloudstorage.SimpleGcsInputChannelImpl$1@278ef74): Attempt #1 failed [java.io.IOException: java.lang.NullPointerException], sleeping for 9 ms
The NullPointerException is thrown whenever .read()
is invoked within the resulting InputStream.
Am I missing credentials (or the path to my local .json auth file) somewhere or should I take into account more things?