Package org.robovm.libimobiledevice
Class AfcClient
java.lang.Object
org.robovm.libimobiledevice.AfcClient
- All Implemented Interfaces:
java.lang.AutoCloseable
public class AfcClient
extends java.lang.Object
implements java.lang.AutoCloseable
Provides access to the device filesystem.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAfcClient.UploadProgressCallback -
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEVICE_INFO_KEY_FS_BLOCK_SIZEstatic java.lang.StringDEVICE_INFO_KEY_FS_FREE_BYTESstatic java.lang.StringDEVICE_INFO_KEY_FS_TOTAL_BYTESstatic java.lang.StringDEVICE_INFO_KEY_MODELstatic java.lang.StringFILE_INFO_KEY_LINK_TARGETLink target.static java.lang.StringFILE_INFO_KEY_ST_BIRTHTIMECreation time in nanos.static java.lang.StringFILE_INFO_KEY_ST_BLOCKSNumber of blocks allocated for a file.static java.lang.StringFILE_INFO_KEY_ST_IFMTFile type.static java.lang.StringFILE_INFO_KEY_ST_MTIMELast modification time in nanos.static java.lang.StringFILE_INFO_KEY_ST_NLINKNumber of hard links.static java.lang.StringFILE_INFO_KEY_ST_SIZEFile size in bytes.protected AfcClientRefrefstatic java.lang.StringSERVICE_NAME -
Constructor Summary
Constructors Constructor Description AfcClient(IDevice device, LockdowndServiceDescriptor service)Creates a newAfcClientand makes a connection to thecom.apple.afcservice on the device. -
Method Summary
Modifier and Type Method Description protected voidcheckDisposed()voidclose()voiddispose()voidfileClose(long handle)Closes a file on the device.voidfileCopy(java.io.File localFile, java.lang.String remoteFile)Copies the specified localFileto the specified remote file.longfileOpen(java.lang.String path, AfcFileMode mode)Opens a file on the device.intfileRead(long handle, byte[] buffer, int offset, int count)Attempts to the read the given number of bytes from the given file.intfileWrite(long handle, byte[] buffer, int offset, int count)Writes a given number of bytes to a file.intgetBlockSize()Returns the disk partition blocksize.java.util.Map<java.lang.String,java.lang.String>getDeviceInfo()Retrieves device information.java.util.Map<java.lang.String,java.lang.String>getFileInfo(java.lang.String path)Retrieves information for a specific file or directory.longgetFreeBytes()Returns the free space on the device in bytes.java.lang.StringgetModel()Returns the name of the device model.protected AfcClientRefgetRef()longgetTotalBytes()Returns the total size of the device in bytes.static voidmain(java.lang.String[] args)voidmakeDirectory(java.lang.String dir)Creates a directory on the device.voidmakeLink(AfcLinkType type, java.lang.String target, java.lang.String source)Creates a hard link or symbolic link on the device.java.lang.String[]readDirectory(java.lang.String dir)Returns a directory listing of the specified directory.voidremovePath(java.lang.String path)Deletes a file or an empty directory.voidremovePath(java.lang.String path, boolean recurse)Deletes a file or a directory hierarchy.voidrenamePath(java.lang.String from, java.lang.String to)Renames a file or directory on the device.voidupload(java.io.File localFile, java.lang.String targetPath)Uploads a local file or directory to the device.voidupload(java.io.File localFile, java.lang.String targetPath, AfcClient.UploadProgressCallback callback)Uploads a local file or directory to the device.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
SERVICE_NAME
public static final java.lang.String SERVICE_NAME- See Also:
- Constant Field Values
-
DEVICE_INFO_KEY_FS_TOTAL_BYTES
public static final java.lang.String DEVICE_INFO_KEY_FS_TOTAL_BYTES- See Also:
- Constant Field Values
-
DEVICE_INFO_KEY_FS_FREE_BYTES
public static final java.lang.String DEVICE_INFO_KEY_FS_FREE_BYTES- See Also:
- Constant Field Values
-
DEVICE_INFO_KEY_FS_BLOCK_SIZE
public static final java.lang.String DEVICE_INFO_KEY_FS_BLOCK_SIZE- See Also:
- Constant Field Values
-
DEVICE_INFO_KEY_MODEL
public static final java.lang.String DEVICE_INFO_KEY_MODEL- See Also:
- Constant Field Values
-
FILE_INFO_KEY_ST_BIRTHTIME
public static final java.lang.String FILE_INFO_KEY_ST_BIRTHTIMECreation time in nanos.- See Also:
- Constant Field Values
-
FILE_INFO_KEY_ST_MTIME
public static final java.lang.String FILE_INFO_KEY_ST_MTIMELast modification time in nanos.- See Also:
- Constant Field Values
-
FILE_INFO_KEY_ST_BLOCKS
public static final java.lang.String FILE_INFO_KEY_ST_BLOCKSNumber of blocks allocated for a file.- See Also:
- Constant Field Values
-
FILE_INFO_KEY_ST_NLINK
public static final java.lang.String FILE_INFO_KEY_ST_NLINKNumber of hard links.- See Also:
- Constant Field Values
-
FILE_INFO_KEY_ST_SIZE
public static final java.lang.String FILE_INFO_KEY_ST_SIZEFile size in bytes.- See Also:
- Constant Field Values
-
FILE_INFO_KEY_ST_IFMT
public static final java.lang.String FILE_INFO_KEY_ST_IFMTFile type.S_IFREGfor regular files.S_IFDIRfor directories.S_IFLNKfor links.- See Also:
- Constant Field Values
-
FILE_INFO_KEY_LINK_TARGET
public static final java.lang.String FILE_INFO_KEY_LINK_TARGETLink target.- See Also:
- Constant Field Values
-
ref
-
-
Constructor Details
-
AfcClient
Creates a newAfcClientand makes a connection to thecom.apple.afcservice on the device.- Parameters:
device- the device to connect to.service- the service descriptor returned byLockdowndClient.startService(String).
-
-
Method Details
-
readDirectory
public java.lang.String[] readDirectory(java.lang.String dir)Returns a directory listing of the specified directory.- Parameters:
dir- the directory to list. Must be a fully-qualified path.- Returns:
- the list of files in the specified directory.
-
getDeviceInfo
public java.util.Map<java.lang.String,java.lang.String> getDeviceInfo()Retrieves device information. The information returned is the device model as well as the free space, the total capacity and blocksize on the accessed disk partition.- Returns:
- the device info as key-value pairs. Possible keys are:
DEVICE_INFO_KEY_MODEL,DEVICE_INFO_KEY_FS_FREE_BYTES,DEVICE_INFO_KEY_FS_TOTAL_BYTES,DEVICE_INFO_KEY_FS_BLOCK_SIZE.
-
getBlockSize
public int getBlockSize()Returns the disk partition blocksize.- Returns:
- the blocksize.
- See Also:
getDeviceInfo()
-
getFreeBytes
public long getFreeBytes()Returns the free space on the device in bytes.- Returns:
- the free space in bytes.
- See Also:
getDeviceInfo()
-
getTotalBytes
public long getTotalBytes()Returns the total size of the device in bytes.- Returns:
- the total size in bytes.
- See Also:
getDeviceInfo()
-
getModel
public java.lang.String getModel()Returns the name of the device model.- Returns:
- the device model name.
- See Also:
getDeviceInfo()
-
getFileInfo
public java.util.Map<java.lang.String,java.lang.String> getFileInfo(java.lang.String path)Retrieves information for a specific file or directory.- Parameters:
path- the path of the file or directory.- Returns:
- the file information as key-value pairs. Possible keys are:
FILE_INFO_KEY_ST_BIRTHTIME,FILE_INFO_KEY_ST_BLOCKS,FILE_INFO_KEY_ST_IFMT,FILE_INFO_KEY_ST_MTIME,FILE_INFO_KEY_ST_NLINK,FILE_INFO_KEY_ST_SIZE.
-
fileOpen
Opens a file on the device.- Parameters:
path- the fully-qualified path of the file to open.mode- the mode to use to open the file.- Returns:
- the handle to the open file.
-
fileClose
public void fileClose(long handle)Closes a file on the device.- Parameters:
handle- file handle of a previously opened file.
-
fileRead
public int fileRead(long handle, byte[] buffer, int offset, int count)Attempts to the read the given number of bytes from the given file.- Parameters:
handle- file handle of a previously opened filebuffer- the byte array in which to store the bytes read.offset- the initial position inbufferto store the bytes read from the file.count- the maximum number of bytes to store inbuffer.- Returns:
- the number of bytes actually read or -1 if the end of the stream has been reached.
-
fileWrite
public int fileWrite(long handle, byte[] buffer, int offset, int count)Writes a given number of bytes to a file.- Parameters:
handle- file handle of previously opened file.buffer- the buffer to be written.offset- the start position inbufferfrom where to get bytes.count- the number of bytes frombufferto write to the file.- Returns:
- the number of bytes actually written to the file.
-
fileCopy
public void fileCopy(java.io.File localFile, java.lang.String remoteFile) throws java.io.IOExceptionCopies the specified localFileto the specified remote file.- Parameters:
localFile- theFileto copy.remoteFile- the path to the remote file.- Throws:
java.io.IOException
-
removePath
public void removePath(java.lang.String path)Deletes a file or an empty directory.- Parameters:
path- the fully-qualified path to delete.
-
removePath
public void removePath(java.lang.String path, boolean recurse)Deletes a file or a directory hierarchy.- Parameters:
path- the fully-qualified path to delete.recurse- iftruenon-empty directories will be deleted recursively.
-
renamePath
public void renamePath(java.lang.String from, java.lang.String to)Renames a file or directory on the device.- Parameters:
from- the fully-qualified path of the file or directory to rename.to- the fully-qualified path the file or directory should be renamed to.
-
makeDirectory
public void makeDirectory(java.lang.String dir)Creates a directory on the device. Does nothing if the directory already exists. Also creates parent directories recursively.- Parameters:
dir- the fully-qualified path of the directory to create.
-
makeLink
Creates a hard link or symbolic link on the device.- Parameters:
type- the type of link to create.target- the absolute or relative path of the link target.source- the fully-qualified path where the link will be created.
-
upload
public void upload(java.io.File localFile, java.lang.String targetPath) throws java.io.IOExceptionUploads a local file or directory to the device.- Parameters:
localFile- the file or directory to upload.targetPath- the path of the directory on the device where to place the uploaded files.- Throws:
java.io.IOException
-
upload
public void upload(java.io.File localFile, java.lang.String targetPath, AfcClient.UploadProgressCallback callback) throws java.io.IOExceptionUploads a local file or directory to the device.- Parameters:
localFile- the file or directory to upload.targetPath- the path of the directory on the device where to place the uploaded files.callback- callback which will receive progress and status updates. Ifnullno progress will be reported.- Throws:
java.io.IOException
-
getRef
-
checkDisposed
protected final void checkDisposed() -
dispose
public void dispose() -
close
public void close()- Specified by:
closein interfacejava.lang.AutoCloseable
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-