public class FileUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FileUtil.FileException
Exception class for reporting back media-related error numbers from
ErrorMessages, which the caller can in turn pass to
Form.dispatchErrorOccurredEvent if needed.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkExternalStorageWriteable() |
static java.lang.String |
copyFile(java.lang.String inputFileName,
java.lang.String outputFileName)
Copies the contents of one local file to another local file.
|
static java.lang.String |
downloadUrlToFile(java.lang.String url,
java.lang.String outputFileName)
Downloads the resource with the given URL and writes it as a local file.
|
static java.io.File |
getDownloadFile(java.lang.String extension)
Creates a
File representing the complete path for a downloaded file,
creating the enclosing directories if needed. |
static java.io.File |
getExternalFile(java.lang.String fileName)
Returns the File for fileName in the external storage directory in
preparation for writing the file.
|
static java.lang.String |
getFileUrl(java.lang.String localFileName)
Returns an URL for the given local file.
|
static java.io.File |
getPictureFile(java.lang.String extension)
Creates a
File representing the complete path for an image
file, creating the enclosing directories if needed. |
static java.io.File |
getRecordingFile(java.lang.String extension)
Creates a
File representing the complete path for a recording,
creating the enclosing directories if needed. |
static byte[] |
readFile(java.lang.String inputFileName)
Reads the given local file and returns the contents as a byte array.
|
static java.lang.String |
writeFile(byte[] array,
java.lang.String outputFileName)
Writes the given byte array as a local file.
|
static java.lang.String |
writeStreamToFile(java.io.InputStream in,
java.lang.String outputFileName)
Writes the contents from the given input stream to the given file.
|
public static java.lang.String getFileUrl(java.lang.String localFileName)
public static byte[] readFile(java.lang.String inputFileName) throws java.io.IOException
inputFileName
- the name of the file to read fromjava.io.IOException
public static java.lang.String downloadUrlToFile(java.lang.String url, java.lang.String outputFileName) throws java.io.IOException
url
- the URL to read fromoutputFileName
- the name of the file to write tojava.io.IOException
public static java.lang.String writeFile(byte[] array, java.lang.String outputFileName) throws java.io.IOException
array
- the byte array to read fromoutputFileName
- the name of the file to write tojava.io.IOException
public static java.lang.String copyFile(java.lang.String inputFileName, java.lang.String outputFileName) throws java.io.IOException
inputFileName
- the name of the file to read tooutputFileName
- the name of the file to write tojava.io.IOException
public static java.lang.String writeStreamToFile(java.io.InputStream in, java.lang.String outputFileName) throws java.io.IOException
in
- the InputStream to read fromoutputFileName
- the name of the file to write tojava.io.IOException
public static java.io.File getPictureFile(java.lang.String extension) throws java.io.IOException, FileUtil.FileException
File
representing the complete path for an image
file, creating the enclosing directories if needed. This does not actually
open the file. Any component that calls this must have
Manifest.permission.WRITE_EXTERNAL_STORAGE
.extension
- file extension, such as "png" or "jpg"java.io.IOException
- if the enclosing directory cannot be createdFileUtil.FileException
- if external storage is not accessible or not writable
with the appropriate ErrorMessages error code.public static java.io.File getRecordingFile(java.lang.String extension) throws java.io.IOException, FileUtil.FileException
File
representing the complete path for a recording,
creating the enclosing directories if needed. This does not actually
open the file. Any component that calls this must have
Manifest.permission.WRITE_EXTERNAL_STORAGE
.extension
- file extension, such as "3gp"java.io.IOException
- if the enclosing directory cannot be createdFileUtil.FileException
- if external storage is not accessible or not writable
with the appropriate ErrorMessages error code.public static java.io.File getDownloadFile(java.lang.String extension) throws java.io.IOException, FileUtil.FileException
File
representing the complete path for a downloaded file,
creating the enclosing directories if needed. This does not actually
open the file. Any component that calls this must have
Manifest.permission.WRITE_EXTERNAL_STORAGE
.extension
- file extension, such as "tmp"java.io.IOException
- if the enclosing directory cannot be createdFileUtil.FileException
- if external storage is not accessible or not writable
with the appropriate ErrorMessages error code.public static java.io.File getExternalFile(java.lang.String fileName) throws java.io.IOException, FileUtil.FileException
fileName
- The path name of the file relative to the external storage
directoryjava.io.IOException
- if we are unable to create necessary parent directories
or delete an existing fileFileUtil.FileException
- if the external storage is not writeable.public static void checkExternalStorageWriteable() throws FileUtil.FileException
FileUtil.FileException