Search in sources :

Example 86 with ZipException

use of java.util.zip.ZipException in project DiscLoader by R3alCl0ud.

the class ModContainer method handleAssets.

private void handleAssets() {
    ZipFile zip = null;
    try {
        try {
            zip = mod.getZipFile();
        } catch (ZipException e) {
            e.printStackTrace();
        }
        if (zip != null) {
            for (ZipEntry e : readEntries(zip.entries())) {
                if (!e.getName().startsWith("assets/" + modInfo.modid()))
                    continue;
                String name = e.getName().substring(("assets/" + modInfo.modid()).length() + 1);
                Resource r = new Resource(modInfo.modid(), name);
                ResourceManager.instance.addResource(r);
            }
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) Resource(io.discloader.discloader.client.render.util.Resource) ZipException(java.util.zip.ZipException) ZipException(java.util.zip.ZipException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 87 with ZipException

use of java.util.zip.ZipException in project DiscLoader by R3alCl0ud.

the class ZipReader method readZip.

public static void readZip(File zip) {
    ZipFile zipFile = null;
    try {
        try {
            zipFile = new ZipFile(zip);
        } catch (ZipException e) {
            e.printStackTrace();
        }
        if (zipFile != null) {
            // read zip file
            for (ZipEntry e : readEntries(zipFile.entries())) {
                if (e.getName().endsWith(".lang")) {
                    // the entry is a language file
                    InputStream is = zipFile.getInputStream(e);
                    Language lang = new Language(is, getLocale(e.getName()));
                    LanguageRegistry.registerLanguage(lang);
                } else if (e.getName().endsWith(".png")) {
                    // the entry is an icon
                    InputStream is = zipFile.getInputStream(e);
                    is.close();
                // TextureRegistry.resourceHandler.addResource(is, e);
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) Language(io.discloader.discloader.common.language.Language) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) IOException(java.io.IOException)

Example 88 with ZipException

use of java.util.zip.ZipException in project OsmAnd-tools by osmandapp.

the class IndexUploader method unzip.

private File unzip(File f) throws OneFileException {
    ZipFile zipFile = null;
    try {
        if (!Algorithms.isZipFile(f)) {
            return f;
        }
        log.info("Unzipping file: " + f.getName());
        zipFile = new ZipFile(f);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        long slastModified = f.lastModified();
        String folderName = f.getName().substring(0, f.getName().length() - 4);
        File unzipFolder = new File(f.getParentFile(), folderName);
        unzipFolder.mkdirs();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            long lastModified = slastModified;
            if (entry.isDirectory()) {
                continue;
            }
            if (entry.getTime() < lastModified) {
                lastModified = entry.getTime();
            }
            File tempFile = new File(unzipFolder, entry.getName());
            tempFile.getParentFile().mkdirs();
            InputStream zin = zipFile.getInputStream(entry);
            FileOutputStream out = new FileOutputStream(tempFile);
            Algorithms.streamCopy(zin, out);
            Algorithms.closeStream(zin);
            Algorithms.closeStream(out);
            tempFile.setLastModified(lastModified);
        }
        return unzipFolder;
    } catch (ZipException e) {
        throw new OneFileException("cannot unzip:" + e.getMessage(), e);
    } catch (IOException e) {
        throw new OneFileException("cannot unzip:" + e.getMessage(), e);
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException e) {
                throw new OneFileException("cannot unzip:" + e.getMessage(), e);
            }
        }
    }
}
Also used : ZipFile(java.util.zip.ZipFile) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 89 with ZipException

use of java.util.zip.ZipException in project pentaho-platform by pentaho.

the class ZipExportProcessor method exportDirectory.

/**
 * @param repositoryDir
 * @param outputStream
 */
@Override
public void exportDirectory(RepositoryFile repositoryDir, OutputStream outputStream, String filePath) throws ExportException, IOException {
    addToManifest(repositoryDir);
    List<RepositoryFile> children = getUnifiedRepository().getChildren(new RepositoryRequest(String.valueOf(repositoryDir.getId()), true, 1, null));
    for (RepositoryFile repositoryFile : children) {
        // exclude 'etc' folder - datasources and etc.
        if (isExportCandidate(repositoryFile.getPath())) {
            if (repositoryFile.isFolder()) {
                if (outputStream.getClass().isAssignableFrom(ZipOutputStream.class)) {
                    ZipOutputStream zos = (ZipOutputStream) outputStream;
                    String zipEntryName = getFixedZipEntryName(repositoryFile, filePath);
                    ZipEntry entry = new ZipEntry(zipEntryName);
                    zos.putNextEntry(entry);
                }
                exportDirectory(repositoryFile, outputStream, filePath);
            } else {
                try {
                    exportFile(repositoryFile, outputStream, filePath);
                } catch (ZipException e) {
                    // possible duplicate entry, log it and continue on with the other files in the directory
                    log.debug(e.getMessage(), e);
                }
            }
        }
    }
    createLocales(repositoryDir, filePath, repositoryDir.isFolder(), outputStream);
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) ZipException(java.util.zip.ZipException)

Example 90 with ZipException

use of java.util.zip.ZipException in project litiengine by gurkenlabs.

the class ResourceBundle method getResourceBundle.

private static ResourceBundle getResourceBundle(URL file) throws JAXBException, IOException {
    final JAXBContext jaxbContext = XmlUtilities.getContext(ResourceBundle.class);
    final Unmarshaller um = jaxbContext.createUnmarshaller();
    try (InputStream inputStream = Resources.get(file)) {
        // try to get compressed game file
        final GZIPInputStream zipStream = new GZIPInputStream(inputStream);
        return (ResourceBundle) um.unmarshal(zipStream);
    } catch (final ZipException e) {
        // if it fails to load the compressed file, get it from plain XML
        return XmlUtilities.read(ResourceBundle.class, file);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBContext(jakarta.xml.bind.JAXBContext) ZipException(java.util.zip.ZipException) Unmarshaller(jakarta.xml.bind.Unmarshaller)

Aggregations

ZipException (java.util.zip.ZipException)197 IOException (java.io.IOException)96 File (java.io.File)74 ZipEntry (java.util.zip.ZipEntry)67 ZipFile (java.util.zip.ZipFile)63 InputStream (java.io.InputStream)50 FileInputStream (java.io.FileInputStream)39 ZipInputStream (java.util.zip.ZipInputStream)26 FileOutputStream (java.io.FileOutputStream)23 BufferedInputStream (java.io.BufferedInputStream)22 JarFile (java.util.jar.JarFile)21 FileNotFoundException (java.io.FileNotFoundException)19 JarEntry (java.util.jar.JarEntry)19 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ZipOutputStream (java.util.zip.ZipOutputStream)15 URL (java.net.URL)14 GZIPInputStream (java.util.zip.GZIPInputStream)12 BufferedOutputStream (java.io.BufferedOutputStream)8 RandomAccessFile (java.io.RandomAccessFile)8