I am trying to read a file from azure blob storage as byte stream as below:
public static final String storageConnectionString =
"DefaultEndpointsProtocol=https;AccountName=*;AccountKey=*;EndpointSuffix=core.windows.net";
public static void main(String[] args) {
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("inputfile");
CloudBlob blob = container.getBlockBlobReference("test.txt");
InputStream input = blob.openInputStream();
InputStreamReader inr = new InputStreamReader(input, "UTF-8");
String output = IOUtils.toString(inr);
System.out.println(output);
System.out.println("read is success");
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
}
}
I am able to read the file from azure file storage. I am trying to create something like Java WatchService where if there is any change in file i want read the changes and print data for example below let say i have file test.txt file in blob initially it have data some thing like below
"Hello"
My program should print "Hello"
.
After some time i will update file with "world"
, now i want to print only "world"
which is a new change in file.
Is it possible in azure blob storage? I saw the API of azure_blob_storage
but didn't find any method like java WatchServices. Could you please help me how can i read file changes in azure blob storage?