edu.wisc.ssec.mcidas
Class AreaFileFactory

java.lang.Object
  extended by edu.wisc.ssec.mcidas.AreaFileFactory

public final class AreaFileFactory
extends Object

Utility class for creating AreaFile instances. This class handles subsetting local files using urls whereas the AreaFile constructors do not.

No instances of this class can be created.

Version:
$Id: AreaFileFactory.java,v 1.8 2009-07-01 12:51:04 donm Exp $
Author:
Bruce Flynn, SSEC

Method Summary
static String calIntToStr(int cal)
          Calibration int to string.
static int calStrToInt(String cal)
          String to calibration int.
static void copyAreaFile(String source, String outputFile)
          Copy an area file from one place to another
static void copyAreaFile(String source, String outputFile, boolean verbose)
          Copy an area file from one place to another
static AreaFile getAreaFileInstance(String src)
          Create an initialized AreaFile instance.
static AreaFile getAreaFileInstance(String fpath, int startLine, int numLines, int lineMag, int startElem, int numEles, int eleMag, int band)
          See AreaFile.AreaFile(String, int, int, int, int, int, int, int)
static AreaFile getAreaFileInstance(URL url)
          Create an initialized AreaFile instance.
static String makeLocalQuery(int sl, int nl, int lm, int se, int ne, int em, int b)
          Construct a url query string for subsetting a local file.
static String makeLocalQuery(int sl, int nl, int lm, int se, int ne, int em, int b, int c)
          Construct a url query string for subsetting a local file.
static String makeLocalQuery(int sl, int nl, int lm, int se, int ne, int em, int b, String c)
          Construct a url query string for subsetting a local file.
static URL makeLocalSubsetURL(String fpath, int sl, int nl, int lm, int se, int ne, int em, int b, String u)
          Construct a URL for subsetting a local file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

calStrToInt

public static final int calStrToInt(String cal)
String to calibration int.

Parameters:
cal - calibration type string
Returns:
calibration type integer, Calibrator.CAL_NONE if unknown

calIntToStr

public static final String calIntToStr(int cal)
Calibration int to string.

Parameters:
cal - calibration type
Returns:
calibration type string, raw if unknown

makeLocalQuery

public static final String makeLocalQuery(int sl,
                                          int nl,
                                          int lm,
                                          int se,
                                          int ne,
                                          int em,
                                          int b)
Construct a url query string for subsetting a local file.

Parameters:
sl - starting line number.
nl - number of lines.
lm - line magnification.
se - starting element.
ne - number of elements.
em - element magnification.
b - band number.
Returns:
"?band=B&linele=SL SE&size=NL NE&mag=LM EM"

makeLocalQuery

public static final String makeLocalQuery(int sl,
                                          int nl,
                                          int lm,
                                          int se,
                                          int ne,
                                          int em,
                                          int b,
                                          int c)
Construct a url query string for subsetting a local file.

Parameters:
sl - starting line number.
nl - number of lines.
lm - line magnification.
se - starting element.
ne - number of elements.
em - element magnification.
b - band number.
c - calibration type
Returns:
"?band=B&linele=SL SE&size=NL NE&mag=LM EM"&unit=C;

makeLocalQuery

public static final String makeLocalQuery(int sl,
                                          int nl,
                                          int lm,
                                          int se,
                                          int ne,
                                          int em,
                                          int b,
                                          String c)
Construct a url query string for subsetting a local file.

Parameters:
sl - starting line number.
nl - number of lines.
lm - line magnification.
se - starting element.
ne - number of elements.
em - element magnification.
b - band number.
c - calibration type as a string
Returns:
"?band=B&linele=SL SE&size=NL NE&mag=LM EM"&unit=C;

makeLocalSubsetURL

public static final URL makeLocalSubsetURL(String fpath,
                                           int sl,
                                           int nl,
                                           int lm,
                                           int se,
                                           int ne,
                                           int em,
                                           int b,
                                           String u)
                                    throws MalformedURLException
Construct a URL for subsetting a local file.

Parameters:
fpath - canonical path to an area file.
sl - starting line number.
nl - number of lines.
lm - line magnification.
se - starting element.
ne - number of elements.
em - element magnification.
b - band number.
u - calibration unit
Returns:
a string of the format "file://FPATH?band=B& linele=SL SE&size=NL NE&mag=LM EM"&unit=U
Throws:
MalformedURLException - bad URL specification

getAreaFileInstance

public static final AreaFile getAreaFileInstance(String src)
                                          throws AreaFileException,
                                                 AddeURLException
Create an initialized AreaFile instance. First, an attempt is made to create a URL from src, if an error occurrs, meaning src is not a valid url, src is interpreted as a file path.

Parameters:
src - A relative or canonical path to a local file as a string or a string representation of a url appropriate for creating an AreaFile instance. For more information on urls appropriate for creating AreaFile instances see getAreaFileInstance(URL).

URLs containing encoded characters in their query strings will be decoded before parsing.

Returns:
an initialized, possibly subsetted, instance
Throws:
AreaFileException - on any error constructing the instance.
AddeURLException - If the source is a URL and the query string is not formatted correctly.

getAreaFileInstance

public static final AreaFile getAreaFileInstance(URL url)
                                          throws AddeURLException,
                                                 AreaFileException
Create an initialized AreaFile instance.

A url appropriate for creating an instance will have a protocol of either adde for remote ADDE data or file for files on the local disk. Information on consructing ADDE urls can be found in the AddeURLConnection class.

A local file url may either be a standard file url such as file:///<absolute file path> or it may specify subsetting information. If specifying subsetting information, the url can contain the following parameters from the ADDE image data url specification with the specified defaults:

 NAME      DEFAULT
 linele  - 0 0 a  Must be used with size.
                  NOTE: only type 'a' is supported at this time
 size    - 0 0    Must be used with linele.
 mag     - 1 1    Only with linele and size, but not required.
 band    - 1      Can be used separately, not required.
 unit    - RAW    Calibration type
 
A file url might look like:
 file://<abs file path>?linele=10 10&band=3&mag=-2 -4&size=500 500&unit=BRIT
 

URLs containing encoded characters in their query strings will be decoded before parsing.

Parameters:
url - - the url as described above
Returns:
an initialized, possibly subsetted, instance
Throws:
AreaFileException - on any error constructing the instance.
AddeURLException - if the query string is not a valid ADDE query stirng.

getAreaFileInstance

public static final AreaFile getAreaFileInstance(String fpath,
                                                 int startLine,
                                                 int numLines,
                                                 int lineMag,
                                                 int startElem,
                                                 int numEles,
                                                 int eleMag,
                                                 int band)
                                          throws AreaFileException
See AreaFile.AreaFile(String, int, int, int, int, int, int, int)

Parameters:
fpath - the path to the file
startLine - the starting image line
numLines - the total number of lines to return
lineMag - the line magnification. Valid values are >= -1. -1, 0, and 1 are all taken to be full line resolution, 2 is every other line, 3 every third, etc...
startElem - the starting image element
numEles - the total number of elements to return
eleMag - the element magnification. Valid values are >= -1. -1, 0, and 1 are all taken to be full element resolution, 2 is every other element, 3 every third, etc...
band - the 1-based band number for the subset, which must be present in the directory blocks band map or -1 for the first band
Returns:
the AreaFile instance
Throws:
AreaFileException

copyAreaFile

public static void copyAreaFile(String source,
                                String outputFile)
                         throws AddeURLException,
                                AreaFileException
Copy an area file from one place to another

Parameters:
source - source file or ADDE url
outputFile - name of the output file
Throws:
AreaFileException - on any error constructing the instance.
AddeURLException - If the source is a URL and the query string is not formatted correctly.

copyAreaFile

public static void copyAreaFile(String source,
                                String outputFile,
                                boolean verbose)
                         throws AddeURLException,
                                AreaFileException
Copy an area file from one place to another

Parameters:
source - source file or ADDE url
outputFile - name of the output file
verbose - true to print out status messages
Throws:
AreaFileException - on any error constructing the instance.
AddeURLException - If the source is a URL and the query string is not formatted correctly.