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

Read Images from a xlsx file using Apache POI

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

How to create mail message in FRC822 format