com.hunnysoft.jmime
Class BinHex

java.lang.Object
  extended bycom.hunnysoft.jmime.BinHex

public class BinHex
extends java.lang.Object

Class for converting files to or from BinHex format.

BinHex converts data to or from BinHex format. BinHex is a format used almost exclusively on Macintosh computers for encoding files into text characters for transmission through the mail transport system or for archiving on non-Macintosh systems. The format includes the file name, file type, file creator, Macintosh Finder flags, data fork, resource fork, and checksums. In MIME, the use of BinHex is deprecated; applesingle and appledouble are the preferred format for encoding Macintosh files. The BinHex format is described in RFC 1741. BinHex is a widely used, de facto standard, but it is not an official Internet standard.

To use BinHex for converting a Macintosh file to BinHex format, call the methods setFileName(com.hunnysoft.jmime.ByteString), setFileType(java.lang.String), setFileCreator(java.lang.String), setFlag1(byte), setFlag2(byte), setDataFork(com.hunnysoft.jmime.ByteString), and setResourceFork(com.hunnysoft.jmime.ByteString) to set the elements to be encoded. (The library sets reasonable default values for any elements that you do not set.) Then call the encode() method to actually perform the conversion to BinHex. Finally, call binHexChars() to get the characters of the BinHex file.

To use BinHex for converting a Macintosh file from BinHex format, call the method setBinHexChars(com.hunnysoft.jmime.ByteString) to set the characters of the BinHex file to be converted. Then call decode() to actually perform the conversion. Finally, call fileName(), fileType(), fileCreator(), flag1(), flag2(), dataFork(), and resourceFork() to get the decoded elements.

Note: BinHex does not change the file name in any way. When you deal with file names, you should be aware of the fact that some filenames that are valid on a Macintosh may cause problems or unexpected results on a non-Macintosh system, and vice versa. Such problem characters include slash ('/'), colon (':'), space and possibly other characters.


Constructor Summary
BinHex()
          Default constructor.
 
Method Summary
 ByteString binHexChars()
          Gets the characters of the BinHex encoded file.
 ByteString dataFork()
          Gets the data fork for the file.
 int decode()
          Converts the Macintosh file information from BinHex format.
 void encode()
          Converts the Macintosh file information to BinHex format.
 java.lang.String fileCreator()
          Gets the file creator.
 ByteString fileName()
          Gets the file name.
 java.lang.String fileType()
          Gets the file type.
 byte flag1()
          Gets the first byte of the Macintosh Finder flags.
 byte flag2()
          Gets the second byte of the Macintosh Finder flags.
 void initialize()
          Resets the object's internal state to its initial state.
 ByteString resourceFork()
          Gets the resource fork for the file.
 void setBinHexChars(ByteString chars)
          Sets the characters of the BinHex encoded file.
 void setDataFork(ByteString bytes)
          Sets the data fork for the file.
 void setFileCreator(java.lang.String creator)
          Sets the file creator.
 void setFileName(ByteString name)
          Sets the file name.
 void setFileType(java.lang.String type)
          Sets the file type.
 void setFlag1(byte flag)
          Sets the first byte of the Macintosh Finder flags.
 void setFlag2(byte flag)
          Sets the second byte of the Macintosh Finder flags.
 void setResourceFork(ByteString bytes)
          Sets the resource fork for the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinHex

public BinHex()
Default constructor.

Method Detail

initialize

public void initialize()
Resets the object's internal state to its initial state.

You may call this method to reuse the object for more than one encode or decode operation.


fileName

public ByteString fileName()
Gets the file name.

The file name is restricted to a maximum length of 63 characters.

Returns:
the file name

setFileName

public void setFileName(ByteString name)
Sets the file name.

The file name is restricted to a maximum length of 63 characters.

Parameters:
name - the file name

fileType

public java.lang.String fileType()
Gets the file type.

All Macintosh files have a file type, which is represented by four bytes. Some examples include "TEXT" for a text file, or "APPL" for an application.

Returns:
the file type

setFileType

public void setFileType(java.lang.String type)
Sets the file type.

All Macintosh files have a file type, which is represented by four bytes. Some examples include "TEXT" for a text file, or "APPL" for an application.

Parameters:
type - the file type

fileCreator

public java.lang.String fileCreator()
Gets the file creator.

Most Macintosh files have a creator, which is represented by a signature of four bytes. The creator specifies which application to launch when a file's icon is double clicked.

Returns:
the file creator

setFileCreator

public void setFileCreator(java.lang.String creator)
Sets the file creator.

Most Macintosh files have a creator, which is represented by a signature of four bytes. The creator specifies which application to launch when a file's icon is double clicked.

Parameters:
creator - the file creator

flag1

public byte flag1()
Gets the first byte of the Macintosh Finder flags.

For files that originate on non-Macintosh systems, this byte should be set to zero (the default).

Returns:
the first byte of the Finder flags

setFlag1

public void setFlag1(byte flag)
Sets the first byte of the Macintosh Finder flags.

For files that originate on non-Macintosh systems, this byte should be set to zero (the default).

Parameters:
flag - the first byte of the Finder flags

flag2

public byte flag2()
Gets the second byte of the Macintosh Finder flags.

For files that originate on non-Macintosh systems, this byte should be set to zero (the default).

Returns:
the second byte of the Finder flags

setFlag2

public void setFlag2(byte flag)
Sets the second byte of the Macintosh Finder flags.

For files that originate on non-Macintosh systems, this byte should be set to zero (the default).

Parameters:
flag - the second byte of the Finder flags

dataFork

public ByteString dataFork()
Gets the data fork for the file.

For files that originate on non-Macintosh systems, such as GIF or JPEG files, the file data should be set as the data fork.

Returns:
the bytes of the data fork

setDataFork

public void setDataFork(ByteString bytes)
Sets the data fork for the file.

For files that originate on non-Macintosh systems, such as GIF or JPEG files, the file data should be set as the data fork.

Parameters:
bytes - the bytes of the data fork

resourceFork

public ByteString resourceFork()
Gets the resource fork for the file.

For files that originate on non-Macintosh systems, such as GIF or JPEG files, the resource fork should normally be empty.

Returns:
the bytes of the resource fork

setResourceFork

public void setResourceFork(ByteString bytes)
Sets the resource fork for the file.

For files that originate on non-Macintosh systems, such as GIF or JPEG files, the resource fork should normally be empty.

Parameters:
bytes - the bytes of the resource fork

binHexChars

public ByteString binHexChars()
Gets the characters of the BinHex encoded file.

Returns:
the encoded characters of the BinHex file

setBinHexChars

public void setBinHexChars(ByteString chars)
Sets the characters of the BinHex encoded file.

Parameters:
chars - the encoded characters of the BinHex file

encode

public void encode()
Converts the Macintosh file information to BinHex format.


decode

public int decode()
Converts the Macintosh file information from BinHex format.

Returns zero if the decode operation completes successufully; otherwise, the function returns -1.

Returns:
0 on success; -1 on failure