Changeset 10010


Ignore:
Timestamp:
2005-06-03T14:57:34+12:00 (19 years ago)
Author:
mdewsnip
Message:

Moved Utility.isInJar and Utility.extractFromJar into a new JarTools class (which will eventually blur all the differences between reading files locally and reading them out of the JAR file).

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/GathererApplet.java

    r9942 r10010  
    4141import org.greenstone.gatherer.feedback.ActionRecorderDialog;
    4242import org.greenstone.gatherer.gui.GUIManager;
     43import org.greenstone.gatherer.util.JarTools;
    4344import org.greenstone.gatherer.util.Utility;
    4445import org.greenstone.gatherer.shell.GShell;
     
    154155    if (!col_dir.exists()) {
    155156
    156         if (Utility.isInJar(Utility.COLLECT_ZIP)) {
     157        if (JarTools.isInJar(Utility.COLLECT_ZIP)) {
    157158        // Dig out collect.zip from JAR file and unzip it (thereby
    158159        // creating collect directory and descendants.
     
    182183        }
    183184
    184 
    185185    File metadata_directory = new File(Utility.METADATA_DIR);
    186186    if (!metadata_directory.exists()) {
     
    189189    }
    190190
    191    
    192191    File plug_dat = new File(Utility.BASE_DIR + "plugins.dat");
    193192    if (!plug_dat.exists()) {
    194         Utility.extractFromJar("plugins.dat",Utility.BASE_DIR,false);
     193        JarTools.extractFromJar("plugins.dat", Utility.BASE_DIR, false);
    195194    }
    196195
    197196    File class_dat = new File(Utility.BASE_DIR + "classifiers.dat");
    198197    if (!class_dat.exists()) {
    199         Utility.extractFromJar("classifiers.dat",Utility.BASE_DIR,false);
     198        JarTools.extractFromJar("classifiers.dat", Utility.BASE_DIR, false);
    200199    }
    201200   
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r10009 r10010  
    471471
    472472
    473     static public boolean isInJar(String filename)
    474     {
    475     try {
    476         InputStream fis = base.getResourceAsStream("/"+filename);
    477            
    478         fis.close();
    479 
    480     }
    481     catch (Exception error) {
    482         System.err.println("**** collect.zip not there!");
    483         error.printStackTrace();
    484 
    485 
    486         return false;
    487     }
    488     return true;
    489     }
    490 
    491 
    492 
    493     static public void extractFromJar(String filename, String dst_dir, boolean must_be_present)
    494     {
    495     try {
    496         // setup input stream for slurping out file
    497         InputStream fis = base.getResourceAsStream("/"+filename);
    498         BufferedInputStream fbis = new BufferedInputStream(fis);
    499         DataInputStream fdbis = new DataInputStream(fbis);
    500            
    501         // set up output stream for writing to disk
    502         String ofname = dst_dir + filename;
    503         FileOutputStream fos = new FileOutputStream(ofname);
    504         BufferedOutputStream bfos = new BufferedOutputStream(fos);
    505 
    506         byte[] buf = new byte[1024];
    507         int len;
    508         int total_bytes = 0;
    509         while ((len = fdbis.read(buf)) >= 0) {
    510         bfos.write(buf,0,len);
    511         total_bytes += len;
    512         }
    513 
    514         fdbis.close();
    515         bfos.close();
    516     }
    517     catch (Exception error) {
    518         if (must_be_present) {
    519         error.printStackTrace();
    520         }
    521     }
    522     }
    523 
    524 
    525473    /** Method which unzips a given metadata resoure
    526474     * @param zip_fname The name of the zip file as a <strong>String</strong>.
     
    535483    }
    536484
    537     extractFromJar(jar_zip_fname,dst_dir,true);
     485    JarTools.extractFromJar(jar_zip_fname,dst_dir,true);
    538486
    539487    String zip_ofname = dst_dir + jar_zip_fname;
Note: See TracChangeset for help on using the changeset viewer.