public class FileStorageModel
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
void |
cacheCleanup()
remove files that have been identified as old versions.
|
boolean |
containsFile(java.io.File file)
return true if the file came (or could come) from this FileStorageModel.
|
boolean |
containsName(java.lang.String name)
return true if the name came (or could come) from this FileStorageModel.
|
static FileStorageModel |
create(FileSystem root,
java.lang.String template)
creates a FileStorageModel for the given template, which uses:
|
static FileStorageModel |
create(FileSystem root,
java.lang.String template,
java.lang.String fieldName,
TimeParser.FieldHandler fieldHandler)
creates a FileStorageModel for the given template, but with a custom FieldHandler and
field.
|
java.lang.String[] |
generateNamesFor(DatumRange range)
generate the names of the files that would cover this range.
|
java.io.File[] |
getBestFilesFor(DatumRange targetRange)
return the best files found for the range, without progress feedback.
|
java.io.File[] |
getBestFilesFor(DatumRange targetRange,
ProgressMonitor monitor)
Get the files for the range, using versioning info ($v,etc).
|
java.lang.String[] |
getBestNamesFor(DatumRange targetRange)
return the names in the range, minding version numbers, or all available
names if the range is null.
|
java.lang.String[] |
getBestNamesFor(DatumRange targetRange,
ProgressMonitor monitor)
return the names in the range, minding version numbers, or all available
names if the range is null.
|
static CacheTag |
getCacheTagFor(FileStorageModel fsm,
DatumRange range,
java.io.File[] files) |
static CacheTag |
getCacheTagFor(FileStorageModel fsm,
DatumRange range,
java.lang.String[] names) |
static FileSystem |
getChildFileSystem(FileSystem root,
java.lang.String child,
ProgressMonitor monitor)
return a child filesystem, with special code for LocalFileSystems to support
Windows.
|
java.lang.String |
getField(java.lang.String field,
java.lang.String name)
return the field value for the given name.
|
java.io.File |
getFileFor(java.lang.String name)
download the file for the given name within the filesystem.
|
java.io.File |
getFileFor(java.lang.String name,
ProgressMonitor monitor)
download the file for the given name within the filesystem.
|
java.lang.String |
getFilenameFor(Datum start,
Datum end)
return a filename that would intersect the range.
|
java.io.File[] |
getFilesFor(DatumRange targetRange) |
java.io.File[] |
getFilesFor(DatumRange targetRange,
ProgressMonitor monitor)
Download the files within the range.
|
java.io.File[] |
getFilesFor(java.lang.String[] names,
ProgressMonitor monitor)
download the files for each of the given names within the filesystem.
|
FileSystem |
getFileSystem()
return the filesystem used to implement this.
|
java.lang.String |
getNameFor(java.io.File file)
Provides a way to recover the model name of a file.
|
java.lang.String[] |
getNamesFor(DatumRange targetRange)
return the names in the range, or all names if the range is null.
|
java.lang.String[] |
getNamesFor(DatumRange targetRange,
ProgressMonitor monitor)
return the names in the range, or all available names if the range is null.
|
FileStorageModel |
getParent()
returns the parent or null if none exists.
|
DatumRange |
getRangeFor(java.lang.String name)
return the time range represented by this name.
|
static java.lang.String |
getRepresentativeFile(FileStorageModel ths,
ProgressMonitor monitor,
java.lang.String childRegex,
DatumRange range,
int depth)
Return a random file from the FSM, which can be used to represent a typical file.
|
java.lang.String |
getRepresentativeFile(ProgressMonitor monitor)
return a random file from the FSM, which can be used to represent a typical file.
|
java.lang.String |
getRepresentativeFile(ProgressMonitor monitor,
java.lang.String childRegex)
return a random file from the FSM, which can be used to represent a typical file.
|
java.lang.String |
getRepresentativeFile(ProgressMonitor monitor,
java.lang.String childRegex,
DatumRange range)
Return a random file from the FSM, which can be used to represent a typical file.
|
java.lang.String |
getRoot()
return the root of the filesystem as a string.
|
boolean |
hasField(java.lang.String field)
returns true if the parser has the field.
|
protected static java.lang.String |
makeCanonical(java.lang.String template)
Autoplot introduced the dollar sign instead of the percent, because $ is
more URI-friendly.
|
DatumRange |
quantize(DatumRange timeRange)
return the timerange that contains the given timerange and
exactly contains a set of granules.
|
void |
setContext(DatumRange trdr)
set the datum range giving context to the files.
|
static int |
splitIndex(java.lang.String surl)
This returns the index splitting the static part of the filename from the templated part.
|
java.lang.String |
toString() |
public FileSystem getFileSystem()
public static FileSystem getChildFileSystem(FileSystem root, java.lang.String child, ProgressMonitor monitor) throws FileSystem.FileSystemOfflineException, java.net.UnknownHostException, java.io.FileNotFoundException
root
- child
- monitor
- FileSystem.FileSystemOfflineException
java.net.UnknownHostException
java.io.FileNotFoundException
https://sourceforge.net/p/autoplot/bugs/2132
public java.lang.String getRepresentativeFile(ProgressMonitor monitor) throws java.io.IOException
monitor
- progress monitor in case a file must be downloaded.java.io.IOException
public java.lang.String getRepresentativeFile(ProgressMonitor monitor, java.lang.String childRegex) throws java.io.IOException
monitor
- progress monitor in case a file must be downloaded.childRegex
- the parent must contain a file/folder matching childRegexjava.io.IOException
public java.lang.String getRepresentativeFile(ProgressMonitor monitor, java.lang.String childRegex, DatumRange range) throws java.io.IOException
monitor
- progress monitor in case a file must be downloaded.childRegex
- the parent must contain a file/folder matching childRegex, or null if there is no child.range
- hint at the range where we are looking, or null if there is not time range constraint.java.io.IOException
- if the file cannot be downloaded.public static java.lang.String getRepresentativeFile(FileStorageModel ths, ProgressMonitor monitor, java.lang.String childRegex, DatumRange range, int depth) throws java.io.IOException
ths
- monitor
- progress monitor in case a file must be downloaded.childRegex
- the parent must contain a file/folder matching childRegex, or null if there is no child.range
- hint at the range where we are looking.depth
- the recursion depth, useful for debugging.java.io.IOException
- if the file cannot be downloaded.public void setContext(DatumRange trdr)
trdr
- the contextpublic java.lang.String getFilenameFor(Datum start, Datum end)
start
- end
- public java.lang.String[] generateNamesFor(DatumRange range)
range
- the time range to cover.public DatumRange quantize(DatumRange timeRange)
timeRange
- arbitrary time rangepublic java.lang.String[] getNamesFor(DatumRange targetRange) throws java.io.IOException
targetRange
- range limit, or null.java.io.IOException
public java.lang.String[] getNamesFor(DatumRange targetRange, ProgressMonitor monitor) throws java.io.IOException
targetRange
- range limit, or null.monitor
- java.io.IOException
public java.lang.String[] getBestNamesFor(DatumRange targetRange, ProgressMonitor monitor) throws java.io.IOException
targetRange
- range limit, or null.monitor
- java.io.IOException
public java.lang.String[] getBestNamesFor(DatumRange targetRange) throws java.io.IOException
targetRange
- range limit, or null.java.io.IOException
public static CacheTag getCacheTagFor(FileStorageModel fsm, DatumRange range, java.lang.String[] names)
public static CacheTag getCacheTagFor(FileStorageModel fsm, DatumRange range, java.io.File[] files)
public java.io.File[] getFilesFor(DatumRange targetRange) throws java.io.IOException
java.io.IOException
public java.io.File[] getBestFilesFor(DatumRange targetRange) throws java.io.IOException
targetRange
- java.io.IOException
public void cacheCleanup()
public DatumRange getRangeFor(java.lang.String name)
name
- like 2013-10-31java.lang.IllegalArgumentException
- if the name is not part of the FileStorageModel.public boolean hasField(java.lang.String field)
field
- e.g. "x"public java.lang.String getField(java.lang.String field, java.lang.String name)
field
- field, for example "v"name
- name, for example 2014/04/04/20140404_v2.3.datpublic boolean containsFile(java.io.File file)
file
- the filepublic boolean containsName(java.lang.String name)
name
- the name within the filesystem.public java.lang.String getNameFor(java.io.File file)
file
- the filepublic java.lang.String getRoot()
public java.io.File getFileFor(java.lang.String name) throws java.io.IOException
name
- the name within the filesystem.java.io.IOException
public java.io.File getFileFor(java.lang.String name, ProgressMonitor monitor) throws java.io.IOException
name
- the name within the filesystem.monitor
- monitor for the download.java.io.IOException
public java.io.File[] getFilesFor(java.lang.String[] names, ProgressMonitor monitor) throws java.io.IOException
names
- array of names within the filesystemmonitor
- monitor for the downloads (or null).java.io.IOException
- during the transferpublic java.io.File[] getFilesFor(DatumRange targetRange, ProgressMonitor monitor) throws java.io.IOException
targetRange
- range limit, or null if no constraint used here.monitor
- the monitorjava.io.IOException
public java.io.File[] getBestFilesFor(DatumRange targetRange, ProgressMonitor monitor) throws java.io.IOException
targetRange
- range limit, or null if no constraint used here.monitor
- the monitorjava.io.IOException
public FileStorageModel getParent()
protected static java.lang.String makeCanonical(java.lang.String template)
template,
- e.g "/%Y/%m%d.dat"public static int splitIndex(java.lang.String surl)
http://autoplot.org/data/ C1_CP_EDI_EGD__$Y$m$d_V$v.cefand http://emfisis.physics.uiowa.edu/Flight/RBSP-A/Quick-Look/$Y/$m/$d/rbsp-a_magnetometer_4sec-gsm_emfisis-Quick-Look_$Y$m$d_v$(v,sep).cdf:
http://emfisis.physics.uiowa.edu/Flight/RBSP-A/Quick-Look/ $Y/$m/$d/rbsp-a_magnetometer_4sec-gsm_emfisis-Quick-Look_$Y$m$d_v$(v,sep).cdf
This new version uses regexs and is more complete than versions found in Autoplot, and they should eventually use this instead. Note the Autoplot one returns the index of the last /, whereas this returns that index plus one.
Taken from Autoplot's AggregatingDataSourceFactory, where Autoplot just has a URI and needs to get a file list. See also org/autoplot/pngwalk/WalkUtil.java splitIndex, which also allows wildcards like *.
Note, ages ago %Y was valid as well as $Y. This is no longer supported, since it is useful to have Python templates working alongside URI_Templates.surl
- a string like http://autoplot.org/data/C1_CP_EDI_EGD__$Y$m$d_V$v.cefpublic static FileStorageModel create(FileSystem root, java.lang.String template)
%Y-%m-%dT%H:%M:%S.%{milli}Z"; %Y 4-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 %S 2-digit second %v best version by number Also %(v,sep) for 4.3.2 or %(v,alpha) %{milli} 3-digit millisecondsproduct_$(o,id=ftp://stevens.lanl.gov/pub/projects/rbsp/autoplot/orbits/rbspa_pp).png
root
- FileSystem source of the files.template
- describes how filenames are constructed. This is converted to a regular expression and may contain regex elements without groups. The
string may contain $ instead of percents as long as there are no percents in the string.public static FileStorageModel create(FileSystem root, java.lang.String template, java.lang.String fieldName, TimeParser.FieldHandler fieldHandler)
root
- FileSystem source of the files.template
- describes how filenames are constructed. This is converted to a regular expression and may contain regex elements without groups. The
string may contain $ instead of percents as long as there are no percents in the string.fieldName
- custom field namefieldHandler
- TimeParser.FieldHandler to call with the field contents.public java.lang.String toString()
toString
in class java.lang.Object