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 interface  AfcClient.UploadProgressCallback  
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String DEVICE_INFO_KEY_FS_BLOCK_SIZE  
    static java.lang.String DEVICE_INFO_KEY_FS_FREE_BYTES  
    static java.lang.String DEVICE_INFO_KEY_FS_TOTAL_BYTES  
    static java.lang.String DEVICE_INFO_KEY_MODEL  
    static java.lang.String FILE_INFO_KEY_LINK_TARGET
    Link target.
    static java.lang.String FILE_INFO_KEY_ST_BIRTHTIME
    Creation time in nanos.
    static java.lang.String FILE_INFO_KEY_ST_BLOCKS
    Number of blocks allocated for a file.
    static java.lang.String FILE_INFO_KEY_ST_IFMT
    File type.
    static java.lang.String FILE_INFO_KEY_ST_MTIME
    Last modification time in nanos.
    static java.lang.String FILE_INFO_KEY_ST_NLINK
    Number of hard links.
    static java.lang.String FILE_INFO_KEY_ST_SIZE
    File size in bytes.
    protected AfcClientRef ref  
    static java.lang.String SERVICE_NAME  
  • Constructor Summary

    Constructors
    Constructor Description
    AfcClient​(IDevice device, LockdowndServiceDescriptor service)
    Creates a new AfcClient and makes a connection to the com.apple.afc service on the device.
  • Method Summary

    Modifier and Type Method Description
    protected void checkDisposed()  
    void close()  
    void dispose()  
    void fileClose​(long handle)
    Closes a file on the device.
    void fileCopy​(java.io.File localFile, java.lang.String remoteFile)
    Copies the specified local File to the specified remote file.
    long fileOpen​(java.lang.String path, AfcFileMode mode)
    Opens a file on the device.
    int fileRead​(long handle, byte[] buffer, int offset, int count)
    Attempts to the read the given number of bytes from the given file.
    int fileWrite​(long handle, byte[] buffer, int offset, int count)
    Writes a given number of bytes to a file.
    int getBlockSize()
    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.
    long getFreeBytes()
    Returns the free space on the device in bytes.
    java.lang.String getModel()
    Returns the name of the device model.
    protected AfcClientRef getRef()  
    long getTotalBytes()
    Returns the total size of the device in bytes.
    static void main​(java.lang.String[] args)  
    void makeDirectory​(java.lang.String dir)
    Creates a directory on the device.
    void makeLink​(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.
    void removePath​(java.lang.String path)
    Deletes a file or an empty directory.
    void removePath​(java.lang.String path, boolean recurse)
    Deletes a file or a directory hierarchy.
    void renamePath​(java.lang.String from, java.lang.String to)
    Renames a file or directory on the device.
    void upload​(java.io.File localFile, java.lang.String targetPath)
    Uploads a local file or directory to the device.
    void upload​(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_BIRTHTIME
      Creation time in nanos.
      See Also:
      Constant Field Values
    • FILE_INFO_KEY_ST_MTIME

      public static final java.lang.String FILE_INFO_KEY_ST_MTIME
      Last modification time in nanos.
      See Also:
      Constant Field Values
    • FILE_INFO_KEY_ST_BLOCKS

      public static final java.lang.String FILE_INFO_KEY_ST_BLOCKS
      Number of blocks allocated for a file.
      See Also:
      Constant Field Values
    • FILE_INFO_KEY_ST_SIZE

      public static final java.lang.String FILE_INFO_KEY_ST_SIZE
      File size in bytes.
      See Also:
      Constant Field Values
    • FILE_INFO_KEY_ST_IFMT

      public static final java.lang.String FILE_INFO_KEY_ST_IFMT
      File type. S_IFREG for regular files. S_IFDIR for directories. S_IFLNK for links.
      See Also:
      Constant Field Values
    • ref

      protected AfcClientRef ref
  • Constructor Details

  • 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

      public long fileOpen​(java.lang.String path, AfcFileMode mode)
      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 file
      buffer - the byte array in which to store the bytes read.
      offset - the initial position in buffer to store the bytes read from the file.
      count - the maximum number of bytes to store in buffer.
      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 in buffer from where to get bytes.
      count - the number of bytes from buffer to 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.IOException
      Copies the specified local File to the specified remote file.
      Parameters:
      localFile - the File to 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 - if true non-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

      public void makeLink​(AfcLinkType type, java.lang.String target, java.lang.String source)
      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.IOException
      Uploads 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.IOException
      Uploads 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. If null no progress will be reported.
      Throws:
      java.io.IOException
    • getRef

      protected AfcClientRef getRef()
    • checkDisposed

      protected final void checkDisposed()
    • dispose

      public void dispose()
    • close

      public void close()
      Specified by:
      close in interface java.lang.AutoCloseable
    • main

      public static void main​(java.lang.String[] args) throws java.lang.Exception
      Throws:
      java.lang.Exception