Search in sources :

Example 21 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 22 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 23 with ZipException

use of java.util.zip.ZipException in project jdk8u_jdk by JetBrains.

the class ZipFileSystem method deleteFile.

public void deleteFile(byte[] path, boolean failIfNotExists) throws IOException {
    checkWritable();
    IndexNode inode = getInode(path);
    if (inode == null) {
        if (path != null && path.length == 0)
            throw new ZipException("root directory </> can't not be delete");
        if (failIfNotExists)
            throw new NoSuchFileException(getString(path));
    } else {
        if (inode.isDir() && inode.child != null)
            throw new DirectoryNotEmptyException(getString(path));
        updateDelete(inode);
    }
}
Also used : ZipException(java.util.zip.ZipException)

Example 24 with ZipException

use of java.util.zip.ZipException in project jdk8u_jdk by JetBrains.

the class ZipFileSystem method getDataPos.

private long getDataPos(Entry e) throws IOException {
    if (e.locoff == -1) {
        Entry e2 = getEntry0(e.name);
        if (e2 == null)
            throw new ZipException("invalid loc for entry <" + e.name + ">");
        e.locoff = e2.locoff;
    }
    byte[] buf = new byte[LOCHDR];
    if (readFullyAt(buf, 0, buf.length, e.locoff) != buf.length)
        throw new ZipException("invalid loc for entry <" + e.name + ">");
    return locpos + e.locoff + LOCHDR + LOCNAM(buf) + LOCEXT(buf);
}
Also used : ZipException(java.util.zip.ZipException)

Example 25 with ZipException

use of java.util.zip.ZipException in project jdk8u_jdk by JetBrains.

the class ZipFileSystem method copyLOCEntry.

// copy over the whole LOC entry (header if necessary, data and ext) from
// old zip to the new one.
private long copyLOCEntry(Entry e, boolean updateHeader, OutputStream os, long written, byte[] buf) throws IOException {
    // where to read
    long locoff = e.locoff;
    // update the e.locoff with new value
    e.locoff = written;
    // calculate the size need to write out
    long size = 0;
    //  if there is A ext
    if ((e.flag & FLAG_DATADESCR) != 0) {
        if (e.size >= ZIP64_MINVAL || e.csize >= ZIP64_MINVAL)
            size = 24;
        else
            size = 16;
    }
    // read loc, use the original loc.elen/nlen
    if (readFullyAt(buf, 0, LOCHDR, locoff) != LOCHDR)
        throw new ZipException("loc: reading failed");
    if (updateHeader) {
        // skip header
        locoff += LOCHDR + LOCNAM(buf) + LOCEXT(buf);
        size += e.csize;
        written = e.writeLOC(os) + size;
    } else {
        // write out the loc header
        os.write(buf, 0, LOCHDR);
        locoff += LOCHDR;
        // use e.csize,  LOCSIZ(buf) is zero if FLAG_DATADESCR is on
        // size += LOCNAM(buf) + LOCEXT(buf) + LOCSIZ(buf);
        size += LOCNAM(buf) + LOCEXT(buf) + e.csize;
        written = LOCHDR + size;
    }
    int n;
    while (size > 0 && (n = (int) readFullyAt(buf, 0, buf.length, locoff)) != -1) {
        if (size < n)
            n = (int) size;
        os.write(buf, 0, n);
        size -= n;
        locoff += n;
    }
    return written;
}
Also used : ZipException(java.util.zip.ZipException)

Aggregations

ZipException (java.util.zip.ZipException)188 IOException (java.io.IOException)89 File (java.io.File)71 ZipEntry (java.util.zip.ZipEntry)66 ZipFile (java.util.zip.ZipFile)62 InputStream (java.io.InputStream)45 FileInputStream (java.io.FileInputStream)37 ZipInputStream (java.util.zip.ZipInputStream)26 BufferedInputStream (java.io.BufferedInputStream)22 FileOutputStream (java.io.FileOutputStream)21 JarFile (java.util.jar.JarFile)21 JarEntry (java.util.jar.JarEntry)19 FileNotFoundException (java.io.FileNotFoundException)18 ArrayList (java.util.ArrayList)17 ZipOutputStream (java.util.zip.ZipOutputStream)15 URL (java.net.URL)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 GZIPInputStream (java.util.zip.GZIPInputStream)10 BufferedOutputStream (java.io.BufferedOutputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7