GZipinputstream is for streams (or files) ziped as gzip (".gz" extension). It doesn't have any header information.
If you have a real zip file, you have to user ZipFile to open the file, ask for the list of files (one in your example) and ask for the decompressed input stream.
Your method would be something like:
// ITS PSEUDOCODE!!
private InputStream extractOnlyFile(String path) {
ZipFile zf = new ZipFile(path);
Enumeration e = zf.entries();
ZipEntry entry = (ZipEntry) e.nextElement(); // your only file
return zf.getInputStream(entry);
}
EDIT:
Ok, if you have an inputstream you can use (as cletus says) ZipInputStream. The code would be something like:
// ITS PSEUDOCODE!!
private InputStream extractOnlyFile(InputStream input) {
ZipInputStream zipinput = new ZipInputStream(input);
ZipEntry entry = zipinput.getNextEntry(); // reads the header info and position in the begining of the file
return zipinput;
}
EDIT: working example
Important: if you have the file in your PC you can use ZipFile
class to access it randomly
This is a test I've made now in my PC:
import java.io.FileInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Main {
public static void main(String[] args) throws Exception
{
FileInputStream fis = new FileInputStream("c:/inas400.zip");
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry entry;
// while there are entries I process them
while ((entry = zis.getNextEntry()) != null)
{
System.out.println("entry: " + entry.getName() + ", " + entry.getSize());
// consume all the data from this entry
while (zis.available() > 0)
zis.read();
// I could close the entry, but getNextEntry does it automatically
// zis.closeEntry()
}
}
}