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.zip.*;

public class Main {
    public static byte[] readZipEntry(File zfile, ZipEntry entry) throws ZipException, IOException {
        Log.d("file3: ", zfile.toString());
        Log.d("zipEntry3: ", entry.toString());
        ZipFile zipFile = new ZipFile(zfile);
        if (entry != null && !entry.isDirectory()) {
            byte[] barr = new byte[(int) entry.getSize()];
            int read = 0;
            int len = 0;
            InputStream is = zipFile.getInputStream(entry);
            BufferedInputStream bis = new BufferedInputStream(is);
            int length = barr.length;
            while ((len = bis.read(barr, read, length - read)) != -1) {
                read += len;
            }
            bis.close();
            is.close();
            zipFile.close();
            return barr;
        } else {
            zipFile.close();
            return new byte[0];
        }
    }

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