Java program upload file to Azure Blob Storage with progress indicator
Main.java
All field types supported (including MEMO, BLOB, graphic, rtf-formatted memo etc) When Clarion file loaded, you may save the data to different file formats (CSV, Text, HTML, XML, MS Excel, MS Access, SPSS, SQL etc) or copy to clipboard. You may convert any Clarion data file into another file format without any programming in a few mouse clicks.
packagecom.cloudriches.sample; |
importcom.microsoft.azure.storage.CloudStorageAccount; |
importcom.microsoft.azure.storage.blob.CloudBlobClient; |
importcom.microsoft.azure.storage.blob.CloudBlobContainer; |
importcom.microsoft.azure.storage.blob.CloudBlockBlob; |
importjava.io.File; |
importjava.io.FileInputStream; |
publicclassMainimplementsWatchingInputStream.ProgressListener { |
publicstaticvoidmain(String[] args) throwsException { |
Main main =newMain(); |
main.upload(); |
} |
publicvoidupload() throwsException |
{ |
CloudStorageAccount account =CloudStorageAccount.parse('DefaultEndpointsProtocol=https;AccountName= ....'); |
CloudBlobClient client = account.createCloudBlobClient(); |
CloudBlobContainer container = client.getContainerReference('files'); |
CloudBlockBlob blob = container.getBlockBlobReference('template_62269_xQ0qqGGG71BB3y99n11x.zip'); |
File sourceFile =newFile('/Users/dino/Downloads/template_62269_xQ0qqGGG71BB3y99n11x.zip'); |
FileInputStream inputStream =newFileInputStream(sourceFile); |
WatchingInputStream watchingInputStream =newWatchingInputStream(inputStream, this); |
blob.upload(watchingInputStream, sourceFile.length()); |
} |
@Override |
publicvoidonAdvance(longat, longlength) { |
double percentage = (double)at / (double)length; |
System.out.println(percentage); |
} |
} |
![Programs Programs](/uploads/1/2/5/8/125849179/196474692.png)
WatchingInputStream.java
packagecom.cloudriches.sample; |
importjava.io.FilterInputStream; |
importjava.io.IOException; |
importjava.io.InputStream; |
// from https://gist.github.com/alterakey/1454764 |
publicclassWatchingInputStreamextendsFilterInputStream { |
publicinterfaceProgressListener { |
voidonAdvance(longat, longlength); |
} |
privateint marked =0; |
privatelong position =0; |
privateProgressListener listener; |
publicWatchingInputStream(InputStreamin, ProgressListenerlistener) { |
super(in); |
this.listener = listener; |
} |
@Override |
publicintread(byte[] buffer, intoffset, intcount) throwsIOException { |
int advanced =super.read(buffer, offset, count); |
this.position += advanced; |
this.report(); |
return advanced; |
} |
@Override |
publicsynchronizedvoidreset() throwsIOException { |
super.reset(); |
this.position =this.marked; |
} |
@Override |
publicsynchronizedvoidmark(intreadlimit) { |
super.mark(readlimit); |
this.marked = readlimit; |
} |
@Override |
publiclongskip(longbyteCount) throwsIOException { |
long advanced =super.skip(byteCount); |
this.position += advanced; |
this.report(); |
return advanced; |
} |
privatevoidreport() { |
if (this.listener null) |
return; |
try { |
this.listener.onAdvance(this.position, this.position +this.in.available()); |
} |
catch (IOException e) { |
this.listener.onAdvance(this.position, 0); |
} |
} |
} |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment