net.aerith.misao.io
Class FileManager

java.lang.Object
  |
  +--net.aerith.misao.io.FileManager

public class FileManager
extends java.lang.Object

The FileManager is a class which consists of static methods to search or copy files.


Field Summary
private  java.io.File home_directory
          The home directory.
 
Constructor Summary
FileManager()
          Constructs a FileManager.
FileManager(java.io.File directory)
          Constructs a FileManager at the specified directory.
 
Method Summary
static void copy(java.io.File src_file, java.io.File dst_file)
          Copies the file.
 Format createFileFormat(XmlImage image)
          Creates the image file format object.
static boolean endsWith(java.lang.String filename, java.lang.String extension)
          Checks if the specified file name ends with the specified extension.
static java.io.File find(java.io.File directory, java.io.File file)
          Searches the specified file of relative path from the specified directory.
 java.io.File newFile(java.lang.String path)
          Creates a new file object for the specified relative path in the home directory.
 XmlInformation readInformation(XmlMagRecord mag_record)
          Reads the XML information document recorded in the specified magnitude record.
 XmlInformation readInformation(XmlMagRecord mag_record, InformationDBManager db_manager)
          Reads the XML information document recorded in the specified magnitude record, from the XML report document file or specified information database.
 XmlReport readReport(XmlInformation info)
          Reads the XML report document recorded in the specified XML information element.
 XmlReport readReport(XmlInformation info, Coor coor, double radius)
          Reads the XML report document recorded in the specified XML information element with only star data around the specified R.A.
 XmlReport readReport(XmlMagRecord mag_record)
          Reads the XML report document recorded in the specified magnitude record.
 XmlStar readStar(XmlInformation info, java.lang.String name)
          Reads the star element in the XML report document with the specified name.
static java.lang.String relativatePathFrom(java.lang.String path, java.io.File file)
          Converts the absolute file path into the relative path from the specified file if possible.
static java.lang.String relativatePathFromDirectory(java.lang.String path, java.io.File directory)
          Converts the absolute file path into the relative path from the specified directory if possible.
static java.lang.String unitePath(java.lang.String path1, java.lang.String path2)
          Unites the two paths.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

home_directory

private java.io.File home_directory
The home directory.
Constructor Detail

FileManager

public FileManager()
Constructs a FileManager.

FileManager

public FileManager(java.io.File directory)
Constructs a FileManager at the specified directory.
Parameters:
directory - the home directory.
Method Detail

find

public static final java.io.File find(java.io.File directory,
                                      java.io.File file)
                               throws java.io.FileNotFoundException
Searches the specified file of relative path from the specified directory.
Parameters:
directory - the directory to search the file.
file - the file to search.
Returns:
the file object.
Throws:
java.io.FileNotFoundException - if the specified file cannot be found in the specified directory.

copy

public static final void copy(java.io.File src_file,
                              java.io.File dst_file)
                       throws java.io.IOException
Copies the file.
Parameters:
src_file - the file to copy from.
dst_file - the file to copy to.
Throws:
java.io.IOException - if a file cannot be accessed.

relativatePathFrom

public static final java.lang.String relativatePathFrom(java.lang.String path,
                                                        java.io.File file)
Converts the absolute file path into the relative path from the specified file if possible.
Parameters:
path - the absolute path.
file - the file to relativate the path from.
Returns:
the relativated path.

relativatePathFromDirectory

public static final java.lang.String relativatePathFromDirectory(java.lang.String path,
                                                                 java.io.File directory)
Converts the absolute file path into the relative path from the specified directory if possible.
Parameters:
path - the absolute path.
directory - the directory to relativate the path from.
Returns:
the relativated path.

unitePath

public static final java.lang.String unitePath(java.lang.String path1,
                                               java.lang.String path2)
Unites the two paths.
Parameters:
path1 - the first path.
path2 - the second path.
Returns:
the united path.

endsWith

public static final boolean endsWith(java.lang.String filename,
                                     java.lang.String extension)
Checks if the specified file name ends with the specified extension.
Parameters:
filename - the filename.
extension - the extension including the period.
Returns:
true if the specified file name ends with the specified extension.

newFile

public java.io.File newFile(java.lang.String path)
Creates a new file object for the specified relative path in the home directory.

If the file does not exists, it searches a file with ".gz" suffix, or a file without ".gz" suffix when it is already attached.

Parameters:
path - the path of a file.
Returns:
the file object.

readReport

public XmlReport readReport(XmlInformation info)
                     throws java.io.IOException
Reads the XML report document recorded in the specified XML information element.
Parameters:
info - the XML information element.
Returns:
the XML report document.
Throws:
java.io.IOException - if I/O error occurs.

readReport

public XmlReport readReport(XmlInformation info,
                            Coor coor,
                            double radius)
                     throws java.io.IOException
Reads the XML report document recorded in the specified XML information element with only star data around the specified R.A. and Decl.
Parameters:
info - the XML information element.
coor - the R.A. and Decl.
radius - the radius in degree.
Returns:
the XML report document.
Throws:
java.io.IOException - if I/O error occurs.

readReport

public XmlReport readReport(XmlMagRecord mag_record)
                     throws java.io.IOException
Reads the XML report document recorded in the specified magnitude record.
Parameters:
mag_record - the magnitude record.
Returns:
the XML report document.
Throws:
java.io.IOException - if I/O error occurs.

readInformation

public XmlInformation readInformation(XmlMagRecord mag_record)
                               throws java.io.IOException
Reads the XML information document recorded in the specified magnitude record.
Parameters:
mag_record - the magnitude record.
Returns:
the XML information document.
Throws:
java.io.IOException - if I/O error occurs.

readInformation

public XmlInformation readInformation(XmlMagRecord mag_record,
                                      InformationDBManager db_manager)
                               throws java.io.IOException
Reads the XML information document recorded in the specified magnitude record, from the XML report document file or specified information database.
Parameters:
mag_record - the magnitude record.
db_manager - the information database manager.
Returns:
the XML information document.
Throws:
java.io.IOException - if I/O error occurs.

readStar

public XmlStar readStar(XmlInformation info,
                        java.lang.String name)
                 throws java.io.IOException
Reads the star element in the XML report document with the specified name.
Parameters:
info - the XML information element.
name - the name.
Returns:
the star element.
Throws:
java.io.IOException - if I/O error occurs.

createFileFormat

public Format createFileFormat(XmlImage image)
                        throws java.io.FileNotFoundException,
                               java.net.MalformedURLException,
                               UnsupportedFileTypeException
Creates the image file format object.
Parameters:
image - the XML image element.
Returns:
the image file format object.
Throws:
java.io.FileNotFoundException - if the file does not exist.
java.net.MalformedURLException - if an unknown protocol is specified.
UnsupportedFileTypeException - if the file type is unsupported.