fullRuntime/src/sc/util/FileUtil.java
public static boolean unzipJava(String zipFile, String resName) {
      File resDir = new File(resName);
      if (resDir.canRead() || resDir.isDirectory()) {
         System.err.println("*** unzip - res dir: " + resName + " exists");
         return false;
      }
      try {
         ZipFile zf = new ZipFile(zipFile);
         Enumeration<? extends ZipEntry> zfe = zf.entries();

         while (zfe.hasMoreElements()) {
            ZipEntry ze = zfe.nextElement();
            String fileRelName = ze.getName();
            String fileAbsName = FileUtil.concat(resName, fileRelName);

            File f = new File(fileAbsName);
            File destParent = f.getParentFile();
            destParent.mkdirs();
            byte[] extra = ze.getExtra();
            int unixFileMode = ExtraFieldUtils.getUnixFileMode(extra);
            if (!ze.isDirectory()) {
               BufferedInputStream is = new BufferedInputStream(zf.getInputStream(ze));
               int bytesRead;
               byte[] data = new byte[BUFFER_SIZE];

               FileOutputStream fos = new FileOutputStream(fileAbsName);
               BufferedOutputStream dst = new BufferedOutputStream(fos, BUFFER_SIZE);

               try {
                  while ((bytesRead = is.read(data, 0, BUFFER_SIZE)) != -1) {
                     dst.write(data, 0, bytesRead);
                  }
                  dst.flush();
               }
               finally {
                  try { dst.close(); } catch (IOException exc) {}
                  try { is.close(); } catch (IOException exc) {}
               }
               if ((unixFileMode & 0111) != 0) {
                  f.setExecutable(true, true);
               }
               if ((unixFileMode & 0444) != 0 && (unixFileMode & 0222) == 0) {
                  f.setReadOnly();
               }
            }
            else
               f.mkdirs();
         }
         return true;
      }
      catch (IOException exc) {
         System.err.println("*** can't read zip file: " + zipFile + ": " + exc);
         return false;
      }
   }
/**
    * TODO: remove this and the zip package?  This does not preserve the execute permissions... I have not found where
    * that metadata exists in the zip file.  There are supposedly two "extra" data sections one in the header and one in the
    * entry itself and I have only found one of them in the Java apis.  I carved out just a little of the apache code
    * that handles the extra data fields and that code seems to work so leaving this in for now in case it's useful in
    * the future.
    */
remove this and the zip package.  This does not preserve the execute permissions... I have not found where
that metadata exists in the zip file.  There are supposedly two "extra" data sections one in the header and one in the
entry itself and I have only found one of them in the Java apis.  I carved out just a little of the apache code
that handles the extra data fields and that code seems to work so leaving this in for now in case it's useful in
the future.
remove this and the zip package . This does not preserve the execute permissions ... I have not found where that metadata exists in the zip file . There are supposedly two " extra " data sections one in the header and one in the entry itself and I have only found one of them in the Java apis . I carved out just a little of the apache code that handles the extra data fields and that code seems to work so leaving this in for now in case it ' s useful in the future .
public static boolean unzipJava(String zipFile, String resName) {
      File resDir = new File(resName);
      if (resDir.canRead() || resDir.isDirectory()) {
         System.err.println("*** unzip - res dir: " + resName + " exists");
         return false;
      }
      try {
         ZipFile zf = new ZipFile(zipFile);
         Enumeration<? extends ZipEntry> zfe = zf.entries();
         while (zfe.hasMoreElements()) {
            ZipEntry ze = zfe.nextElement();
            String fileRelName = ze.getName();
            String fileAbsName = FileUtil.concat(resName, fileRelName);
            File f = new File(fileAbsName);
            File destParent = f.getParentFile();
            destParent.mkdirs();
            byte[] extra = ze.getExtra();
            int unixFileMode = ExtraFieldUtils.getUnixFileMode(extra);
            if (!ze.isDirectory()) {
               BufferedInputStream is = new BufferedInputStream(zf.getInputStream(ze));
               int bytesRead;
               byte[] data = new byte[BUFFER_SIZE];
               FileOutputStream fos = new FileOutputStream(fileAbsName);
               BufferedOutputStream dst = new BufferedOutputStream(fos, BUFFER_SIZE);
               try {
                  while ((bytesRead = is.read(data, 0, BUFFER_SIZE)) != -1) {
                     dst.write(data, 0, bytesRead);
                  }
                  dst.flush();
               }
               finally {
                  try { dst.close(); } catch (IOException exc) {}
                  try { is.close(); } catch (IOException exc) {}
               }
               if ((unixFileMode & 0111) != 0) {
                  f.setExecutable(true, true);
               }
               if ((unixFileMode & 0444) != 0 && (unixFileMode & 0222) == 0) {
                  f.setReadOnly();
               }
            }
            else
               f.mkdirs();
         }
         return true;
      }
      catch (IOException exc) {
         System.err.println("*** can't read zip file: " + zipFile + ": " + exc);
         return false;
      }
   }
public static boolean unzipJava ( String zipFile , String resName ) { File resDir = new File ( resName ) ; if ( resDir . canRead ( ) || resDir . isDirectory ( ) ) { System . err . println ( "*** unzip - res dir: " + resName + " exists" ) ; return false ; } try { ZipFile zf = new ZipFile ( zipFile ) ; Enumeration < ? extends ZipEntry > zfe = zf . entries ( ) ; while ( zfe . hasMoreElements ( ) ) { ZipEntry ze = zfe . nextElement ( ) ; String fileRelName = ze . getName ( ) ; String fileAbsName = FileUtil . concat ( resName , fileRelName ) ; File f = new File ( fileAbsName ) ; File destParent = f . getParentFile ( ) ; destParent . mkdirs ( ) ; byte [ ] extra = ze . getExtra ( ) ; int unixFileMode = ExtraFieldUtils . getUnixFileMode ( extra ) ; if ( ! ze . isDirectory ( ) ) { BufferedInputStream is = new BufferedInputStream ( zf . getInputStream ( ze ) ) ; int bytesRead ; byte [ ] data = new byte [ BUFFER_SIZE ] ; FileOutputStream fos = new FileOutputStream ( fileAbsName ) ; BufferedOutputStream dst = new BufferedOutputStream ( fos , BUFFER_SIZE ) ; try { while ( ( bytesRead = is . read ( data , 0 , BUFFER_SIZE ) ) != - 1 ) { dst . write ( data , 0 , bytesRead ) ; } dst . flush ( ) ; } finally { try { dst . close ( ) ; } catch ( IOException exc ) { } try { is . close ( ) ; } catch ( IOException exc ) { } } if ( ( unixFileMode & 0111 ) != 0 ) { f . setExecutable ( true , true ) ; } if ( ( unixFileMode & 0444 ) != 0 && ( unixFileMode & 0222 ) == 0 ) { f . setReadOnly ( ) ; } } else f . mkdirs ( ) ; } return true ; } catch ( IOException exc ) { System . err . println ( "*** can't read zip file: " + zipFile + ": " + exc ) ; return false ; } }
TODO: remove this and the zip package?
TODO : remove this and the zip package?