home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / JarEntrySource.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  1.5 KB  |  79 lines

  1. package sun.beanbox;
  2.  
  3. /**
  4.  * Used to request creating Jars
  5.  */
  6.  
  7. import java.io.InputStream;
  8. import java.io.FileInputStream;
  9. import java.io.File;
  10.  
  11. public class JarEntrySource {
  12.     public JarEntrySource(File file) {
  13.     this.markOnly = false;
  14.     this.name = file.getPath().replace(File.separatorChar, '/');
  15.     this.file = file;
  16.     }
  17.  
  18.     public JarEntrySource(String name, File file) {
  19.     this.markOnly = false;
  20.     this.name = name;
  21.     this.file = file;
  22.     }
  23.  
  24.     public JarEntrySource(String name, InputStream is) {
  25.     this.markOnly = false;
  26.     this.name = name;
  27.     this.is = is;
  28.     }
  29.  
  30.     public JarEntrySource(String name) {
  31.     this.markOnly = true;
  32.     this.name = name;
  33.     }
  34.     /**
  35.      * Accessors
  36.      */
  37.     public boolean isMarkOnly() {
  38.     return markOnly;
  39.     }
  40.  
  41.     public long getTime() {
  42.     if (file != null) {
  43.         return file.lastModified();
  44.     } else {
  45.         return 0;        // ??
  46.     }
  47.     }
  48.  
  49.     public long getLength() {
  50.     if (file != null) {
  51.         return file.length();
  52.     } else {
  53.         return 0;        // ??
  54.     }
  55.     }
  56.  
  57.     public String getName() {
  58.     return name;
  59.     }
  60.  
  61.     public InputStream getInputStream() {
  62.     if (file != null) {
  63.         try {
  64.         return new FileInputStream(file);
  65.         } catch (Exception ex) {
  66.         return null;
  67.         }
  68.     } else {
  69.         return is;
  70.     }
  71.     }
  72.  
  73.     private boolean markOnly;    // only mark in the ZIP
  74.     private String name;    // the name of this entry
  75.     private InputStream is;    // the input stream for the entry
  76.     private File file;        // if a file
  77.     private long modifiedTime;    // if an inputstream
  78. }
  79.