File I/O utilities.
Public Methods
static byte[] | |
static List<String> |
loadLabels(Context context, String filePath)
Loads labels from the label file into a list of strings.
|
static List<String> | |
static List<String> |
loadLabels(InputStream inputStream, Charset cs)
Loads labels from an input stream of an opened label file.
|
static List<String> |
loadLabels(Context context, String filePath, Charset cs)
Loads labels from the label file into a list of strings.
|
static MappedByteBuffer |
loadMappedFile(Context context, String filePath)
Loads a file from the asset folder through memory mapping.
|
static List<String> |
loadSingleColumnTextFile(Context context, String filePath, Charset cs)
Loads a vocabulary file (a single-column text file) into a list of strings.
|
static List<String> |
loadSingleColumnTextFile(InputStream inputStream, Charset cs)
Loads vocabulary from an input stream of an opened vocabulary file (which is a single-column
text file).
|
Inherited Methods
Public Methods
public static byte[] loadByteFromFile (Context context, String filePath)
Loads a binary file from the asset folder.
Parameters
context | Application context to access assets. |
---|---|
filePath | Asset path of the file. |
Returns
- the byte array for the binary file.
Throws
IOException | if an I/O error occurs when loading file. |
---|
public static List<String> loadLabels (Context context, String filePath)
Loads labels from the label file into a list of strings.
A legal label file is the plain text file whose contents are split into lines, and each line is an individual value. The file should be in assets of the context.
Parameters
context | The context holds assets. |
---|---|
filePath | The path of the label file, relative with assets directory. |
Returns
- a list of labels.
Throws
IOException | if error occurs to open or read the file. |
---|
public static List<String> loadLabels (InputStream inputStream)
Loads labels from an input stream of an opened label file. See details for label files in
loadLabels(Context, String)
.
Parameters
inputStream | the input stream of an opened label file. |
---|
Returns
- a list of labels.
Throws
IOException | if error occurs to open or read the file. |
---|
public static List<String> loadLabels (InputStream inputStream, Charset cs)
Loads labels from an input stream of an opened label file. See details for label files in
loadLabels(Context, String)
.
Parameters
inputStream | the input stream of an opened label file. |
---|---|
cs | Charset to use when decoding content of label file. |
Returns
- a list of labels.
Throws
IOException | if error occurs to open or read the file. |
---|
public static List<String> loadLabels (Context context, String filePath, Charset cs)
Loads labels from the label file into a list of strings.
A legal label file is the plain text file whose contents are split into lines, and each line is an individual value. The empty lines will be ignored. The file should be in assets of the context.
Parameters
context | The context holds assets. |
---|---|
filePath | The path of the label file, relative with assets directory. |
cs | Charset to use when decoding content of label file. |
Returns
- a list of labels.
Throws
IOException | if error occurs to open or read the file. |
---|
public static MappedByteBuffer loadMappedFile (Context context, String filePath)
Loads a file from the asset folder through memory mapping.
Parameters
context | Application context to access assets. |
---|---|
filePath | Asset path of the file. |
Returns
- the loaded memory mapped file.
Throws
IOException | if an I/O error occurs when loading the tflite model. |
---|
public static List<String> loadSingleColumnTextFile (Context context, String filePath, Charset cs)
Loads a vocabulary file (a single-column text file) into a list of strings.
A vocabulary file is a single-column plain text file whose contents are split into lines, and each line is an individual value. The file should be in assets of the context.
Parameters
context | The context holds assets. |
---|---|
filePath | The path of the vocabulary file, relative with assets directory. |
cs |
Returns
- a list of vocabulary words.
Throws
IOException | if error occurs to open or read the file. |
---|
public static List<String> loadSingleColumnTextFile (InputStream inputStream, Charset cs)
Loads vocabulary from an input stream of an opened vocabulary file (which is a single-column text file).
A vocabulary file is a single-column plain text file whose contents are split into lines, and each line is an individual value. The file should be in assets of the context.
Parameters
inputStream | the input stream of an opened vocabulary file. |
---|---|
cs |
Returns
- a list of vocabulary words.
Throws
IOException | if error occurs to open or read the file. |
---|