Example usage for java.util.zip ZipException printStackTrace

List of usage examples for java.util.zip ZipException printStackTrace

Introduction

In this page you can find the example usage for java.util.zip ZipException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.sead.repositories.reference.util.RefLocalContentProvider.java

@Override
public InputStream getInputStreamMatchingHash(String algorithm, String hash) {
    // If algorithm matches
    if (algorithm.equals(hashtype) && zf != null) {

        // Look up path based on hash
        if (hashToPathMap.containsKey(hash)) {

            String relPath = hashToPathMap.get(hash);
            log.trace("Retrieving stream for hash: " + hash + "from : " + relPath);

            try {
                ZipEntry archiveEntry1 = zf.getEntry(relPath);
                if (archiveEntry1 != null) {
                    return new BufferedInputStream(zf.getInputStream(archiveEntry1));
                }/*from  www  . j  av  a 2 s .  co  m*/

            } catch (ZipException e) {
                log.error(relPath + " : " + e.getLocalizedMessage());
                e.printStackTrace();
            } catch (IOException e) {
                log.error(relPath + " : " + e.getLocalizedMessage());
                e.printStackTrace();
            }
        }
    }

    return null;
}

From source file:drawnzer.anurag.archivereaddemo.RarFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    final ListView lsView = (ListView) view.findViewById(R.id.ls);
    lsView.setSelector(R.drawable.button_click);
    lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles()));

    lsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from w  ww .java2s  .  c  o m*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub

            if (opened) {
                //zip file already opened....
                //we are selecting sub files inside of zip file....

                //getting selected entry from list view....
                RarObj obj = (RarObj) lsView.getAdapter().getItem(arg2);

                //getting path of selected folder inside zip archive....
                rar_path = obj.getPath();

                if (obj.isFile()) {
                    // a files is selected inside of archive....
                    Toast.makeText(getActivity(), "A file is selected....", Toast.LENGTH_SHORT).show();
                } else {
                    //a folder is selected inside zip archive....
                    //so further listing the selected folder....

                    try {
                        lsView.setAdapter(read_rar.getAdapter(rar_path, getActivity()));
                    } catch (ZipException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show();
                    }
                }
                return;
            }

            //folder or some file is selected....
            //getting the file....
            File getFile = (File) lsView.getAdapter().getItem(arg2);

            if (getFile.isDirectory()) {
                //updating th path....
                path = path + "/" + getFile.getName();

                //updating the listview as per new path....
                lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles()));
            } else {
                //file is selected....
                if (getFile.getName().endsWith(".rar")) {
                    //open the zip file....
                    opened = true;
                    read_rar = new ReadArchive(getFile);

                    if (rar_path == null)
                        rar_path = "/";

                    try {
                        lsView.setAdapter(read_rar.getAdapter(rar_path, getActivity()));
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Invalid zip file....", Toast.LENGTH_SHORT).show();
                    }
                } else
                    Toast.makeText(getActivity(), "Choose a rar file to open....", Toast.LENGTH_SHORT).show();
            }
        }
    });
    lsView.setOnItemLongClickListener(null);
}

From source file:drawnzer.anurag.archivereaddemo.ZipFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    final ListView lsView = (ListView) view.findViewById(R.id.ls);
    lsView.setSelector(R.drawable.button_click);
    lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles()));

    lsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//  ww  w. j ava 2s.  com
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub

            if (opened) {
                //zip file already opened....
                //we are selecting sub files inside of zip file....

                //getting selected entry from list view....
                ZipObj obj = (ZipObj) lsView.getAdapter().getItem(arg2);

                //getting path of selected folder inside zip archive....
                zip_path = obj.getPath();

                if (obj.isFile()) {
                    // a files is selected inside of archive....
                    Toast.makeText(getActivity(), "A file is selected....", Toast.LENGTH_SHORT).show();
                } else {
                    //a folder is selected inside zip archive....
                    //so further listing the selected folder....

                    try {
                        lsView.setAdapter(read_zip.getAdapter(zip_path, getActivity()));
                    } catch (ZipException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show();
                    }
                }
                return;
            }

            //folder or some file is selected....
            //getting the file....
            File getFile = (File) lsView.getAdapter().getItem(arg2);

            if (getFile.isDirectory()) {
                //updating th path....
                path = path + "/" + getFile.getName();

                //updating the listview as per new path....
                lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles()));
            } else {
                //file is selected....
                if (getFile.getName().endsWith(".zip")) {
                    //open the zip file....
                    opened = true;
                    read_zip = new ReadArchive(getFile);

                    if (zip_path == null)
                        zip_path = "/";

                    try {
                        lsView.setAdapter(read_zip.getAdapter(zip_path, getActivity()));
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Invalid zip file....", Toast.LENGTH_SHORT).show();
                    }
                } else
                    Toast.makeText(getActivity(), "Choose a zip file to open....", Toast.LENGTH_SHORT).show();
            }
        }
    });
    lsView.setOnItemLongClickListener(null);
}

From source file:drawnzer.anurag.archivereaddemo.TarFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    final ListView lsView = (ListView) view.findViewById(R.id.ls);
    lsView.setSelector(R.drawable.button_click);
    lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles()));

    lsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/* w  w w  .j av a  2 s . com*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub

            if (opened) {
                //zip file already opened....
                //we are selecting sub files inside of zip file....

                //getting selected entry from list view....
                TarObj obj = (TarObj) lsView.getAdapter().getItem(arg2);

                //getting path of selected folder inside zip archive....
                tar_path = obj.getPath();

                if (obj.isFile()) {
                    // a files is selected inside of archive....
                    Toast.makeText(getActivity(), "A file is selected....", Toast.LENGTH_SHORT).show();
                } else {
                    //a folder is selected inside zip archive....
                    //so further listing the selected folder....

                    if (tar_path.startsWith("/"))
                        tar_path = tar_path.substring(1, tar_path.length());
                    try {
                        lsView.setAdapter(read_tar.getAdapter(tar_path, getActivity()));
                    } catch (ZipException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show();
                    }
                }
                return;
            }

            //folder or some file is selected....
            //getting the file....
            File getFile = (File) lsView.getAdapter().getItem(arg2);

            if (getFile.isDirectory()) {
                //updating th path....
                path = path + "/" + getFile.getName();

                //updating the listview as per new path....
                lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles()));
            } else {
                //file is selected....
                if (getFile.getName().endsWith(".tar") || getFile.getName().endsWith(".tar.bz2")) {
                    //open the zip file....
                    opened = true;
                    read_tar = new ReadArchive(getFile);

                    if (tar_path == null)
                        tar_path = "/";

                    try {
                        lsView.setAdapter(read_tar.getAdapter(tar_path, getActivity()));
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Invalid tar file....", Toast.LENGTH_SHORT).show();
                    }
                } else
                    Toast.makeText(getActivity(), "Choose a tar file to open....", Toast.LENGTH_SHORT).show();
            }
        }
    });
    lsView.setOnItemLongClickListener(null);
}

From source file:au.com.addstar.objects.Plugin.java

/**
 * Adds the Spigot.ver file to the jar/*  w  ww  .ja  v a  2  s.  co m*/
 *
 * @param ver
 */
public void addSpigotVer(String ver) {
    if (latestFile == null)
        return;
    File newFile = new File(latestFile.getParentFile(),
            SpigotUpdater.getFormat().format(Calendar.getInstance().getTime()) + "-" + ver + "-s.jar");
    File spigotFile = new File(latestFile.getParentFile(), "spigot.ver");
    if (spigotFile.exists())
        FileUtils.deleteQuietly(spigotFile);
    try {
        JarFile oldjar = new JarFile(latestFile);
        if (oldjar.getEntry("spigot.ver") != null)
            return;
        JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(newFile));
        try (Writer wr = new FileWriter(spigotFile); BufferedWriter writer = new BufferedWriter(wr)) {
            writer.write(ver);
            writer.newLine();
        }
        try (FileInputStream stream = new FileInputStream(spigotFile)) {
            byte[] buffer = new byte[1024];
            int bytesRead = 0;
            JarEntry je = new JarEntry(spigotFile.getName());
            tempJarOutputStream.putNextEntry(je);
            while ((bytesRead = stream.read(buffer)) != -1) {
                tempJarOutputStream.write(buffer, 0, bytesRead);
            }
            stream.close();
        }
        Enumeration jarEntries = oldjar.entries();
        while (jarEntries.hasMoreElements()) {
            JarEntry entry = (JarEntry) jarEntries.nextElement();
            InputStream entryInputStream = oldjar.getInputStream(entry);
            tempJarOutputStream.putNextEntry(entry);
            byte[] buffer = new byte[1024];
            int bytesRead = 0;
            while ((bytesRead = entryInputStream.read(buffer)) != -1) {
                tempJarOutputStream.write(buffer, 0, bytesRead);
            }
            entryInputStream.close();
        }
        tempJarOutputStream.close();
        oldjar.close();
        FileUtils.deleteQuietly(latestFile);
        FileUtils.deleteQuietly(spigotFile);
        FileUtils.moveFile(newFile, latestFile);
        latestFile = newFile;

    } catch (ZipException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.openflexo.foundation.cg.action.ImportDocumentationTemplates.java

/**
 * Overrides doAction/* www.j ava2s . co m*/
 * 
 * @see org.openflexo.foundation.action.FlexoAction#doAction(java.lang.Object)
 */
@Override
protected void doAction(Object context) throws FlexoException {
    makeFlexoProgress("importing_documentation_templates", 2);
    try {
        File documentationTemplateDirectory = FileUtils.createTempDirectory("DocumentTemplates", ".tmp");
        ZipUtils.unzip(zipFile, documentationTemplateDirectory, getFlexoProgress());
        Collection<File> tocFiles = org.apache.commons.io.FileUtils.listFiles(documentationTemplateDirectory,
                new String[] { "toc.xml" }, true);
        makeFlexoProgress("importing_documentation_templates", tocFiles.size());
        for (File tocfile : tocFiles) {
            importTemplatesFromDir(tocfile);
        }
    } catch (ZipException e) {
        e.printStackTrace();
        throw new ImportException(
                FlexoLocalization.localizedForKey("invalid_zip_file") + " (" + e.getMessage() + ")", e);
    } catch (IOException e) {
        e.printStackTrace();
        throw new ImportException(
                FlexoLocalization.localizedForKey("error_while_reading_file") + " (" + e.getMessage() + ")", e);
    } catch (InvalidXMLDataException e) {
        e.printStackTrace();
        throw new ImportException(
                FlexoLocalization.localizedForKey("invalid_xml_data") + " (" + e.getMessage() + ")", e);
    } catch (InvalidObjectSpecificationException e) {
        e.printStackTrace();
        throw new ImportException(
                FlexoLocalization.localizedForKey("invalid_object_specification") + " (" + e.getMessage() + ")",
                e);
    } catch (InvalidModelException e) {
        e.printStackTrace();
        throw new ImportException(
                FlexoLocalization.localizedForKey("invalid_model") + " (" + e.getMessage() + ")", e);
    } catch (AccessorInvocationException e) {
        e.printStackTrace();
        throw new ImportException(
                FlexoLocalization.localizedForKey("model_error") + " (" + e.getMessage() + ")", e);
    } catch (SAXException e) {
        e.printStackTrace();
        throw new ImportException(FlexoLocalization.localizedForKey("xml_error") + " (" + e.getMessage() + ")",
                e);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        throw new ImportException(FlexoLocalization.localizedForKey("parser_configuration_exception") + " ("
                + e.getMessage() + ")", e);
    } catch (JDOMException e) {
        e.printStackTrace();
        throw new ImportException(FlexoLocalization.localizedForKey("xml_error") + " (" + e.getMessage() + ")",
                e);
    }
}

From source file:org.opt4j.config.ModuleAutoFinder.java

/**
 * Returns {@code true} if the file is a Jar archive.
 * /*  w ww  .ja  v  a 2 s.c  o  m*/
 * @param file
 *            the tested file
 * @return {@code true} if the file is a Jar archive
 */
protected boolean isJar(File file) {
    if (file.isDirectory()) {
        return false;
    }

    try {
        ZipFile zf = new ZipFile(file);
        zf.close();
        return true;
    } catch (ZipException e) {

    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:org.spoutcraft.launcher.launch.MinecraftClassLoader.java

private Class<?> findClassInjar(String name, File file) throws ClassNotFoundException {
    byte classByte[];
    Class<?> result = null;
    JarFile jar = null;// w  w w. ja v  a 2s .c om
    try {
        jar = new JarFile(file);
        JarEntry entry = jar.getJarEntry(name.replace(".", "/") + ".class");
        if (entry != null) {
            InputStream is = jar.getInputStream(entry);
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
            int next = is.read();
            while (-1 != next) {
                byteStream.write(next);
                next = is.read();
            }

            classByte = byteStream.toByteArray();
            result = defineClass(name, classByte, 0, classByte.length,
                    new CodeSource(file.toURI().toURL(), (CodeSigner[]) null));
            loadedClasses.put(name, result);
            return result;
        }
    } catch (FileNotFoundException e) {
        // Assume temp file has been cleaned if the thread is interrupted
        if (!Thread.currentThread().isInterrupted()) {
            e.printStackTrace();
        }
    } catch (ZipException zipEx) {
        System.out.println("Failed to open " + name + " from " + file.getPath());
        zipEx.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            jar.close();
        } catch (IOException ignore) {
        }
    }
    return null;
}

From source file:com.pieframework.runtime.utils.azure.Cspack.java

private void stageStartupTasks(Role role, File roleDir) {

    File roleBin = null;/* ww w . j  av  a  2 s.  c o m*/
    if (role.getProps().get("type") != null) {
        if (role.getProps().get("type").equals("WebRole")) {
            roleBin = new File(roleDir.getPath() + File.separatorChar + "bin");
        } else if (role.getProps().get("type").equals("WorkerRole")) {
            roleBin = new File(roleDir.getPath() + File.separatorChar);
        }
    }

    //Locate startup tasks and copy payloads into roleDir payloads   
    for (String key : role.getChildren().keySet()) {

        if (role.getChildren().get(key) instanceof Service) {
            Service s = (Service) role.getChildren().get(key);
            if (s.getProps().get("type") != null && s.getProps().get("type").equalsIgnoreCase("bootstrap")) {

                roleBin.mkdir();
                String query = s.getProps().get("installer");
                if (query != null) {
                    String fQuery = s.getProps().get("installer");
                    String nQuery = ResourceLoader.getResourceName(fQuery);
                    String pQuery = ResourceLoader.getResourcePath(fQuery);
                    Files bootstrap = (Files) s.getResources().get(nQuery);
                    if (bootstrap != null) {
                        List<File> flist = ResourceLoader.findPath(bootstrap.getLocalPath(), pQuery);
                        if (flist.size() == 1 && flist.get(0).exists()
                                && FilenameUtils.isExtension(flist.get(0).getPath(), "zip")) {

                            try {
                                Zipper.unzip(flist.get(0).getPath(), roleBin.getPath());
                            } catch (ZipException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }

                }
            }
        }
    }
}

From source file:com.pieframework.runtime.utils.azure.Cspack.java

private void stageRoleBinaries(Role role, File roleDir) {
    File roleBin = null;//from w  w  w. ja va2 s  .  com
    if (role.getProps().get("type") != null) {
        roleBin = new File(roleDir.getPath() + File.separatorChar);
        roleBin.mkdir();

        if (roleBin != null) {
            for (String key : role.getChildren().keySet()) {

                if (role.getChildren().get(key) instanceof Service) {
                    Service s = (Service) role.getChildren().get(key);
                    if (s.getProps().get("type") != null
                            && s.getProps().get("type").equalsIgnoreCase("application")) {
                        String query = s.getProps().get("package");
                        if (query != null) {
                            String fQuery = s.getProps().get("package");
                            String nQuery = ResourceLoader.getResourceName(fQuery);
                            String pQuery = ResourceLoader.getResourcePath(fQuery);
                            Files bootstrap = (Files) s.getResources().get(nQuery);
                            if (bootstrap != null) {
                                List<File> flist = ResourceLoader.findPath(bootstrap.getLocalPath(), pQuery);
                                if (flist.size() == 1 && flist.get(0).exists()
                                        && FilenameUtils.isExtension(flist.get(0).getPath(), "zip")) {

                                    try {
                                        Zipper.unzip(flist.get(0).getPath(), roleBin.getPath());
                                        if (role.getProps().get("type").equals("WebRole")) {
                                            //Cleanup non-bin files
                                            for (File f : roleBin.listFiles()) {
                                                if (!f.getName().equalsIgnoreCase("bin")) {
                                                    FileUtils.forceDelete(f);
                                                }
                                            }

                                            //Move contents of bin dir into the current directory
                                            File binDir = new File(
                                                    roleBin.getPath() + File.separatorChar + "bin");
                                            if (binDir.exists()) {
                                                for (File f : binDir.listFiles()) {
                                                    if (f.isDirectory()) {
                                                        FileUtils.copyDirectory(f, roleBin);
                                                    } else {
                                                        FileUtils.copyFileToDirectory(f, roleBin);
                                                    }
                                                }
                                                FileUtils.forceDelete(binDir);
                                            }
                                        }
                                    } catch (ZipException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}