Android InputStream Unzip getZipFileList(InputStream is)

Here you can find the source of getZipFileList(InputStream is)

Description

get the file list in the inputstream data

Parameter

Parameter Description
is the inputstream data

Return

the file list contain in the inputstream. if the is is null return null

Declaration

public static List<String> getZipFileList(InputStream is) 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.InputStream;
import java.util.ArrayList;

import java.util.List;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    /**//from   w  ww .j  a  v  a  2  s. c om
     * get the files in the zip file.
     * 
     * @param fileName
     *            zip file name. is a full path for the file.
     * @return return a List contain the files in the zip file. if the file is
     *         not exists return null.
     */
    public static List<String> getZipFileList(String fileName) {
        try {
            return getZipFileList(new FileInputStream(new File(fileName)));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * get the file list in the inputstream data
     * 
     * @param is
     *            the inputstream data
     * @return the file list contain in the inputstream. if the is is null
     *         return null
     */
    public static List<String> getZipFileList(InputStream is) {
        List<String> ret = new ArrayList<String>();
        try {
            ZipInputStream in = new ZipInputStream(is);
            ZipEntry entry = null;
            while ((entry = in.getNextEntry()) != null) {
                ret.add(entry.getName());
            }
            return ret;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. decompress(InputStream is, OutputStream os)
  2. decompress(InputStream is, OutputStream os)
  3. uncompress(InputStream inputStream)
  4. unpackZip(Context context, String s, InputStream is)
  5. readEntryAsWhatEverInternal( final ZipEntry entry, final InputStream unzippedInputStream)
  6. extZipFile(InputStream is, String extPlace)
  7. decompressFile(File destFile, ZipInputStream zis)