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();
}
}
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();
}
}
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);
}
}
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);
}
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;
}
Aggregations