org.das2.fsm
Class FileStorageModel

java.lang.Object
  extended by org.das2.fsm.FileStorageModel

public class FileStorageModel
extends java.lang.Object

Represents a method for storing data sets in a set of files by time. The client provides a regex for the files and how each group of the regex is interpreted as a time digit. The model can then be used to provide the set of files that cover a time range, etc.


Nested Class Summary
static interface FileStorageModel.FieldHandler
           
static class FileStorageModel.IntegerFieldHandler
           
 
Field Summary
static int EndDay
           
static int EndDoy
           
static int EndHour
           
static int EndMinute
           
static int EndMonth
           
static int EndMonthName
           
static int EndSecond
           
static int EndYear2
           
static int EndYear4
           
static int Ignore
           
static int StartDay
           
static int StartDoy
           
static int StartHour
           
static int StartMinute
           
static int StartMonth
           
static int StartMonthName
           
static int StartSecond
           
static int StartYear2
           
static int StartYear4
           
 
Constructor Summary
FileStorageModel(FileStorageModel parent, FileSystem root, java.lang.String regex, FileStorageModel.FieldHandler[] handlers)
           
 
Method Summary
 java.lang.String calculateNameFor(Datum start)
          return the name that this time will fall into.
 boolean containsFile(java.io.File file)
          returns true if the file came (or could come) from this FileStorageModel.
static FileStorageModel create(FileSystem root, java.lang.String template)
          %Y 4-digit year %y 2-digit year %m 2-digit month %d 2-digit day of month %j 3-digit day of year %H 2-digit hour %M 2-digit minute %b month name
static FileStorageModel create(FileSystem root, java.lang.String regex, int[] digitList)
           
 java.io.File getFileFor(java.lang.String name, ProgressMonitor monitor)
          retrieve the file for the name.
 java.lang.String getFilenameFor(Datum start, Datum end)
           
 java.io.File[] getFilesFor(DatumRange targetRange)
           
 java.io.File[] getFilesFor(DatumRange targetRange, ProgressMonitor monitor)
          returns a list of files that can be used
 FileSystem getFileSystem()
           
 java.lang.String getNameFor(java.io.File file)
          Need a way to recover the model name of a file.
 java.lang.String[] getNamesFor(DatumRange targetRange)
           
 java.lang.String[] getNamesFor(DatumRange targetRange, ProgressMonitor monitor)
           
static java.lang.String getParentRegex(java.lang.String regex)
           
 DatumRange getRangeFor(java.lang.String name)
           
 java.lang.String getRepresentativeFile(ProgressMonitor monitor)
          this is introduced to support discovery, where we just need one file to get started.
 void setFileWidth(int multiplier, char digitCode)
          specify each file's width when the implicit width is not correct.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

StartYear4

public static final int StartYear4
See Also:
Constant Field Values

StartYear2

public static final int StartYear2
See Also:
Constant Field Values

StartMonth

public static final int StartMonth
See Also:
Constant Field Values

StartMonthName

public static final int StartMonthName
See Also:
Constant Field Values

StartDay

public static final int StartDay
See Also:
Constant Field Values

StartDoy

public static final int StartDoy
See Also:
Constant Field Values

StartHour

public static final int StartHour
See Also:
Constant Field Values

StartMinute

public static final int StartMinute
See Also:
Constant Field Values

StartSecond

public static final int StartSecond
See Also:
Constant Field Values

EndYear4

public static final int EndYear4
See Also:
Constant Field Values

EndYear2

public static final int EndYear2
See Also:
Constant Field Values

EndMonth

public static final int EndMonth
See Also:
Constant Field Values

EndMonthName

public static final int EndMonthName
See Also:
Constant Field Values

EndDay

public static final int EndDay
See Also:
Constant Field Values

EndDoy

public static final int EndDoy
See Also:
Constant Field Values

EndHour

public static final int EndHour
See Also:
Constant Field Values

EndMinute

public static final int EndMinute
See Also:
Constant Field Values

EndSecond

public static final int EndSecond
See Also:
Constant Field Values

Ignore

public static final int Ignore
See Also:
Constant Field Values
Constructor Detail

FileStorageModel

public FileStorageModel(FileStorageModel parent,
                        FileSystem root,
                        java.lang.String regex,
                        FileStorageModel.FieldHandler[] handlers)
Method Detail

getFilenameFor

public java.lang.String getFilenameFor(Datum start,
                                       Datum end)

getNamesFor

public java.lang.String[] getNamesFor(DatumRange targetRange)
                               throws java.io.IOException
Throws:
java.io.IOException

calculateNameFor

public java.lang.String calculateNameFor(Datum start)
return the name that this time will fall into.

Parameters:
start -
Returns:
the internal name of the file.
Throws:
java.lang.IllegalArgumentException - if this cannot be done.

getNamesFor

public java.lang.String[] getNamesFor(DatumRange targetRange,
                                      ProgressMonitor monitor)
                               throws java.io.IOException
Parameters:
targetRange - restrict search to range. May be null, in which case all names are returned.
Throws:
java.io.IOException - if the filesystem cannot be listed.

getRepresentativeFile

public java.lang.String getRepresentativeFile(ProgressMonitor monitor)
                                       throws java.io.IOException
this is introduced to support discovery, where we just need one file to get started. Before, there was code that would list all files, then use just the first one. This may return a skeleton file, but getFileFor() must return a result. This implementation does the same as getNames(), but stops after finding a file.

Returns:
null if no file is found
Throws:
java.io.IOException

getFilesFor

public java.io.File[] getFilesFor(DatumRange targetRange)
                           throws java.io.IOException
Throws:
java.io.IOException

getRangeFor

public DatumRange getRangeFor(java.lang.String name)

containsFile

public boolean containsFile(java.io.File file)
returns true if the file came (or could come) from this FileStorageModel.


getNameFor

public java.lang.String getNameFor(java.io.File file)
Need a way to recover the model name of a file. The returned File from getFilesFor can be anywhere, so it would be good to provide a way to get it back into a FSM name.


getFileFor

public java.io.File getFileFor(java.lang.String name,
                               ProgressMonitor monitor)
                        throws java.io.FileNotFoundException,
                               java.io.IOException
retrieve the file for the name.

Throws:
java.io.IOException - if the file cannot be transferred.
java.io.FileNotFoundException

getFilesFor

public java.io.File[] getFilesFor(DatumRange targetRange,
                                  ProgressMonitor monitor)
                           throws java.io.IOException
returns a list of files that can be used

Throws:
java.io.IOException

getParentRegex

public static java.lang.String getParentRegex(java.lang.String regex)

create

public static FileStorageModel create(FileSystem root,
                                      java.lang.String regex,
                                      int[] digitList)

create

public static FileStorageModel create(FileSystem root,
                                      java.lang.String template)
%Y 4-digit year %y 2-digit year %m 2-digit month %d 2-digit day of month %j 3-digit day of year %H 2-digit hour %M 2-digit minute %b month name


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getFileSystem

public FileSystem getFileSystem()

setFileWidth

public void setFileWidth(int multiplier,
                         char digitCode)
specify each file's width when the implicit width is not correct. For example, files are stored with a tag for the starting day, but actually span a week. The width must be an integer multiple of one year, month, day, hour, minute, or second.

Parameters:
digitCode - 'Y', 'm', 'd', 'H', etc.