Search in sources :

Example 36 with ZipFile

use of java.util.zip.ZipFile in project libgdx by libgdx.

the class JniGenSharedLibraryLoader method getFromJar.

private InputStream getFromJar(String jarFile, String sharedLibrary) throws IOException {
    ZipFile file = new ZipFile(nativesJar);
    ZipEntry entry = file.getEntry(sharedLibrary);
    return file.getInputStream(entry);
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry)

Example 37 with ZipFile

use of java.util.zip.ZipFile in project android-classyshark by google.

the class AndroidXmlTranslator method apply.

@Override
public void apply() {
    InputStream is = null;
    ZipFile zip = null;
    ByteArrayOutputStream bout = null;
    try {
        long size;
        if (archiveFile.getName().endsWith(".apk") || archiveFile.getName().endsWith(".zip") || archiveFile.getName().endsWith(".aar")) {
            zip = new ZipFile(archiveFile);
            ZipEntry mft = zip.getEntry(xmlName);
            size = mft.getSize();
            is = zip.getInputStream(mft);
        } else {
            size = archiveFile.length();
            is = new FileInputStream(archiveFile);
        }
        if (size > Integer.MAX_VALUE) {
            throw new IOException("File larger than " + Integer.MAX_VALUE + " bytes not supported");
        }
        bout = new ByteArrayOutputStream((int) size);
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) > 0) {
            bout.write(buffer, 0, bytesRead);
        }
        if (archiveFile.getName().endsWith(".aar")) {
            this.xml = bout.toString();
        } else {
            this.xml = xmlDecompressor.decompressXml(bout.toByteArray());
        }
    } catch (Exception e) {
        System.err.println("Error reading AndroidManifext.xml " + e.getMessage());
        e.printStackTrace(System.err);
    } finally {
        closeResource(is);
        closeResource(zip);
        closeResource(bout);
    }
}
Also used : ZipFile(java.util.zip.ZipFile) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 38 with ZipFile

use of java.util.zip.ZipFile in project buck by facebook.

the class ClassPathOpener method processArchive.

/**
     * Processes the contents of an archive ({@code .zip},
     * {@code .jar}, or {@code .apk}).
     *
     * @param file {@code non-null;} archive file to process
     * @return whether any processing actually happened
     * @throws IOException on i/o problem
     */
private boolean processArchive(File file) throws IOException {
    ZipFile zip = new ZipFile(file);
    ArrayList<? extends java.util.zip.ZipEntry> entriesList = Collections.list(zip.entries());
    if (sort) {
        Collections.sort(entriesList, new Comparator<ZipEntry>() {

            public int compare(ZipEntry a, ZipEntry b) {
                return compareClassNames(a.getName(), b.getName());
            }
        });
    }
    consumer.onProcessArchiveStart(file);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(40000);
    byte[] buf = new byte[20000];
    boolean any = false;
    for (ZipEntry one : entriesList) {
        final boolean isDirectory = one.isDirectory();
        String path = one.getName();
        if (filter.accept(path)) {
            final byte[] bytes;
            if (!isDirectory) {
                InputStream in = zip.getInputStream(one);
                baos.reset();
                int read;
                while ((read = in.read(buf)) != -1) {
                    baos.write(buf, 0, read);
                }
                in.close();
                bytes = baos.toByteArray();
            } else {
                bytes = new byte[0];
            }
            any |= consumer.processFileBytes(path, one.getTime(), bytes);
        }
    }
    zip.close();
    return any;
}
Also used : ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 39 with ZipFile

use of java.util.zip.ZipFile in project gephi by gephi.

the class LoadTask method run.

@Override
public void run() {
    Progress.start(progressTicket);
    Progress.setDisplayName(progressTicket, NbBundle.getMessage(LoadTask.class, "LoadTask.name"));
    try {
        ZipFile zip = null;
        try {
            zip = new ZipFile(file);
            ProjectImpl project = readProject(zip);
            if (project != null) {
                // Enumerate workspaces
                List<String> workspaceEntries = new ArrayList<>();
                for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
                    ZipEntry entry = e.nextElement();
                    if (entry.getName().matches("Workspace_[0-9]*_xml")) {
                        workspaceEntries.add(entry.getName());
                    }
                }
                // Get providers
                Collection<WorkspacePersistenceProvider> providers = PersistenceProviderUtils.getPersistenceProviders();
                //Setup progress
                Progress.switchToDeterminate(progressTicket, (1 + providers.size()) * workspaceEntries.size());
                // Read workspaces
                for (String workspaceEntry : workspaceEntries) {
                    WorkspaceImpl workspace = readWorkspace(project, workspaceEntry, zip);
                    Progress.progress(progressTicket);
                    if (workspace != null) {
                        for (WorkspacePersistenceProvider provider : providers) {
                            if (provider instanceof WorkspaceXMLPersistenceProvider) {
                                readWorkspaceChildrenXML((WorkspaceXMLPersistenceProvider) provider, workspace, zip);
                            } else if (provider instanceof WorkspaceBytesPersistenceProvider) {
                                readWorkspaceChildrenBytes((WorkspaceBytesPersistenceProvider) provider, workspace, zip);
                            }
                            Progress.progress(progressTicket);
                            if (cancel) {
                                break;
                            }
                        }
                    }
                    if (cancel) {
                        break;
                    }
                }
            }
            Progress.switchToIndeterminate(progressTicket);
            //Add project
            ProjectControllerImpl projectController = Lookup.getDefault().lookup(ProjectControllerImpl.class);
            if (project != null && !cancel) {
                if (!cancel) {
                    //Set current workspace
                    WorkspaceProviderImpl workspaces = project.getLookup().lookup(WorkspaceProviderImpl.class);
                    for (Workspace workspace : workspaces.getWorkspaces()) {
                        WorkspaceInformationImpl info = workspace.getLookup().lookup(WorkspaceInformationImpl.class);
                        if (info.isOpen()) {
                            workspaces.setCurrentWorkspace(workspace);
                            break;
                        }
                    }
                    // Open project
                    projectController.openProject(project);
                }
            }
        } finally {
            if (zip != null) {
                zip.close();
            }
        }
    } catch (Exception ex) {
        if (ex instanceof GephiFormatException) {
            throw (GephiFormatException) ex;
        }
        throw new GephiFormatException(GephiReader.class, ex);
    }
    Progress.finish(progressTicket);
}
Also used : ProjectControllerImpl(org.gephi.project.impl.ProjectControllerImpl) WorkspaceImpl(org.gephi.workspace.impl.WorkspaceImpl) WorkspaceProviderImpl(org.gephi.project.impl.WorkspaceProviderImpl) ProjectImpl(org.gephi.project.impl.ProjectImpl) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) WorkspacePersistenceProvider(org.gephi.project.spi.WorkspacePersistenceProvider) WorkspaceInformationImpl(org.gephi.workspace.impl.WorkspaceInformationImpl) XMLStreamException(javax.xml.stream.XMLStreamException) WorkspaceXMLPersistenceProvider(org.gephi.project.spi.WorkspaceXMLPersistenceProvider) ZipFile(java.util.zip.ZipFile) WorkspaceBytesPersistenceProvider(org.gephi.project.spi.WorkspaceBytesPersistenceProvider) Workspace(org.gephi.project.api.Workspace)

Example 40 with ZipFile

use of java.util.zip.ZipFile in project jaggery by wso2.

the class JaggeryAppListener method isJaggeryApp.

/**
     * check whether webapp is jaggery app or not
     *
     * @param context Context of the jaggery app
     * @return boolean
     */
private boolean isJaggeryApp(Context context) {
    Path appBase = getAppBase(context);
    String path;
    if (context.getDocBase().contains(WAR_EXTENSION)) {
        try {
            if (!appBase.endsWith("/")) {
                path = appBase + File.separator + context.getDocBase();
            } else {
                path = appBase + context.getDocBase();
            }
            ZipFile zip = new ZipFile(path);
            for (Enumeration e = zip.entries(); e.hasMoreElements(); ) {
                ZipEntry entry = (ZipEntry) e.nextElement();
                if (entry.getName().toLowerCase().contains(JAGGERY_CONF)) {
                    return true;
                }
            }
        } catch (IOException e) {
            log.error("Error in processing the zip file", e);
        }
    } else {
        Path filepath = Paths.get(appBase + context.getPath() + File.separator + JAGGERY_CONF);
        return Files.exists(filepath);
    }
    return false;
}
Also used : Path(java.nio.file.Path) Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Aggregations

ZipFile (java.util.zip.ZipFile)637 ZipEntry (java.util.zip.ZipEntry)454 File (java.io.File)287 IOException (java.io.IOException)214 InputStream (java.io.InputStream)147 FileOutputStream (java.io.FileOutputStream)108 ZipOutputStream (java.util.zip.ZipOutputStream)92 Test (org.junit.Test)89 FileInputStream (java.io.FileInputStream)68 Enumeration (java.util.Enumeration)47 ArrayList (java.util.ArrayList)46 BufferedInputStream (java.io.BufferedInputStream)44 BufferedOutputStream (java.io.BufferedOutputStream)39 ZipInputStream (java.util.zip.ZipInputStream)35 ZipException (java.util.zip.ZipException)34 OutputStream (java.io.OutputStream)31 ClassReader (org.objectweb.asm.ClassReader)29 FileNotFoundException (java.io.FileNotFoundException)26 JarFile (java.util.jar.JarFile)26 ByteArrayOutputStream (java.io.ByteArrayOutputStream)24