net.sf.freecol.common.io
Class FreeColDataFile

java.lang.Object
  extended by net.sf.freecol.common.io.FreeColDataFile
Direct Known Subclasses:
FreeColModFile, FreeColSavegameFile

public class FreeColDataFile
extends java.lang.Object

Support for reading a FreeCol data file. The data file is either a ZIP-file or a directory containing certain files.


Field Summary
private  java.io.File file
          The file this object represents.
private  java.lang.String jarDirectory
          A prefix string for the jar-entries (only if file is a ZIP-file).
private static java.util.logging.Logger logger
           
private static java.lang.String RESOURCES_PROPERTIES_FILE
           
 
Constructor Summary
FreeColDataFile(java.io.File file)
          Opens the given file for reading.
 
Method Summary
private static java.lang.String findJarDirectory(java.lang.String expectedName, java.io.File file)
          Finds the directory within the zip-file in case the data file has been renamed.
protected  java.lang.String[] getFileEndings()
          File endings that are supported for this type of data file.
 java.io.FileFilter getFileFilter()
          Returns a FileFilter.
protected  java.io.InputStream getInputStream(java.lang.String filename)
          Returns an input stream for the specified resource.
 ResourceMapping getResourceMapping()
          Creates a ResourceMapping from the file "resources.properties".
protected  java.net.URI getURI(java.lang.String filename)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

RESOURCES_PROPERTIES_FILE

private static final java.lang.String RESOURCES_PROPERTIES_FILE
See Also:
Constant Field Values

file

private final java.io.File file
The file this object represents.


jarDirectory

private final java.lang.String jarDirectory
A prefix string for the jar-entries (only if file is a ZIP-file).

Constructor Detail

FreeColDataFile

public FreeColDataFile(java.io.File file)
Opens the given file for reading.

Parameters:
file - The file to be read.
Method Detail

findJarDirectory

private static java.lang.String findJarDirectory(java.lang.String expectedName,
                                                 java.io.File file)
Finds the directory within the zip-file in case the data file has been renamed.

Parameters:
expectedName - The name the directory should have.
file - The zip-file.
Returns:
The name of the base directory in the zip-file.

getInputStream

protected java.io.InputStream getInputStream(java.lang.String filename)
                                      throws java.io.IOException
Returns an input stream for the specified resource.

Parameters:
filename - The filename of a resource within this collection of data. If this object represents a directory then the provided filename should be relative towards the path of the directory. In case of a compressed archieve it should be the path within the archive.
Returns:
an InputStream value
Throws:
java.io.IOException - if an error occurs

getURI

protected java.net.URI getURI(java.lang.String filename)

getResourceMapping

public ResourceMapping getResourceMapping()
Creates a ResourceMapping from the file "resources.properties".

Returns:
A ResourceMapping or null there is no resource mapping file.

getFileFilter

public java.io.FileFilter getFileFilter()
Returns a FileFilter.

Returns:
The FileFilter.

getFileEndings

protected java.lang.String[] getFileEndings()
File endings that are supported for this type of data file.

Returns:
An array with a single element: ".zip".