java - How to download GZip file from S3? -


i have looked @ both aws s3 java sdk - download file help , working zip , gzip files in java.

while provide ways download , deal files s3 , gzipped files respectively, these not in dealing gzipped file located in s3. how this?

currently have:

try {     amazons3 s3client = new amazons3client(             new profilecredentialsprovider());     string url = downloadurl.getprimitivejavaobject(arg0[0].get());     s3object fileobj = s3client.getobject(getbucket(url), getfile(url));     bufferedreader filein = new bufferedreader(new inputstreamreader(             fileobj.getobjectcontent()));     string filecontent = "";     string line = filein.readline();     while (line != null){         filecontent += line + "\n";         line = filein.readline();     }     fileobj.close();     return filecontent; } catch (ioexception e) {     e.printstacktrace();     return "error ioexception"; } 

clearly, not handling compressed nature of file, , output is:

����su�3204�50�5010�20�24��l,(���o�v�m-.nlou�r�u�����<s��<#�^�.wߐx�%w���������}c=�%�j3��.�����둚�s�ᜑ���zq�t�e��#sr�cdn#瘐:&� s�bǔj����p�<�� 

however, cannot implement example in second question given above because file not located locally, requires downloading s3.

what should do?

i solved issue using scanner instead of inputstream.

the scanner takes gzipinputstream , reads unzipped file line line:

fileobj = s3client.getobject(new getobjectrequest(osummary.getbucketname(), osummary.getkey())); filein = new scanner(new gzipinputstream(fileobj.getobjectcontent())); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -