Showing posts with label zip. Show all posts
Showing posts with label zip. Show all posts

Tuesday, January 5, 2016

GZip HTTP Request/Response

import java.util.zip.GZIPInputStream

String pageUrl = "http://www.google.com"
BufferedInputStream buff = pageUrl.toURL().newInputStream(requestProperties: ['Accept-Encoding': 'gzip,deflate'])
BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(buff)))
String resp = ""; reader.eachLine{ line -> resp += line }

Thursday, November 24, 2011

Read Lines in Zip File's (File) Entries

//to read a file:

import java.io.*;
import java.util.*;
import java.util.zip.*;

String fname = "C:\\test.zip"

ZipFile zf = new ZipFile(fname)

zf.entries().each { entry ->
    if (!entry.directory) {
        String entryFileName = entry.name
        println entryFileName
        InputStream inp = zf.getInputStream(entryFileName);
        inp.eachLine { line -> println line }
    }
}

//to write a file:
new AntBuilder().zip(destfile:"zipped.zip", basedir=".", excludes="lib .svn plugins *.class")
//http://groovy-almanac.org/creating-a-zipfile-with-antbuilder/