Java Resource Load getResourcesFromZip(final byte[] barContent)

Here you can find the source of getResourcesFromZip(final byte[] barContent)

Description

get Resources From Zip

License

Open Source License

Declaration

public static Map<String, byte[]> getResourcesFromZip(final byte[] barContent) throws IOException 

Method Source Code

//package com.java2s;
/**/*from ww w. j ava2s .  c  o  m*/
 * Copyright (C) 2011 BonitaSoft S.A.
 * BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
 * 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 2.0 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.ByteArrayOutputStream;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static Map<String, byte[]> getResourcesFromZip(final byte[] barContent) throws IOException {
        final Map<String, byte[]> resources = new HashMap<String, byte[]>();
        final InputStream in = new ByteArrayInputStream(barContent);
        final ZipInputStream zis = new ZipInputStream(in);

        ZipEntry zipEntry = null;
        while ((zipEntry = zis.getNextEntry()) != null) {
            if (!zipEntry.isDirectory()) {
                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                int c;
                final byte[] buffer = new byte[512];
                while ((c = zis.read(buffer)) != -1) {
                    baos.write(buffer, 0, c);
                }
                baos.flush();
                resources.put(zipEntry.getName(), baos.toByteArray());
                baos.close();
            }
        }
        zis.close();
        in.close();
        return resources;
    }
}

Related

  1. getResourceScripts(String path)
  2. getResourcesFromDirectory(File directory)
  3. getResourcesFromDirectory(final File directory, final Pattern pattern)
  4. getResourcesFromJarFile(File file, String resName)
  5. getResourcesFromJarFile(final File file, final Pattern pattern)
  6. getResourceSize(ClassLoader classLoader, String path)
  7. getResourceStream(Class clazz, String resourceName)
  8. getResourceStream(final String resource)
  9. getResourceStream(String className, ClassLoader classLoader)