Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 *   Graph89 - Emulator for Android
 *  
 *    Copyright (C) 2012-2013  Dritan Hashorva
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
    
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

import java.io.ByteArrayInputStream;

import java.io.File;

import java.io.FileOutputStream;

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

public class Main {
    public static void Unzip(String dir, byte[] data) throws Exception {
        ByteArrayInputStream input = new ByteArrayInputStream(data);
        ZipInputStream zipIn = new ZipInputStream(input);
        ZipEntry entry;
        while ((entry = zipIn.getNextEntry()) != null) {
            String outpath = dir + entry.getName();
            FileOutputStream output = null;
            try {
                File f = new File(outpath);
                f.getParentFile().mkdirs();

                output = new FileOutputStream(f);
                int len = 0;
                byte[] buffer = new byte[4096];
                while ((len = zipIn.read(buffer)) > 0) {
                    output.write(buffer, 0, len);
                }
            } finally {
                if (output != null)
                    output.close();
            }
        }

        zipIn.close();
    }
}