Apple Java Extensions

com.apple.eio
Class FileManager

java.lang.Object
  extended by com.apple.eio.FileManager

public class FileManager
extends java.lang.Object

Provides functionality to query and modify Mac-specific file attributes. The methods in this class are based on Finder attributes. These attributes in turn are dependent on HFS and HFS+ file systems. As such, it is important to recognize their limitation when writing code that must function well across multiple platforms.

In addition to file name suffixes, Mac OS X can use Finder attributes like file type and creator codes to identify and handle files. These codes are unique 4-byte identifiers. The file type is a string that describes the contents of a file. For example, the file type APPL identifies the file as an application and therefore executable. A file type of TEXT means that the file contains raw text. Any application that can read raw text can open a file of type TEXT. Applications that use proprietary file types might assign their files a proprietary file type code.

To identify the application that can handle a document, the Finder can look at the creator. For example, if a user double-clicks on a document with the ttxt creator, it opens up in Text Edit, the application registered with the ttxt creator code. Note that the creator code should possibly assigned not to match not the application that created a document but the application that should ultimately handle the document. For example, if you use an editor to create an HTML document, you might want to assign a browser's creator code for the file rather than the HTML editor's creator code. Double-clicking on the document then opens the appropriate browser rather than the HTML editor.

If you plan to publicly distribute your application, you must register its creator and any proprietary file types with the Apple Developer Connection to avoid collisions with codes used by other developers. You can register a codes online at the Creator Code Registration site.


Field Summary
static short kLocalDomain
          All users of a single machine have access to these resources.
static short kNetworkDomain
          All users configured to use a common network server has access to these resources.
static short kOnAppropriateDisk
          The default
static short kSystemDomain
          Read-only system hierarchy.
static short kUserDomain
          Read/write.
 
Constructor Summary
FileManager()
           
 
Method Summary
static java.lang.String findFolder(int folderType)
          Locates a folder of a particular type.
static java.lang.String findFolder(short domain, int folderType)
          Locates a folder of a particular type, within a given domain.
static java.lang.String findFolder(short domain, int folderType, boolean createIfNeeded)
          Locates a folder of a particular type within a given domain and optionally creating the folder if it does not exist.
static int getFileCreator(java.lang.String filename)
          Obtains the file creator code for a file or folder.
static int getFileType(java.lang.String filename)
          Obtains the file type code for a file or folder.
static java.lang.String getResource(java.lang.String resourceName)
          Documentation Forthcoming
static java.lang.String getResource(java.lang.String resourceName, java.lang.String subDirName)
          Documentation Forthcoming
static void openURL(java.lang.String url)
          Opens the path specified by a URL in the appropriate application for that URL.
static int OSTypeToInt(java.lang.String type)
          Converts an OSType (e.g.
static void setFileCreator(java.lang.String filename, int creator)
          Sets the file creator code for a file or folder.
static void setFileType(java.lang.String filename, int type)
          Sets the file type code for a file or folder.
static void setFileTypeAndCreator(java.lang.String filename, int type, int creator)
          Sets the file type and creator codes for a file or folder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kOnAppropriateDisk

public static final short kOnAppropriateDisk
The default

See Also:
Constant Field Values

kSystemDomain

public static final short kSystemDomain
Read-only system hierarchy.

See Also:
Constant Field Values

kLocalDomain

public static final short kLocalDomain
All users of a single machine have access to these resources.

See Also:
Constant Field Values

kNetworkDomain

public static final short kNetworkDomain
All users configured to use a common network server has access to these resources.

See Also:
Constant Field Values

kUserDomain

public static final short kUserDomain
Read/write. Resources that are private to the user.

See Also:
Constant Field Values
Constructor Detail

FileManager

public FileManager()
Method Detail

OSTypeToInt

public static int OSTypeToInt(java.lang.String type)
Converts an OSType (e.g. "macs" from ) into an int.

Parameters:
type - the 4 character type to convert.
Returns:
an int representing the 4 character value
Since:
1.6

setFileTypeAndCreator

public static void setFileTypeAndCreator(java.lang.String filename,
                                         int type,
                                         int creator)
                                  throws java.io.IOException
Sets the file type and creator codes for a file or folder.

Throws:
java.io.IOException

setFileType

public static void setFileType(java.lang.String filename,
                               int type)
                        throws java.io.IOException
Sets the file type code for a file or folder.

Throws:
java.io.IOException

setFileCreator

public static void setFileCreator(java.lang.String filename,
                                  int creator)
                           throws java.io.IOException
Sets the file creator code for a file or folder.

Throws:
java.io.IOException

getFileType

public static int getFileType(java.lang.String filename)
                       throws java.io.IOException
Obtains the file type code for a file or folder.

Throws:
java.io.IOException

getFileCreator

public static int getFileCreator(java.lang.String filename)
                          throws java.io.IOException
Obtains the file creator code for a file or folder.

Throws:
java.io.IOException

findFolder

public static java.lang.String findFolder(int folderType)
                                   throws java.io.FileNotFoundException
Locates a folder of a particular type. Mac OS X recognizes certain specific folders that have distinct purposes. For example, the user's desktop or temporary folder. These folders have corresponding codes. Given one of these codes, this method returns the path to that particular folder. Certain folders of a given type may appear in more than one domain. For example, although there is only one root folder, there are multiple pref folders. If this method is called to find the pref folder, it will return the first one it finds, the user's preferences folder in ~/Library/Preferences. To explicitly locate a folder in a certain domain use findFolder(short domain, int folderType) or findFolder(short domain, int folderType, boolean createIfNeeded).

Returns:
the path to the folder searched for
Throws:
java.io.FileNotFoundException

findFolder

public static java.lang.String findFolder(short domain,
                                          int folderType)
                                   throws java.io.FileNotFoundException
Locates a folder of a particular type, within a given domain. Similar to findFolder(int folderType) except that the domain to look in can be specified. Valid values for domaininclude:
user
The User domain contains resources specific to the user who is currently logged in
local
The Local domain contains resources shared by all users of the system but are not needed for the system itself to run.
network
The Network domain contains resources shared by users of a local area network.
system
The System domain contains the operating system resources installed by Apple.

Returns:
the path to the folder searched for
Throws:
java.io.FileNotFoundException

findFolder

public static java.lang.String findFolder(short domain,
                                          int folderType,
                                          boolean createIfNeeded)
                                   throws java.io.FileNotFoundException
Locates a folder of a particular type within a given domain and optionally creating the folder if it does not exist. The behavior is similar to findFolder(int folderType) and findFolder(short domain, int folderType) except that it can create the folder if it does not already exist.

Parameters:
createIfNeeded - set to true, by setting to false the behavior will be the same as findFolder(short domain, int folderType, boolean createIfNeeded)
Returns:
the path to the folder searched for
Throws:
java.io.FileNotFoundException

openURL

public static void openURL(java.lang.String url)
                    throws java.io.IOException
Opens the path specified by a URL in the appropriate application for that URL. HTTP URL's (http://) open in the default browser as set in the Internet pane of System Preferences. File (file://) and FTP URL's (ftp://) open in the Finder. Note that opening an FTP URL will prompt the user for where they want to save the downloaded file(s).

Parameters:
url - the URL for the file you want to open, it can either be an HTTP, FTP, or file url
Throws:
java.io.IOException

getResource

public static java.lang.String getResource(java.lang.String resourceName)
                                    throws java.io.FileNotFoundException
Documentation Forthcoming

Returns:
a string that describes the requested resource
Throws:
java.io.FileNotFoundException

getResource

public static java.lang.String getResource(java.lang.String resourceName,
                                           java.lang.String subDirName)
                                    throws java.io.FileNotFoundException
Documentation Forthcoming

Throws:
java.io.FileNotFoundException

Apple Java Extensions

To file bugs or suggest feature enhancements for the Java implementation in Mac OS X, visit the Apple Developer Connection Bug Reporter website. File bugs under the Java (new bugs) component, version X.

Additional documentation for Java development on Mac OS X is available online at the Java Developer Documentation website.

© Apple Computer, Inc. March 2008