Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Last active February 12, 2019 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/8f295c686a38f901fccb92a69c76e597 to your computer and use it in GitHub Desktop.
Save abhirockzz/8f295c686a38f901fccb92a69c76e597 to your computer and use it in GitHub Desktop.
public String handle(GetObjectInfo objectInfo) {
String result = "FAILED";
if (objStoreClient == null) {
System.err.println("There was a problem creating the ObjectStorageClient object. Please check logs");
return result;
}
try {
String nameSpace = System.getenv().get("NAMESPACE");
GetObjectRequest gor = GetObjectRequest.builder()
.namespaceName(nameSpace)
.bucketName(objectInfo.getBucketName())
.objectName(objectInfo.getName())
.build();
System.err.println("Getting content for object " + objectInfo.getName() + " from bucket " + objectInfo.getBucketName());
GetObjectResponse response = objStoreClient.getObject(gor);
result = new BufferedReader(new InputStreamReader(response.getInputStream()))
.lines().collect(Collectors.joining("\n"));
System.err.println("Finished reading content for object " + objectInfo.getName());
} catch (Throwable e) {
System.err.println("Error fetching object " + e.getMessage());
result = "Error fetching object " + e.getMessage();
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment