hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r381803 - /lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java
Date Tue, 28 Feb 2006 22:44:06 GMT
Author: cutting
Date: Tue Feb 28 14:44:05 2006
New Revision: 381803

URL: http://svn.apache.org/viewcvs?rev=381803&view=rev
Log:
Fix to make independent of "unzip", using java's built in unzip code instead.

Modified:
    lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java?rev=381803&r1=381802&r2=381803&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java Tue Feb 28 14:44:05
2006
@@ -20,8 +20,10 @@
 import org.apache.hadoop.fs.*;
 
 import java.io.*;
+import java.util.jar.*;
 import java.util.logging.*;
 import java.util.Vector;
+import java.util.Enumeration;
 
 /** Base class that runs a task in a separate process.  Tasks are run in a
  * separate process in order to isolate the map/reduce system code from bugs in
@@ -77,7 +79,7 @@
       JobConf job = new JobConf(t.getJobFile());
       String jar = job.getJar();
       if (jar != null) {                      // if jar exists, it into workDir
-        runChild(new String[] { "unzip", "-o", "-q", jar}, workDir);
+        unJar(new File(jar), workDir);
         File[] libs = new File(workDir, "lib").listFiles();
         if (libs != null) {
           for (int i = 0; i < libs.length; i++) {
@@ -219,6 +221,37 @@
         
     }
     return text;
+  }
+
+  private void unJar(File jarFile, File toDir) throws IOException {
+    JarFile jar = new JarFile(jarFile);
+    try {
+      Enumeration entries = jar.entries();
+      while (entries.hasMoreElements()) {
+        JarEntry entry = (JarEntry)entries.nextElement();
+        if (!entry.isDirectory()) {
+          InputStream in = jar.getInputStream(entry);
+          try {
+            File file = new File(toDir, entry.getName());
+            file.getParentFile().mkdirs();
+            OutputStream out = new FileOutputStream(file);
+            try {
+              byte[] buffer = new byte[8192];
+              int i;
+              while ((i = in.read(buffer)) != -1) {
+                out.write(buffer, 0, i);
+              }
+            } finally {
+              out.close();
+            }
+          } finally {
+            in.close();
+          }
+        }
+      }
+    } finally {
+      jar.close();
+    }
   }
 
   /**



Mime
View raw message