Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.util.*;
import java.io.*;

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

public class Main {
    /**
     * 
     * @param file
     *            zip file
     * @return
     * @throws ZipException
     * @throws IOException
     */
    public static List<ZipEntry> loadFiles(File file) throws ZipException, IOException {
        return loadFiles(file, "");
    }

    /**
     * 
     * @param zipFile
     *            zip file
     * @param folderName
     *            folder to load
     * @return list of entry in the folder
     * @throws ZipException
     * @throws IOException
     */
    public static List<ZipEntry> loadFiles(File zipFile, String folderName) throws ZipException, IOException {
        Log.d("loadFiles", folderName);
        long start = System.currentTimeMillis();
        FileInputStream fis = new FileInputStream(zipFile);
        BufferedInputStream bis = new BufferedInputStream(fis);
        ZipInputStream zis = new ZipInputStream(bis);

        ZipEntry zipEntry = null;
        List<ZipEntry> list = new LinkedList<ZipEntry>();
        String folderLowerCase = folderName.toLowerCase();
        int counter = 0;
        while ((zipEntry = zis.getNextEntry()) != null) {
            counter++;
            String zipEntryName = zipEntry.getName();
            Log.d("loadFiles.zipEntry.getName()", zipEntryName);
            if (zipEntryName.toLowerCase().startsWith(folderLowerCase) && !zipEntry.isDirectory()) {
                list.add(zipEntry);
            }
        }
        Log.d("Loaded 1", counter + " files, took: " + (System.currentTimeMillis() - start) + " milliseconds.");
        zis.close();
        bis.close();
        fis.close();
        return list;
    }

    public static void close(Closeable closable) {
        if (closable != null) {
            try {
                closable.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}