Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2008-12-18 16:58:02 -0500
committerDoug Schaefer2008-12-18 16:58:02 -0500
commited9ade92a23ebaaac7c625348488c79d38006be3 (patch)
tree265936db2e93773d2407b66798d27411ae3ea641 /p2/org.eclipse.cdt.p2
parent9a0bcfe2c6623508f020ba62dd33c6e9e9dc1984 (diff)
downloadorg.eclipse.cdt-ed9ade92a23ebaaac7c625348488c79d38006be3.tar.gz
org.eclipse.cdt-ed9ade92a23ebaaac7c625348488c79d38006be3.tar.xz
org.eclipse.cdt-ed9ade92a23ebaaac7c625348488c79d38006be3.zip
Add zlib. General clean up. Set versions to 5.0.0 consistently.
Diffstat (limited to 'p2/org.eclipse.cdt.p2')
-rw-r--r--p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/InstallArtifactRepository.java4
-rw-r--r--p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/ZipExtractor.java76
2 files changed, 79 insertions, 1 deletions
diff --git a/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/InstallArtifactRepository.java b/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/InstallArtifactRepository.java
index 50ddd518c7..9c105aa88d 100644
--- a/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/InstallArtifactRepository.java
+++ b/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/InstallArtifactRepository.java
@@ -232,7 +232,9 @@ public class InstallArtifactRepository extends AbstractArtifactRepository {
PipedInputStream in = new PipedInputStream(out);
String compression = descriptor.getProperty(COMPRESSION);
if (ZIP_COMPRESSION.equals(compression)) {
- // TODO a zip extractor
+ ZipExtractor extractor = new ZipExtractor(in, installDir,
+ new FileListWriter(getFileListFile(descriptor.getArtifactKey().getId())));
+ extractor.start();
} else {
TarExtractor extractor = new TarExtractor(in, installDir,
new FileListWriter(getFileListFile(descriptor.getArtifactKey().getId())),
diff --git a/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/ZipExtractor.java b/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/ZipExtractor.java
new file mode 100644
index 0000000000..ef7d046343
--- /dev/null
+++ b/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/p2/internal/repo/artifact/ZipExtractor.java
@@ -0,0 +1,76 @@
+package org.eclipse.cdt.p2.internal.repo.artifact;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class ZipExtractor extends Thread {
+
+ private final InputStream in;
+ private final File installDir;
+ private final FileListWriter fileListWriter;
+
+ public ZipExtractor(InputStream in, File installDir, FileListWriter fileListWriter) {
+ this.in = in;
+ this.installDir = installDir;
+ this.fileListWriter = fileListWriter;
+ }
+
+ @Override
+ public void run() {
+ try {
+ ZipInputStream zipIn = new ZipInputStream(in);
+ for (ZipEntry zipEntry = zipIn.getNextEntry(); zipEntry != null; zipEntry = zipIn.getNextEntry()) {
+ File outFile = new File(installDir, zipEntry.getName());
+ if (zipEntry.isDirectory()) {
+ outFile.mkdirs();
+ } else {
+ if (outFile.exists())
+ outFile.delete();
+ else
+ outFile.getParentFile().mkdirs();
+ FileOutputStream outStream = new FileOutputStream(outFile);
+ copyStream(zipIn, false, outStream, true);
+ long lastModified = zipEntry.getTime();
+ outFile.setLastModified(lastModified);
+ fileListWriter.addFile(new InstalledFile(outFile, lastModified));
+ }
+ zipIn.closeEntry();
+ }
+ zipIn.close();
+ fileListWriter.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ private static int copyStream(InputStream in, boolean closeIn, OutputStream out, boolean closeOut) throws IOException {
+ try {
+ int written = 0;
+ byte[] buffer = new byte[1024];
+ int len;
+ while ((len = in.read(buffer)) != -1) {
+ out.write(buffer, 0, len);
+ written += len;
+ }
+ return written;
+ } finally {
+ try {
+ if (closeIn) {
+ in.close();
+ }
+ } finally {
+ if (closeOut) {
+ out.close();
+ }
+ }
+ }
+ }
+
+}

Back to the top