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