View Javadoc
1   /*
2    * Created on 2005-maj-13
3    */
4   package net.sourceforge.jsh3modtool.modpackage;
5   
6   import java.io.File;
7   import java.io.FileInputStream;
8   import java.io.FileNotFoundException;
9   import java.io.IOException;
10  import java.io.InputStream;
11  
12  /***
13   * A file path package.
14   * The mod is stored in a normal folder, all files are unpacked.
15   * @author redsolo
16   */
17  public FolderModPackage implements ModPackage/package-summary.html">class FolderModPackage implements ModPackage
18  {
19      private File parentPath;
20  
21      publicFolderModPackage(File parentpath) throws IOException/package-summary.html">ong> FolderModPackage(File parentpath) throws IOException
22      {
23          if (parentpath == null)
24          {
25              throw new IllegalArgumentException("The folder path can not be null");
26          }
27          if (!parentpath.exists())
28          {
29              throw new FileNotFoundException(parentpath.toString());
30          }
31          parentPath = parentpath;
32      }
33  
34      public InputStream getEntry(String entryName) throws IOException
35      {
36          File fileEntry = getEntryAsFile(entryName);
37          return new FileInputStream(fileEntry);
38      }
39      
40      public boolean entryExists(String entryName)
41      {
42          return (getEntryAsFile(entryName).exists());
43      }
44  
45      /***
46       * Returns a File object pointing to the entry in the folder.
47       * @param entryName the name of entry 
48       * @return a File object pointing to the entry as a file.
49       */
50      private File getEntryAsFile(String entryName)
51      {
52          return new File(parentPath.getAbsolutePath() + File.separator + entryName);
53      }
54  }