Java: streaming the contents of a zip file over HTTP

I have quite a lot of streaming data (> 100 MB) which I would like to place in a zip file on an http server for compression. So this zipfile contains one file.

Is it possible for a java client to be able to transfer data via http, even if it is packed into a zip file?

According to Wikipedia, ZIP files are not consistent ...

http://en.wikipedia.org/wiki/ZIP_(file_format)#Structure

If this is still possible, then how?

edit: about gzip: as I said, I use a custom java client (not a webbrowser) - is gzip available in the java-http implementation?

+5
source share
5 answers

Java gzip GZipInputStream () GZipOutputStream (). zip gzip , : zip , gzip ( gzip ).

gzip, , .

, HTTPConnection Accept-Encoding: gzip, , Content-Encoding: gzip, , , , .gz (.. Content-Encoding: identity).

(, , , , Java GZipInputStream zlib.)

+4

( ), :

static void processZippedInputStream(InputStream in, String entryNameRegex)
throws IOException
{
    ZipInputStream zin = new ZipInputStream(in);
    ZipEntry ze;
    while ((ze = zin.getNextEntry()) != null)
    {
        if (ze.getName().matches(entryNameRegex))
        {
            // treat zin as a normal input stream - ie read() from it till "empty" etc
            break;
        }
        zin.closeEntry();
    }
    zin.close();
}

InputStream . , , , ..

+5

, , MIME application/zip

, , , .

, mp3 , ogg/vorbis

+2

GZIP, . Gzip zip.

0

All Articles