use of java.util.zip.ZipFile in project libgdx by libgdx.
the class JniGenSharedLibraryLoader method getFromJar.
private InputStream getFromJar(String jarFile, String sharedLibrary) throws IOException {
ZipFile file = new ZipFile(nativesJar);
ZipEntry entry = file.getEntry(sharedLibrary);
return file.getInputStream(entry);
}
use of java.util.zip.ZipFile in project android-classyshark by google.
the class AndroidXmlTranslator method apply.
@Override
public void apply() {
InputStream is = null;
ZipFile zip = null;
ByteArrayOutputStream bout = null;
try {
long size;
if (archiveFile.getName().endsWith(".apk") || archiveFile.getName().endsWith(".zip") || archiveFile.getName().endsWith(".aar")) {
zip = new ZipFile(archiveFile);
ZipEntry mft = zip.getEntry(xmlName);
size = mft.getSize();
is = zip.getInputStream(mft);
} else {
size = archiveFile.length();
is = new FileInputStream(archiveFile);
}
if (size > Integer.MAX_VALUE) {
throw new IOException("File larger than " + Integer.MAX_VALUE + " bytes not supported");
}
bout = new ByteArrayOutputStream((int) size);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(buffer)) > 0) {
bout.write(buffer, 0, bytesRead);
}
if (archiveFile.getName().endsWith(".aar")) {
this.xml = bout.toString();
} else {
this.xml = xmlDecompressor.decompressXml(bout.toByteArray());
}
} catch (Exception e) {
System.err.println("Error reading AndroidManifext.xml " + e.getMessage());
e.printStackTrace(System.err);
} finally {
closeResource(is);
closeResource(zip);
closeResource(bout);
}
}
use of java.util.zip.ZipFile in project buck by facebook.
the class ClassPathOpener method processArchive.
/**
* Processes the contents of an archive ({@code .zip},
* {@code .jar}, or {@code .apk}).
*
* @param file {@code non-null;} archive file to process
* @return whether any processing actually happened
* @throws IOException on i/o problem
*/
private boolean processArchive(File file) throws IOException {
ZipFile zip = new ZipFile(file);
ArrayList<? extends java.util.zip.ZipEntry> entriesList = Collections.list(zip.entries());
if (sort) {
Collections.sort(entriesList, new Comparator<ZipEntry>() {
public int compare(ZipEntry a, ZipEntry b) {
return compareClassNames(a.getName(), b.getName());
}
});
}
consumer.onProcessArchiveStart(file);
ByteArrayOutputStream baos = new ByteArrayOutputStream(40000);
byte[] buf = new byte[20000];
boolean any = false;
for (ZipEntry one : entriesList) {
final boolean isDirectory = one.isDirectory();
String path = one.getName();
if (filter.accept(path)) {
final byte[] bytes;
if (!isDirectory) {
InputStream in = zip.getInputStream(one);
baos.reset();
int read;
while ((read = in.read(buf)) != -1) {
baos.write(buf, 0, read);
}
in.close();
bytes = baos.toByteArray();
} else {
bytes = new byte[0];
}
any |= consumer.processFileBytes(path, one.getTime(), bytes);
}
}
zip.close();
return any;
}
use of java.util.zip.ZipFile in project gephi by gephi.
the class LoadTask method run.
@Override
public void run() {
Progress.start(progressTicket);
Progress.setDisplayName(progressTicket, NbBundle.getMessage(LoadTask.class, "LoadTask.name"));
try {
ZipFile zip = null;
try {
zip = new ZipFile(file);
ProjectImpl project = readProject(zip);
if (project != null) {
// Enumerate workspaces
List<String> workspaceEntries = new ArrayList<>();
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
ZipEntry entry = e.nextElement();
if (entry.getName().matches("Workspace_[0-9]*_xml")) {
workspaceEntries.add(entry.getName());
}
}
// Get providers
Collection<WorkspacePersistenceProvider> providers = PersistenceProviderUtils.getPersistenceProviders();
//Setup progress
Progress.switchToDeterminate(progressTicket, (1 + providers.size()) * workspaceEntries.size());
// Read workspaces
for (String workspaceEntry : workspaceEntries) {
WorkspaceImpl workspace = readWorkspace(project, workspaceEntry, zip);
Progress.progress(progressTicket);
if (workspace != null) {
for (WorkspacePersistenceProvider provider : providers) {
if (provider instanceof WorkspaceXMLPersistenceProvider) {
readWorkspaceChildrenXML((WorkspaceXMLPersistenceProvider) provider, workspace, zip);
} else if (provider instanceof WorkspaceBytesPersistenceProvider) {
readWorkspaceChildrenBytes((WorkspaceBytesPersistenceProvider) provider, workspace, zip);
}
Progress.progress(progressTicket);
if (cancel) {
break;
}
}
}
if (cancel) {
break;
}
}
}
Progress.switchToIndeterminate(progressTicket);
//Add project
ProjectControllerImpl projectController = Lookup.getDefault().lookup(ProjectControllerImpl.class);
if (project != null && !cancel) {
if (!cancel) {
//Set current workspace
WorkspaceProviderImpl workspaces = project.getLookup().lookup(WorkspaceProviderImpl.class);
for (Workspace workspace : workspaces.getWorkspaces()) {
WorkspaceInformationImpl info = workspace.getLookup().lookup(WorkspaceInformationImpl.class);
if (info.isOpen()) {
workspaces.setCurrentWorkspace(workspace);
break;
}
}
// Open project
projectController.openProject(project);
}
}
} finally {
if (zip != null) {
zip.close();
}
}
} catch (Exception ex) {
if (ex instanceof GephiFormatException) {
throw (GephiFormatException) ex;
}
throw new GephiFormatException(GephiReader.class, ex);
}
Progress.finish(progressTicket);
}
use of java.util.zip.ZipFile in project jaggery by wso2.
the class JaggeryAppListener method isJaggeryApp.
/**
* check whether webapp is jaggery app or not
*
* @param context Context of the jaggery app
* @return boolean
*/
private boolean isJaggeryApp(Context context) {
Path appBase = getAppBase(context);
String path;
if (context.getDocBase().contains(WAR_EXTENSION)) {
try {
if (!appBase.endsWith("/")) {
path = appBase + File.separator + context.getDocBase();
} else {
path = appBase + context.getDocBase();
}
ZipFile zip = new ZipFile(path);
for (Enumeration e = zip.entries(); e.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) e.nextElement();
if (entry.getName().toLowerCase().contains(JAGGERY_CONF)) {
return true;
}
}
} catch (IOException e) {
log.error("Error in processing the zip file", e);
}
} else {
Path filepath = Paths.get(appBase + context.getPath() + File.separator + JAGGERY_CONF);
return Files.exists(filepath);
}
return false;
}
Aggregations