public class StreamFactory
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DIRECTORY
Identifies a plain directory.
|
static java.lang.String |
ZIP_FILE
Identifies a ZIP file.
|
Constructor and Description |
---|
StreamFactory() |
Modifier and Type | Method and Description |
---|---|
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) |
public static final java.lang.String ZIP_FILE
public static final java.lang.String DIRECTORY
public static java.io.InputStream getInputStream(java.lang.String location, java.lang.String file) throws java.io.IOException
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 InputStreamjava.io.IOException
- if IO went wrongpublic static java.io.InputStream getInputStream(java.lang.String format, java.lang.String location, java.lang.String file) throws java.io.IOException
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(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 InputStreamjava.io.IOException
- if IO went wrongpublic static java.io.OutputStream getOutputStream(java.lang.String location, java.lang.String file, boolean append) throws java.io.IOException
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.IOException
- if IO went wrongpublic static java.io.OutputStream getOutputStream(java.lang.String format, java.lang.String location, java.lang.String file, boolean append) throws java.io.IOException
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(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.IOException
- if IO went wrongpublic static java.io.OutputStream getOutputStream(java.lang.String location, java.lang.String file) throws java.io.IOException
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 OutputStreamjava.io.IOException
- if IO went wrongpublic static java.io.OutputStream getOutputStream(java.lang.String format, java.lang.String location, java.lang.String file) throws java.io.IOException
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(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 OutputStreamjava.io.IOException
- if IO went wrongpublic static java.lang.String resolve(java.lang.String sourceName)
sourceName
- name of the source StreamFactory.ZIP_FILE
StreamFactory.DIRECTORY