Read gzip response from a URL using Java

Here is a code template.....

public static String readGZFile(String url) throws IOException {
           StringBuffer dataBuffer =new StringBuffer();
           InputStream gzipStream = new GZIPInputStream((new URL(url)).openStream());
           Reader decoder = new InputStreamReader(gzipStream, "UTF-8");
           BufferedReader buffered = new BufferedReader(decoder);
           int i=0;
           String line=buffered.readLine();
           while(line !=null){
               dataBuffer.append(line);
               line=buffered.readLine();
               i++;
           }       
           return dataBuffer.toString();          
    }

Comments

Popular posts from this blog

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

Upload csv file at Google Cloud Storage using java

Read Images from a xlsx file using Apache POI