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 static java.lang.String FILE_PREFIX
           
private static java.lang.String FILE_SUFFIX
           
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 resourceScheme
          A fake URI scheme for resources delegating to other resources.
 
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.
static java.util.List<java.lang.String> getFileNames(java.lang.String prefix, java.lang.String suffix, java.lang.String language, java.lang.String country, java.lang.String variant)
          Returns a list containing the names of all message files to load.
 java.io.BufferedInputStream getInputStream(java.lang.String filename)
          Returns an input stream for the specified resource.
 ResourceMapping getResourceMapping()
          Creates a ResourceMapping from the available resource files.
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

FILE_PREFIX

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

FILE_SUFFIX

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

resourceScheme

private static final java.lang.String resourceScheme
A fake URI scheme for resources delegating to other resources.

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.

getFileNames

public static java.util.List<java.lang.String> getFileNames(java.lang.String prefix,
                                                            java.lang.String suffix,
                                                            java.lang.String language,
                                                            java.lang.String country,
                                                            java.lang.String variant)
Returns a list containing the names of all message files to load.

Parameters:
prefix - a String value
suffix - a String value
language - a String value
country - a String value
variant - a String value
Returns:
a List value

getInputStream

public java.io.BufferedInputStream 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 archive 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 available resource files.

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".