|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.cmu.sphinx.util.StreamFactory
Supports the loading and saving of files from different sources, e.g., a ZIP file or a plain directory. Provides methods that returns an InputStream or OutputStream to the named file in the given source.
Field Summary | |
static java.lang.String |
DIRECTORY
Identifies a plain directory. |
static java.lang.String |
ZIP_FILE
Identifies a ZIP file. |
Constructor Summary | |
StreamFactory()
|
Method Summary | |
static java.io.InputStream |
getInputStream(java.lang.String location,
java.lang.String file)
Returns an appropriate InputStream of the given file in the given URL location. |
static java.io.InputStream |
getInputStream(java.lang.String format,
java.lang.String location,
java.lang.String file)
According to the given data format, returns an appropriate InputStream of the given file in the given URL location. |
static java.io.OutputStream |
getOutputStream(java.lang.String location,
java.lang.String file)
Returns an appropriate OutputStream of the given file in the given URL location. |
static java.io.OutputStream |
getOutputStream(java.lang.String location,
java.lang.String file,
boolean append)
Returns an appropriate OutputStream of the given file in the given URL location. |
static java.io.OutputStream |
getOutputStream(java.lang.String format,
java.lang.String location,
java.lang.String file)
According to the given data format, returns an appropriate OutputStream of the given file in the given URL location. |
static java.io.OutputStream |
getOutputStream(java.lang.String format,
java.lang.String location,
java.lang.String file,
boolean append)
According to the given data format, returns an appropriate OutputStream of the given file in the given URL location. |
static java.lang.String |
resolve(java.lang.String sourceName)
Returns the type of the given data source. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String ZIP_FILE
public static final java.lang.String DIRECTORY
Constructor Detail |
public StreamFactory()
Method Detail |
public static java.io.InputStream getInputStream(java.lang.String location, java.lang.String file) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
resolve
method is called to resolve whether
"location" refers to a ZIP file or a directory.
Suppose you want the InputStream to the file "dict/dictionary.txt"
in the ZIP file "file:/lab/speech/sphinx4/data/wsj.zip".
You will do:
StreamFactory.getInputStream(
"file:/lab/speech/sphinx4/data/wsj.zip", "dict/dictionary.txt");
Suppose you want the InputStream to the file "dict/dictionary.txt"
in the directory "file:/lab/speech/sphinx4/data/wsj", you will do:
StreamFactory.getInputStream(
"file:/lab/speech/sphinx4/data/wsj", "dict/dictionary.txt");
The StreamFactory.resolve()
method is called to
resolve whether "location" refers to a ZIP file or a directory.
location
- the URL location of the input data, it can now
be a directory or a ZIP filefile
- the file in the given location to obtain the InputStream
java.io.FileNotFoundException
java.io.IOException
java.util.zip.ZipException
public static java.io.InputStream getInputStream(java.lang.String format, java.lang.String location, java.lang.String file) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
StreamFactory.getInputStream(StreamFactory.ZIP_FILE,
"file:/lab/speech/sphinx4/data/wsj.zip", "dict/dictionary.txt");
Suppose you want the InputStream to the file "dict/dictionary.txt"
in the directory "file:/lab/speech/sphinx4/data/wsj", you will do:
StreamFactory.getInputStream(StreamFactory.DIRECTORY,
"file:/lab/speech/sphinx4/data/wsj", "dict/dictionary.txt");
format
- the format of the input data, the currently supported
formats are:
location
- the URL location of the input data, it can now
be a directory or a JAR or ZIP file, or null if no location
is given, which means that the argument
also
specifies the exact locationfile
- the file in the given location to obtain the InputStream
java.io.FileNotFoundException
java.io.IOException
java.util.zip.ZipException
public static java.io.OutputStream getOutputStream(java.lang.String location, java.lang.String file, boolean append) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
resolve
method is called to resolve whether
"location" refers to a ZIP file or a directory. If saving to a
zip or jar, the file can be appended or overwritten. If saving
to a directory, files are always overwritten.
Suppose you want the OutputStream to the file "dict/dictionary.txt"
in the ZIP file "file:/lab/speech/sphinx4/data/wsj.zip".
You will do:
StreamFactory.getOutputStream(
"file:/lab/speech/sphinx4/data/wsj.zip", "dict/dictionary.txt", true);
Suppose you want the OutputStream to the file "dict/dictionary.txt"
in the directory "file:/lab/speech/sphinx4/data/wsj", you will do:
StreamFactory.getOutputStream(
"file:/lab/speech/sphinx4/data/wsj", "dict/dictionary.txt", false);
The StreamFactory.resolve()
method is called to
resolve whether "location" refers to a ZIP file or a directory.
location
- the URL location of the output data, it can now
be a directory or a ZIP filefile
- the file in the given location to obtain the OutputStreamappend
- if true and saving to a zip file, then file is appended
rather than overwritten.
java.io.FileNotFoundException
java.io.IOException
java.util.zip.ZipException
public static java.io.OutputStream getOutputStream(java.lang.String format, java.lang.String location, java.lang.String file, boolean append) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
StreamFactory.getOutputStream(StreamFactory.ZIP_FILE,
"file:/lab/speech/sphinx4/data/wsj.zip", "dict/dictionary.txt", true);
Suppose you want the OutputStream to the file "dict/dictionary.txt"
in the directory "file:/lab/speech/sphinx4/data/wsj", you will do:
StreamFactory.getOutputStream(StreamFactory.DIRECTORY,
"file:/lab/speech/sphinx4/data/wsj", "dict/dictionary.txt", false);
format
- the format of the output data, the currently supported
formats are:
location
- the URL location of the output data, it can now
be a directory or a JAR or ZIP file, or null if no location
is given, which means that the argument
also
specifies the exact locationfile
- the file in the given location to obtain the OutputStreamappend
- if true and saving to a zip file, then file is appended
rather than overwritten.
java.io.FileNotFoundException
java.io.IOException
java.util.zip.ZipException
public static java.io.OutputStream getOutputStream(java.lang.String location, java.lang.String file) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
resolve
method is called to resolve whether
"location" refers to a ZIP file or a directory. Files are
overwritten, which may be risky for ZIP of JAR files.
Suppose you want the OutputStream to the file "dict/dictionary.txt"
in the ZIP file "file:/lab/speech/sphinx4/data/wsj.zip".
You will do:
StreamFactory.getOutputStream(
"file:/lab/speech/sphinx4/data/wsj.zip", "dict/dictionary.txt");
Suppose you want the OutputStream to the file "dict/dictionary.txt"
in the directory "file:/lab/speech/sphinx4/data/wsj", you will do:
StreamFactory.getOutputStream(
"file:/lab/speech/sphinx4/data/wsj", "dict/dictionary.txt");
The StreamFactory.resolve()
method is called to
resolve whether "location" refers to a ZIP file or a directory.
location
- the URL location of the output data, it can now
be a directory or a ZIP filefile
- the file in the given location to obtain the OutputStream
java.io.FileNotFoundException
java.io.IOException
java.util.zip.ZipException
public static java.io.OutputStream getOutputStream(java.lang.String format, java.lang.String location, java.lang.String file) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
StreamFactory.getOutputStream(StreamFactory.ZIP_FILE,
"file:/lab/speech/sphinx4/data/wsj.zip", "dict/dictionary.txt");
Suppose you want the OutputStream to the file "dict/dictionary.txt"
in the directory "file:/lab/speech/sphinx4/data/wsj", you will do:
StreamFactory.getOutputStream(StreamFactory.DIRECTORY,
"file:/lab/speech/sphinx4/data/wsj", "dict/dictionary.txt");
format
- the format of the output data, the currently supported
formats are:
location
- the URL location of the output data, it can now
be a directory or a JAR or ZIP file, or null if no location
is given, which means that the argument
also
specifies the exact locationfile
- the file in the given location to obtain the OutputStream
java.io.FileNotFoundException
java.io.IOException
java.util.zip.ZipException
public static java.lang.String resolve(java.lang.String sourceName)
StreamFactory.ZIP_FILE
StreamFactory.DIRECTORY
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |