use of java.util.zip.ZipEntry in project che by eclipse.
the class JavaNavigation method getContent.
public ClassContent getContent(IJavaProject project, int rootId, String path) throws CoreException {
IPackageFragmentRoot root = getPackageFragmentRoot(project, rootId);
if (root == null) {
return null;
}
if (path.startsWith("/")) {
//non java file
if (root instanceof JarPackageFragmentRoot) {
JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
ZipFile jar = null;
try {
jar = jarPackageFragmentRoot.getJar();
ZipEntry entry = jar.getEntry(path.substring(1));
if (entry != null) {
try (InputStream stream = jar.getInputStream(entry)) {
return createContent(IoUtil.readStream(stream), false);
} catch (IOException e) {
LOG.error("Can't read file content: " + entry.getName(), e);
}
}
} finally {
if (jar != null) {
JavaModelManager.getJavaModelManager().closeZipFile(jar);
}
}
}
Object[] resources = root.getNonJavaResources();
for (Object resource : resources) {
if (resource instanceof JarEntryFile) {
JarEntryFile file = (JarEntryFile) resource;
if (file.getFullPath().toOSString().equals(path)) {
return readFileContent(file);
}
}
if (resource instanceof JarEntryDirectory) {
JarEntryDirectory directory = (JarEntryDirectory) resource;
JarEntryFile file = findJarFile(directory, path);
if (file != null) {
return readFileContent(file);
}
}
}
} else {
return getContent(project, path);
}
return null;
}
use of java.util.zip.ZipEntry in project jetty.project by eclipse.
the class WarURLConnection method substitueManifest.
/**
* Use PipedOuputStream and PipedInputStream to do the transformation without making
* a new temporary file ust to replace the manifest.
* @param newmanifest The new manifest
* @param rawIn The file input stream or equivalent. not the jar input stream.
*/
public static InputStream substitueManifest(final Manifest newmanifest, final InputStream rawIn) throws IOException {
final PipedOutputStream pOut = new PipedOutputStream();
PipedInputStream pIn = new PipedInputStream(pOut);
Runnable run = new Runnable() {
public void run() {
JarInputStream jin = null;
JarOutputStream dest = null;
try {
jin = new JarInputStream(rawIn, false);
dest = new JarOutputStream(pOut, newmanifest);
ZipEntry next = jin.getNextEntry();
while (next != null) {
if (next.getName().equalsIgnoreCase(JarFile.MANIFEST_NAME)) {
continue;
}
dest.putNextEntry(next);
if (next.getSize() > 0) {
IO.copy(jin, dest, next.getSize());
}
next = jin.getNextJarEntry();
}
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (dest != null)
IO.close(dest);
if (jin != null)
IO.close(jin);
IO.close(pOut);
}
}
};
Thread th = new Thread(run);
th.start();
return pIn;
}
use of java.util.zip.ZipEntry in project buck by facebook.
the class DexJarAnalysisStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
try (ZipFile zf = new ZipFile(filesystem.resolve(dexPath).toFile())) {
ZipEntry classesDexEntry = zf.getEntry("classes.dex");
if (classesDexEntry == null) {
throw new RuntimeException("could not find classes.dex in jar");
}
long uncompressedSize = classesDexEntry.getSize();
if (uncompressedSize == -1) {
throw new RuntimeException("classes.dex size should be known");
}
filesystem.writeContentsToPath(String.format("jar:%s dex:%s", filesystem.getFileSize(dexPath), uncompressedSize), dexMetaPath);
return StepExecutionResult.SUCCESS;
} catch (IOException e) {
context.logError(e, "There was an error in smart dexing step.");
return StepExecutionResult.ERROR;
}
}
use of java.util.zip.ZipEntry in project buck by facebook.
the class HashingDeterministicJarWriter method putEntry.
private void putEntry(ZipOutputStream jar, String fileName) throws IOException {
ZipEntry entry = new ZipEntry(fileName);
// We want deterministic JARs, so avoid mtimes.
entry.setTime(ZipConstants.getFakeTime());
jar.putNextEntry(entry);
}
use of java.util.zip.ZipEntry in project buck by facebook.
the class JarDirectoryStepHelper method createManifest.
private static Manifest createManifest(ProjectFilesystem filesystem, ImmutableSortedSet<Path> entriesToJar, Optional<String> mainClass, Optional<Path> manifestFile, boolean mergeManifests) throws IOException {
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
if (mergeManifests) {
for (Path entry : entriesToJar) {
entry = filesystem.getPathForRelativePath(entry);
Manifest readManifest;
if (Files.isDirectory(entry)) {
Path manifestPath = entry.resolve(JarFile.MANIFEST_NAME);
if (!Files.exists(manifestPath)) {
continue;
}
try (InputStream inputStream = Files.newInputStream(manifestPath)) {
readManifest = new Manifest(inputStream);
}
} else {
// Assume a zip or jar file.
try (ZipFile zipFile = new ZipFile(entry.toFile())) {
ZipEntry manifestEntry = zipFile.getEntry(JarFile.MANIFEST_NAME);
if (manifestEntry == null) {
continue;
}
try (InputStream inputStream = zipFile.getInputStream(manifestEntry)) {
readManifest = new Manifest(inputStream);
}
}
}
merge(manifest, readManifest);
}
}
// so that values from the user overwrite values from merged manifests.
if (manifestFile.isPresent()) {
Path path = filesystem.getPathForRelativePath(manifestFile.get());
try (InputStream stream = Files.newInputStream(path)) {
Manifest readManifest = new Manifest(stream);
merge(manifest, readManifest);
}
}
// We may have merged manifests and over-written the user-supplied main class. Add it back.
if (mainClass.isPresent()) {
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, mainClass.get());
}
return manifest;
}
Aggregations