simtools.util
Class FileSerializer

java.lang.Object
  extended by simtools.util.FileSerializer

public class FileSerializer
extends java.lang.Object

Serialize/deserialize a file description

Author:
cazenave_c
See Also:
write(ObjectOutputStream, File, File), read(ObjectInputStream, File)

Field Summary
protected static java.io.File file
          The current file the FileSerializer works on.
protected static ListenerManager listeners
           
 
Constructor Summary
FileSerializer()
           
 
Method Summary
static void addListener(FileReferenceListener dsl)
           
static java.io.File getFile()
          Get the current file the FileSerializer works on
protected static void notifyFileReferenceListeners(java.io.File file)
           
 java.io.File read(java.io.ObjectInputStream in, java.io.File referenceFile)
          Reads a file description from an input stream If the file computation fails an invalid file (not null) is returned
static java.io.File readFromString(java.lang.String path, java.io.File referenceFile)
          Reads a file description from an input string If the file computation fails an invalid file (not null) is returned
static void removeListener(FileReferenceListener dsl)
           
static void setFile(java.io.File file)
          Get the current file the FileSerializer works on
 void write(java.io.ObjectOutputStream out, java.io.File file, java.io.File referenceFile)
          Writes a file description to an output stream According to the file serializer configuration the following applies : - A computation of a relative path from the reference file to the file to serialize is performed.
static java.lang.String writeIntoString(java.io.File file, java.io.File referenceFile)
          Writes a file description to an output string According to the file serializer configuration the following applies : A computation of a relative path from the reference file to the file to serialize is performed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected static ListenerManager listeners

file

protected static java.io.File file
The current file the FileSerializer works on.

Constructor Detail

FileSerializer

public FileSerializer()
Method Detail

write

public void write(java.io.ObjectOutputStream out,
                  java.io.File file,
                  java.io.File referenceFile)
           throws java.io.IOException
Writes a file description to an output stream According to the file serializer configuration the following applies : - A computation of a relative path from the reference file to the file to serialize is performed. This computation enables upper directories relative path detection i.e. referenceFile/../../../path/file is handled while it is not the case for preferred directories If this computation succeeds then the number of upper directories and the relative path from that upper directory is written to the ouptut stream (in the example 3 and path). If this computation fails then a null object and the absolute path is written. If referenceFile is null and the file is not located inside a preferred directory then the null object and the absolute path is written to the stream

Parameters:
out - the output stream
file - the file to save
referenceFile - the file to be used for relative path computation
Throws:
java.io.IOException

read

public java.io.File read(java.io.ObjectInputStream in,
                         java.io.File referenceFile)
                  throws java.lang.ClassNotFoundException,
                         java.io.IOException
Reads a file description from an input stream If the file computation fails an invalid file (not null) is returned

Parameters:
in - the stream to read
referenceFile - the file to be used for relative path computation
Returns:
the file according to stream information (not null but may be not a real file!)
Throws:
java.lang.ClassNotFoundException
java.io.IOException

writeIntoString

public static java.lang.String writeIntoString(java.io.File file,
                                               java.io.File referenceFile)
Writes a file description to an output string According to the file serializer configuration the following applies : A computation of a relative path from the reference file to the file to serialize is performed. This computation enables upper directories relative path detection i.e. referenceFile/../../../path/file is handled while it is not the case for preferred directories If this computation succeeds then the number of upper directories and the relative path from that upper directory is written to the string. If this computation fails then the absolute path is written. If referenceFile is null or the file is not located inside a preferred directory then the absolute path is written to the string

Parameters:
file - the file to save
referenceFile - the file to be used for relative path computation

readFromString

public static java.io.File readFromString(java.lang.String path,
                                          java.io.File referenceFile)
Reads a file description from an input string If the file computation fails an invalid file (not null) is returned

Parameters:
relative - or absolule path file
referenceFile - the file to be used for relative path computation

addListener

public static void addListener(FileReferenceListener dsl)

removeListener

public static void removeListener(FileReferenceListener dsl)

setFile

public static void setFile(java.io.File file)
Get the current file the FileSerializer works on

Parameters:
file -

getFile

public static java.io.File getFile()
Get the current file the FileSerializer works on

Returns:
the current file the FileSerializer works on

notifyFileReferenceListeners

protected static void notifyFileReferenceListeners(java.io.File file)
Parameters:
file - - The file that has been referenced