I want to print the data present in the file in GCS bucket.As per my requirement, file should not be downloaded to local system but the code should directly read the code from gcs bucket itselef.As my file size is huge, i dont want to download the file to local system.
Below is the code which i'm trying but i'm not getting the expected output.
import java.io.*;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.ReadChannel;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import java.io.*;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.ReadChannel;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
public class BucketData{
public static void main(String[] args) throws IOException{
String PROJECT_ID = "project_name";
String PATH_TO_JSON_KEY = "path/to/json_key";
System.out.println(PATH_TO_JSON_KEY);
String BUCKET_NAME = "bucket";
String OBJECT_NAME = "abhi.txt";
StorageOptions options = StorageOptions.newBuilder()
.setProjectId(PROJECT_ID)
.setCredentials(GoogleCredentials.fromStream(
new FileInputStream(PATH_TO_JSON_KEY))).build();
Storage storage = options.getService();
Blob blob = storage.get(BUCKET_NAME, OBJECT_NAME);
ReadChannel r = blob.reader();
System.out.println(r);
}
}