Package com.unitech.api.file
Class FileCtrl
- java.lang.Object
-
- com.unitech.api.file.FileCtrl
-
public class FileCtrl extends java.lang.ObjectThis controller is used to read / write file to storage with system permission.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBUNDLE_DATAstatic java.lang.StringBUNDLE_ERROR_CODEstatic java.lang.StringBUNDLE_ERROR_MSGstatic java.lang.StringBUNDLE_FILE_STREAM_IDstatic java.lang.StringBUNDLE_PARCEL_FILE_DESCRIPTORstatic intRESULT_CODE_ERRORstatic intRESULT_CODE_SUCCESS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description android.os.BundlecanRead(java.lang.String path)Tests whether the application can read the file denoted by this abstract pathname.android.os.BundlecanWrite(java.lang.String path)Tests whether the application can modify the file denoted by this abstract pathname.android.os.BundlecloseFileStream(long fileStreamId)Close the specific file stream that created by FileCtrl.createFileStream.android.os.BundlecopyFile(java.lang.String fromPath, java.lang.String toPath)Copy file bundle.android.os.BundlecreateFile(java.lang.String path)Create file or folder on deviceandroid.os.BundlecreateFileStream(java.lang.String filepath, boolean keepContents)Create a stream that you can use the stream to read or write data into the file.
If you have completed your operation on this stream, you should call FileCtrl.closeFileStream(fileStreamId) to close this stream.android.os.BundledeleteFile(java.lang.String path)Deletes the file or folder.android.os.Bundleexists(java.lang.String path)Check if the file or folder exists.static FileCtrlgetInstance(android.content.Context context)Gets instance.android.os.BundleisDirectory(java.lang.String path)Check if path is directory.android.os.Bundlelist(java.lang.String path)Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.android.os.BundleopenFile(java.lang.String path)open file for the given package name and pathandroid.os.BundlereadFromFile(java.lang.String path)Read from file.android.os.BundlerenameTo(java.lang.String path, java.lang.String newName)Renames the file denoted by this name.android.os.BundlewriteToFile(java.lang.String path, byte[] content)Write to file with byte[]android.os.BundlewriteUTF8ToFile(java.lang.String path, java.lang.String content)Write String(utf8) to file.
-
-
-
Field Detail
-
BUNDLE_ERROR_CODE
public static final java.lang.String BUNDLE_ERROR_CODE
- See Also:
- Constant Field Values
-
BUNDLE_ERROR_MSG
public static final java.lang.String BUNDLE_ERROR_MSG
- See Also:
- Constant Field Values
-
BUNDLE_DATA
public static final java.lang.String BUNDLE_DATA
- See Also:
- Constant Field Values
-
BUNDLE_PARCEL_FILE_DESCRIPTOR
public static final java.lang.String BUNDLE_PARCEL_FILE_DESCRIPTOR
- See Also:
- Constant Field Values
-
BUNDLE_FILE_STREAM_ID
public static final java.lang.String BUNDLE_FILE_STREAM_ID
- See Also:
- Constant Field Values
-
RESULT_CODE_ERROR
public static final int RESULT_CODE_ERROR
- See Also:
- Constant Field Values
-
RESULT_CODE_SUCCESS
public static final int RESULT_CODE_SUCCESS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static FileCtrl getInstance(android.content.Context context)
Gets instance.- Parameters:
context- the context- Returns:
- the instance
-
writeUTF8ToFile
public android.os.Bundle writeUTF8ToFile(java.lang.String path, java.lang.String content)Write String(utf8) to file.- Parameters:
path- the path (String)content- the content (String)- Returns:
- A bundle contains the error code and message
int erroeCode = bundle.getInt("errorCode"), (error:1, success=0)
String errorMsg = bundle.getString("errorMsg");
-
writeToFile
public android.os.Bundle writeToFile(java.lang.String path, byte[] content)Write to file with byte[]- Parameters:
path- the path (String)content- the content (String)- Returns:
- A bundle contains the error code and message
int erroeCode = bundle.getInt("errorCode"), (error:1, success=0)
String errorMsg = bundle.getString("errorMsg");
-
readFromFile
public android.os.Bundle readFromFile(java.lang.String path)
Read from file.- Parameters:
path- the path (String)- Returns:
- A bundle contains the error code and message
int erroeCode = bundle.getInt("errorCode"), (error:1, success=0)
String errorMsg = bundle.getString("errorMsg");
-
copyFile
public android.os.Bundle copyFile(java.lang.String fromPath, java.lang.String toPath)Copy file bundle.- Parameters:
fromPath- the from path (String)toPath- the to path (String)- Returns:
- A bundle contains the error code and message
int erroeCode = bundle.getInt("errorCode"), (error:1, success=0)
String errorMsg = bundle.getString("errorMsg");
-
createFile
public android.os.Bundle createFile(java.lang.String path)
Create file or folder on device- Parameters:
path- The path of file or folder. If you want to create folder, the path should end with "/" like "/sdcard/newfolder/" (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (error:1, success=0)
String errorMsg = bundle.getString("errorMsg");
-
deleteFile
public android.os.Bundle deleteFile(java.lang.String path)
Deletes the file or folder. If this pathname denotes a folder, then the folder must be empty in order to be deleted.- Parameters:
path- The path of file or folder. (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (error:1, success=0)
String errorMsg = bundle.getString("errorMsg");
-
createFileStream
public android.os.Bundle createFileStream(java.lang.String filepath, boolean keepContents)Create a stream that you can use the stream to read or write data into the file.
If you have completed your operation on this stream, you should call FileCtrl.closeFileStream(fileStreamId) to close this stream.- Parameters:
filepath- The file path that you want to make a stream on it. (String)keepContents- Whether you want to keep the file contents. If you want to read data from the stream, you should set keepContents as true. (true: keep, false: erase file) (boolean)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (error:1, success=0)
String errorMsg = bundle.getString("errorMsg");
ParcelFileDescriptor pfd = bundle.getParcelable(FileCtrl.BUNDLE_PARCEL_FILE_DESCRIPTOR);
long fileStreamId = bundle.getLong(FileCtrl.BUNDLE_FILE_STREAM_ID);
-
closeFileStream
public android.os.Bundle closeFileStream(long fileStreamId)
Close the specific file stream that created by FileCtrl.createFileStream.- Parameters:
fileStreamId- The file stream ID that you want to close. (long)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (error:1, success=0)
String errorMsg = bundle.getString("errorMsg");
-
exists
public android.os.Bundle exists(java.lang.String path)
Check if the file or folder exists.- Parameters:
path- The path of the file or folder. (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (1: file or folder does not exist, 0: file or folder exists)
String errorMsg = bundle.getString("errorMsg");
-
isDirectory
public android.os.Bundle isDirectory(java.lang.String path)
Check if path is directory.- Parameters:
path- The path of the file or folder. (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (1: path is not directory, 0: path is directory)
String errorMsg = bundle.getString("errorMsg");
-
openFile
public android.os.Bundle openFile(java.lang.String path)
open file for the given package name and path- Parameters:
path- The path of the file. (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (1: Cannot open the file, 0: success to open the file)
String errorMsg = bundle.getString("errorMsg");
-
list
public android.os.Bundle list(java.lang.String path)
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.- Parameters:
path- The path of the file or folder. (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (1: list is null, 0: list is not null)
String errorMsg = bundle.getString("errorMsg");
-
renameTo
public android.os.Bundle renameTo(java.lang.String path, java.lang.String newName)Renames the file denoted by this name.- Parameters:
path- The path of the file or folder. (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (1: fail, 0: success)
String errorMsg = bundle.getString("errorMsg");
-
canWrite
public android.os.Bundle canWrite(java.lang.String path)
Tests whether the application can modify the file denoted by this abstract pathname.- Parameters:
path- The path of the file or folder. (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (1: fail, 0: success)
String errorMsg = bundle.getString("errorMsg");
-
canRead
public android.os.Bundle canRead(java.lang.String path)
Tests whether the application can read the file denoted by this abstract pathname.- Parameters:
path- The path of the file or folder. (String)- Returns:
- A bundle contains the error code and message
int errorCode = bundle.getInt("errorCode"), (1: fail, 0: success)
String errorMsg = bundle.getString("errorMsg");
-
-