
Public Member Functions | |
| int | calcCRC () |
| int | calcCRC2 () |
| int | checkFormat (boolean strictFormat) |
| ERXMacBinarySwissArmyKnife (NSData fileData) | |
| ERXMacBinarySwissArmyKnife () | |
| final byte[] | getByteArray () |
| byte | getByteAt (int offset) |
| int | getCRC () |
| int | getDataForkLength () |
| int | getIntAt (int offset) |
| long | getLongAt (int offset) |
| int | getResourceForkLength () |
| short | getShortAt (int offset) |
| int | getUByteAt (int offset) |
| long | getUIntAt (int offset) |
| int | getUShortAt (int offset) |
| boolean | isMacBinary (NSData fileData) |
| boolean | isValidCRC () |
| void | putByteAt (byte value, int offset) |
| void | putBytesAt (byte[] data, int offset, int count) |
| void | putBytesAt (byte[] data, int offset) |
| void | putIntAt (int value, int offset) |
| void | putLongAt (long value, int offset) |
| void | putShortAt (short value, int offset) |
| final void | setByteArray (byte[] bytes) |
| void | setCRC () |
| NSData | unwrapMacBinary (NSData fileContents) |
Static Public Member Functions | |
| static int | calculateCRC (int seed, byte[] bytes, int offset, int count) |
Static Public Attributes | |
| static final int | _AT = 0 |
| static final int | CRC_AT = 124 |
| static final int | FILE_CREATOR_AT = 69 |
| static final int | FILE_TYPE_AT = 65 |
| static final int | FINDER_FLAGS1_AT = 73 |
| static final int | FINDER_FLAGS2_AT = 101 |
| static final int | FINDER_FLAGS3_AT = 107 |
| static final int | FINDER_HORZ_AT = 77 |
| static final int | FINDER_VERT_AT = 75 |
| static final int | FINDER_WINDOW_AT = 79 |
| static final int | FLAG_LOCKED_AT = 81 |
| static final int | LEN_COMMENT_AT = 99 |
| static final int | LEN_DATA_FORK_AT = 83 |
| static final int | LEN_RES_FORK_AT = 87 |
| static final int | LEN_SECONDARY_AT = 120 |
| static final long | LIMIT_DATAFORK = Integer.MAX_VALUE |
| static final int | LIMIT_NAME = 31 |
| static final int | LIMIT_RESFORK = (16 * 1024 * 1024) - 1 |
| static final Logger | log = Logger.getLogger(ERXMacBinarySwissArmyKnife.class) |
| static final int | MACBINARY_HEADER_LEN = 128 |
| static final int | MB1_VERSION = 128 |
| static final int | MB2_VERSION = 129 |
| static final int | MB3_SIGNATURE = 0x6D42494E |
| static final int | MB3_SIGNATURE_AT = 102 |
| static final int | MB3_VERSION = 130 |
| static final int | NAME_BYTES_AT = 2 |
| static final int | NAME_LEN_AT = 1 |
| static final int | NAME_SCRIPT_AT = 106 |
| static final int | VERSION_MIN_AT = 123 |
| static final int | VERSION_OBSOLETE_AT = 126 |
| static final int | VERSION_TARGET_AT = 122 |
| static final int | WHEN_CREATED_AT = 91 |
| static final int | WHEN_MODIFIED_AT = 95 |
| static final int | ZERO_1_AT = 0 |
| static final int | ZERO_2_AT = 74 |
| static final int | ZERO_3_AT = 82 |
Static Protected Attributes | |
| static final int[] | levelMasks |
| static boolean | strict = false |
Static Private Member Functions | |
| static String | formatExplained (int format) |
Private Attributes | |
| byte[] | myBytes |
Static Private Attributes | |
| static final char[] | crcTable |
| static String[] | errorText |
| static final byte[] | noBytes = new byte[ 0 ] |
| ERXMacBinarySwissArmyKnife | ( | NSData | fileData | ) |
| int calcCRC | ( | ) |
Calculate and return a CRC over the header. The CRC value is in the low 16-bits of the returned int.
| int calcCRC2 | ( | ) |
Calculate and return an alternative header CRC. Where calcCRC() calculates over the first 124 bytes of the header, this calculates over the first 126 bytes of the header. I'm guessing that with a valid CRC-value in the header, the returned value is zero, but I don't know enough about CRC theory and practice to assert that confidently. This is more of a Greg's-hacky-toy than anything that might actually be useful.
| static int calculateCRC | ( | int | seed, | |
| byte[] | bytes, | |||
| int | offset, | |||
| int | count | |||
| ) | [static] |
Calculate a MacBinary CRC using the given starting seed, and proceeding over the given range of bytes. The returned CRC value is a 16-bit result in an int, because it's unsigned.
| int checkFormat | ( | boolean | strictFormat | ) |
| static String formatExplained | ( | int | format | ) | [static, private] |
Return a brief text String explaining a format or result-code.
| final byte [] getByteArray | ( | ) |
Get the internal byte-array.
| byte getByteAt | ( | int | offset | ) |
Return the signed byte at the given offset.
| int getCRC | ( | ) |
Return the header CRC, as embedded in the header itself.
| int getDataForkLength | ( | ) |
Get the data-fork length from the header.
| int getIntAt | ( | int | offset | ) |
Return the signed int at the given offset.
| long getLongAt | ( | int | offset | ) |
Return the signed long at the given offset.
| int getResourceForkLength | ( | ) |
Get the resource-fork length from the header.
| short getShortAt | ( | int | offset | ) |
Return the signed short at the given offset.
| int getUByteAt | ( | int | offset | ) |
Return an int holding the unsigned byte at the given offset.
| long getUIntAt | ( | int | offset | ) |
Return a long holding the unsigned int at the given offset.
| int getUShortAt | ( | int | offset | ) |
Return an int holding the unsigned short at the given offset.
| boolean isMacBinary | ( | NSData | fileData | ) |
| boolean isValidCRC | ( | ) |
Calculate and check the header CRC.
| void putByteAt | ( | byte | value, | |
| int | offset | |||
| ) |
Put the given byte at the supplied offset.
| void putBytesAt | ( | byte[] | data, | |
| int | offset, | |||
| int | count | |||
| ) |
Put the given bytes at the supplied offset.
| void putBytesAt | ( | byte[] | data, | |
| int | offset | |||
| ) |
Put all the given bytes at the supplied offset.
| void putIntAt | ( | int | value, | |
| int | offset | |||
| ) |
Put the given int at the supplied offset.
| void putLongAt | ( | long | value, | |
| int | offset | |||
| ) |
Put the given long at the supplied offset.
| void putShortAt | ( | short | value, | |
| int | offset | |||
| ) |
Put the given short at the supplied offset.
| final void setByteArray | ( | byte[] | bytes | ) |
Use the given array to hold bytes. Accepts null and/or zero-length arrays without error, though a subsequent get or put will throw an exception.
| void setCRC | ( | ) |
Calculate and set the CRC over the header bytes previously set, invoking calcCRC() to calculate the 16-bit value to store. You should only invoke this after setting every other field of interest, such as name and name-encoding, data-fork len, res-fork len, secondary-header len, etc. Since the CRC is calculated internally, there is no parameter to this method, even though it's a "setter" method.
In most cases, you will find finishHeader() more useful since it finishes all the assembly for a particular header-format you select.
| NSData unwrapMacBinary | ( | NSData | fileContents | ) |
final int _AT = 0 [static] |
final int CRC_AT = 124 [static] |
final char [] crcTable [static, private] |
Conveniently, UniCode chars are unsigned 16-bit values. Equally convenient, it's very easy to create constant String objects, then retrieve individual chars from them later. In particular, the String-constant rendering of the code consumes vastly fewer byte-codes than an ordinary array initializer would. And we still get a char[] out of it.
Initial value:
{
"Zero-length name",
"Invalid fork-lengths",
"Non-zero byte at 74",
"Non-zero bytes at 0 and/or 82"
}
final int FILE_CREATOR_AT = 69 [static] |
final int FILE_TYPE_AT = 65 [static] |
final int FINDER_FLAGS1_AT = 73 [static] |
final int FINDER_FLAGS2_AT = 101 [static] |
final int FINDER_FLAGS3_AT = 107 [static] |
final int FINDER_HORZ_AT = 77 [static] |
final int FINDER_VERT_AT = 75 [static] |
final int FINDER_WINDOW_AT = 79 [static] |
final int FLAG_LOCKED_AT = 81 [static] |
final int LEN_COMMENT_AT = 99 [static] |
final int LEN_DATA_FORK_AT = 83 [static] |
final int LEN_RES_FORK_AT = 87 [static] |
final int LEN_SECONDARY_AT = 120 [static] |
final int [] levelMasks [static, protected] |
Initial value:
{
0x00FFFE7F,
0x0000FC00,
0x0000FC4E,
0x0000FC4E,
}
final long LIMIT_DATAFORK = Integer.MAX_VALUE [static] |
Enforce this limit on data-fork length, due either to Mac OS API or field-width.
final int LIMIT_NAME = 31 [static] |
Enforce this limit on name-length, regardless of available space in header.
final int LIMIT_RESFORK = (16 * 1024 * 1024) - 1 [static] |
Enforce this limit on resource-fork length, due either to Mac OS API or field-width.
final Logger log = Logger.getLogger(ERXMacBinarySwissArmyKnife.class) [static] |
final int MACBINARY_HEADER_LEN = 128 [static] |
Length of a MacBinary header, always the first component of the file, and the only required element. A MacBinary file must be at least this length.
final int MB1_VERSION = 128 [static] |
Possible values in VERSION_TARGET_AT and VERSION_MIN_AT byte-sized fields.
final int MB2_VERSION = 129 [static] |
final int MB3_SIGNATURE = 0x6D42494E [static] |
Distinctive int-sized value in MB3_SIGNATURE_AT field, only present for MB-3 format.
final int MB3_SIGNATURE_AT = 102 [static] |
final int MB3_VERSION = 130 [static] |
byte [] myBytes [private] |
final int NAME_BYTES_AT = 2 [static] |
final int NAME_LEN_AT = 1 [static] |
final int NAME_SCRIPT_AT = 106 [static] |
final byte [] noBytes = new byte[ 0 ] [static, private] |
boolean strict = false [static, protected] |
final int VERSION_MIN_AT = 123 [static] |
final int VERSION_OBSOLETE_AT = 126 [static] |
final int VERSION_TARGET_AT = 122 [static] |
final int WHEN_CREATED_AT = 91 [static] |
final int WHEN_MODIFIED_AT = 95 [static] |
final int ZERO_1_AT = 0 [static] |
Offsets in header where the fields are located.
final int ZERO_2_AT = 74 [static] |
final int ZERO_3_AT = 82 [static] |
1.5.8