|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.hunnysoft.jmime.AppleFile
Class for packing and unpacking AppleSingle and AppleDouble data.
AppleFile packs or unpacks file data to or from
AppleSingle or AppleDouble format. The AppleSingle format allows a
file's contents to be packed together with related file information,
such as file dates, resources, icons, and so forth, into a single file.
The AppleDouble format is similar, but different in that the file's
contents are stored in one file, and the remaining file information
(dates, resources, icons, and so forth) is stored in a separate
AppleDouble header file.
In the MIME world, AppleSingle and AppleDouble are the preferred ways to transfer Macintosh files, with AppleDouble preferred over AppleSingle where possible. In actual practice, the BinHex format is common (most likely due to the fact that most Macintosh archives store files in BinHex format). The use of AppleSingle and AppleDouble in MIME is described in RFC 1740 and is referred to as MacMIME. MacMIME is an official Internet standards track protocol.
To use AppleFile for packing file data to the
AppleDouble header format, first call
setFormat(AppleFile.APPLE_DOUBLE_HEADER) to set the format
type to AppleDouble header, then call one or more of the following
methods to set the file data: setFileName(),
setCreateTime(), setModifyTime(),
setBackupTime(), setAccessTime()
setResourceFork(). Next, call the pack()
method to pack all the file information into a single buffer. Finally,
call packedData() to get the packed AppleDouble header
data.
To use AppleFile for packing file data to the
AppleSingle format, first call
setFormat(AppleFile.APPLE_SINGLE) to set the format type to
AppleSingle, then call one or more of the following methods to set the
file data: setFileName(), setCreateTime(),
setModifyTime(), setBackupTime(),
setAccessTime() setResourceFork(),
setDataFork(). Next, call the pack() method
to pack all the file information into a single buffer. Finally, call
packedData() to get the packed AppleSingle data.
To use AppleFile to unpack AppleSingle or AppleDouble
file data, first call setPackedData() to set the packed
data into the AppleFile object. Then call the
unpack() method to unpack the file data. Finally, call
format(), fileName(),
createTime(), and other methods to get the file data.
Note: The definitive reference for AppleSingle and AppleDouble is AppleSingle/AppleDouble Formats: Developer's Note, available from Apple Computer.
| Field Summary | |
static int |
APPLE_DOUBLE_HEADER
|
static int |
APPLE_SINGLE
|
static int |
BAD_MAGIC_NUMBER
|
static int |
CORRUPT_DATA
|
static int |
NO_ERROR
|
static int |
TOO_SHORT
|
static int |
WRONG_VERSION
|
| Constructor Summary | |
AppleFile()
Default constructor. |
|
| Method Summary | |
int |
accessTime()
Gets the access time. |
static int |
appleFileTimeToUnixTime(int afTime)
Converts from AppleFile time to Unix time. |
int |
backupTime()
Gets the backup time. |
int |
createTime()
Gets the create time. |
ByteString |
dataFork()
Gets the data fork. |
ByteString |
fileName()
Gets the file name. |
int |
format()
Gets the format type. |
boolean |
hasDataFork()
Returns true if the AppleFile data contains a data fork entry. |
boolean |
hasFileName()
Returns true if the AppleFile data contains a file name. |
boolean |
hasFileTimes()
Returns true if the AppleFile data contains a file times entry. |
boolean |
hasResourceFork()
Returns true if the AppleFile data contains a Macintosh resource fork entry. |
int |
modifyTime()
Gets the modify time. |
void |
pack()
Packs the file data into a single buffer. |
ByteString |
packedData()
Gets the buffer of packed file data. |
ByteString |
resourceFork()
Gets the resource fork. |
void |
setAccessTime(int time)
Sets the access time. |
void |
setBackupTime(int time)
Sets the backup time. |
void |
setCreateTime(int time)
Sets the create time. |
void |
setDataFork(ByteString bytes)
Sets the data fork. |
void |
setFileName(ByteString name)
Sets the file name. |
void |
setFormat(int formatType)
Sets the format type. |
void |
setModifyTime(int time)
Sets the modify time. |
void |
setPackedData(ByteString str)
Sets the buffer of packed file data. |
void |
setResourceFork(ByteString bytes)
Sets the resource fork. |
static int |
unixTimeToAppleFileTime(int unixTime)
Converts from Unix time to AppleFile time. |
void |
unpack()
Unpacks the packed file data. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int NO_ERROR
public static final int TOO_SHORT
public static final int BAD_MAGIC_NUMBER
public static final int WRONG_VERSION
public static final int CORRUPT_DATA
public static final int APPLE_SINGLE
public static final int APPLE_DOUBLE_HEADER
| Constructor Detail |
public AppleFile()
| Method Detail |
public int format()
The format type can be AppleFile.APPLE_SINGLE or
AppleFile.APPLE_DOUBLE_HEADER.
When using AppleFile to unpack file data, the
format type is determined by interpreting a magic number in the
packed data.
The AppleDouble header and AppleSingle formats are almost identical. They are different in two ways: the magic number is different, and an AppleDouble header is not permitted to contain a data fork.
AppleFile.APPLE_SINGLE or
AppleFile.APPLE_DOUBLE_HEADERpublic void setFormat(int formatType)
When using AppleFile to pack file data, you should
set a format type of AppleFile.APPLE_SINGLE or
AppleFile.APPLE_DOUBLE_HEADER. When using
AppleFile to unpack file data, the format type is
determined by interpreting a magic number in the packed data.
The AppleDouble header and AppleSingle formats are almost identical. They are different in two ways: the magic number is different, and an AppleDouble header is not permitted to contain a data fork.
formatType - AppleFile.APPLE_SINGLE or
AppleFile.APPLE_DOUBLE_HEADERpublic boolean hasFileName()
If the AppleFile data contains a file name, you may get the file
name by calling fileName().
public ByteString fileName()
This method always returns a valid reference -- it never returns
null. If there is no file name, the method returns a
zero-length ByteString.
public void setFileName(ByteString name)
name - file namepublic boolean hasFileTimes()
If the AppleFile data contains a file times entry, you may get
the file times by calling createTime(),
modifyTime(), backupTime(), and
accessTime().
If a file times entry is present, that does not mean that all
the times (create time, modify time, backup time, and access time)
are valid. An invalid time is indicated by a value of
Integer.MIN_VALUE.
public int createTime()
The create time is the time that the file was created.
A file time's value represents the number of seconds before or
after 1 Jan 2000 00:00:00 UTC. The value 0
represents 1 Jan 2000 00:00:00 UTC; a negative time
represents the number of seconds until 1 Jan 2000
00:00:00 UTC; and a positive value represents the number of
seconds after 1 Jan 2000 00:00:00 UTC. The
value Integer.MIN_VALUE is a special value that
indicates an invalid value.
You may use the methods unixTimeToAppleFileTime()
and appleFileTimeToUnixTime() to convert between the
apple file time representation (signed number of seconds since
1 Jan 2000) and the Unix time representation (unsigned
number of seconds since 1 Jan 1970).
public void setCreateTime(int time)
The create time is the time that the file was created.
time - the file create timepublic int modifyTime()
The modify time is the time the file was last modified.
A file time's value represents the number of seconds before or
after 1 Jan 2000 00:00:00 UTC. The value 0
represents 1 Jan 2000 00:00:00 UTC; a negative time
represents the number of seconds until 1 Jan 2000
00:00:00 UTC; and a positive value represents the number of
seconds after 1 Jan 2000 00:00:00 UTC. The
value Integer.MIN_VALUE is a special value that
indicates an invalid value.
You may use the methods unixTimeToAppleFileTime()
and appleFileTimeToUnixTime() to convert between the
apple file time representation (signed number of seconds since
1 Jan 2000) and the Unix time representation (unsigned
number of seconds since 1 Jan 1970).
public void setModifyTime(int time)
The modify time is the time the file was last modified.
time - the file modify timepublic int backupTime()
The backup time is the time the file was last saved to a backup medium.
A file time's value represents the number of seconds before or
after 1 Jan 2000 00:00:00 UTC. The value 0
represents 1 Jan 2000 00:00:00 UTC; a negative time
represents the number of seconds until 1 Jan 2000
00:00:00 UTC; and a positive value represents the number of
seconds after 1 Jan 2000 00:00:00 UTC. The
value Integer.MIN_VALUE is a special value that
indicates an invalid value.
You may use the methods unixTimeToAppleFileTime()
and appleFileTimeToUnixTime() to convert between the
apple file time representation (signed number of seconds since
1 Jan 2000) and the Unix time representation (unsigned
number of seconds since 1 Jan 1970).
public void setBackupTime(int time)
The backup time is the time the file was last saved to a backup medium.
time - the file backup timepublic int accessTime()
The access time is the time the file was last accessed.
A file time's value represents the number of seconds before or
after 1 Jan 2000 00:00:00 UTC. The value 0
represents 1 Jan 2000 00:00:00 UTC; a negative time
represents the number of seconds until 1 Jan 2000
00:00:00 UTC; and a positive value represents the number of
seconds after 1 Jan 2000 00:00:00 UTC. The
value Integer.MIN_VALUE is a special value that
indicates an invalid value.
You may use the methods unixTimeToAppleFileTime()
and appleFileTimeToUnixTime() to convert between the
apple file time representation (signed number of seconds since
1 Jan 2000) and the Unix time representation (unsigned
number of seconds since 1 Jan 1970).
public void setAccessTime(int time)
The access time is the time the file was last accessed.
time - the file access timepublic boolean hasDataFork()
If it does contain a data fork, you may get the data fork by
calling dataFork().
An AppleDouble header does not contain a data fork entry.
public ByteString dataFork()
The data fork contains the file's "data," such as the text in a text file, or the image data in a GIF file. In contrast, the resource fork contains resources that are used only by the Macintosh operating system (font information, code, icons, and so forth). An AppleDouble header does not contain a data fork entry.
This method always returns a valid reference -- it never returns
null. If there is no file name, the method returns a
zero-length ByteString.
public void setDataFork(ByteString bytes)
The data fork contains the file's "data," such as the text in a text file, or the image data in a GIF file. In contrast, the resource fork contains resources that are used only by the Macintosh operating system (font information, code, icons, and so forth). An AppleDouble header does not contain a data fork entry.
bytes - the bytes of the data forkpublic boolean hasResourceFork()
If it does contain a resource fork, you may get the resource
fork by calling resourceFork().
public ByteString resourceFork()
The resource fork contains resources that are used only by the Macintosh operating system (font information, code, icons, and so forth).
This method always returns a valid reference -- it never returns
null. If there is no file name, the method returns a
zero-length ByteString.
public void setResourceFork(ByteString bytes)
The resource fork contains resources that are used only by the Macintosh operating system (font information, code, icons, and so forth).
bytes - the bytes of the resource forkpublic ByteString packedData()
This method always returns a valid reference -- it never returns
null. If there is no file name, the method returns a
zero-length ByteString.
public void setPackedData(ByteString str)
str - packed file datapublic void pack()
After calling pack(), you may get the packed data
by calling packedData().
public void unpack()
throws DecodeException
Before calling unpack(), you should call
setPackedData() to set the buffer of packed file data.
After calling unpack(), you may call other methods to
retrieve the unpacked file information.
If an error occurs while unpacking, the method throws a
DecodeException.
DecodeException - -- if there is an error unpacking the datapublic static int unixTimeToAppleFileTime(int unixTime)
An Apple file time is defined to be the signed number of seconds before or after 1 Jan 2000 00:00:00 UTC. The value 0 represents 1 Jan 2000 00:00:00 UTC; a negative time represents the number of seconds until 1 Jan 2000 00:00:00 UTC; and a positive value represents the number of seconds after 1 Jan 2000 00:00:00 UTC. A Unix time is the number of seconds since 1 Jan 1970 00:00:00 UTC.
unixTime - a UNIX time
public static int appleFileTimeToUnixTime(int afTime)
An Apple file time is defined to be the signed number of seconds before or after 1 Jan 2000 00:00:00 UTC. The value 0 represents 1 Jan 2000 00:00:00 UTC; a negative time represents the number of seconds until 1 Jan 2000 00:00:00 UTC; and a positive value represents the number of seconds after 1 Jan 2000 00:00:00 UTC. A Unix time is the number of seconds since 1 Jan 1970 00:00:00 UTC.
afTime - an AppleFile time
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||