|
|||||||||
| Home >> All >> com >> flexstor >> common >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.flexstor.common.io
Class MacBinaryAccessFile

java.lang.Objectjava.io.RandomAccessFile
com.flexstor.common.io.MacBinaryAccessFile
- All Implemented Interfaces:
- java.io.DataInput, java.io.DataOutput
- public class MacBinaryAccessFile
- extends java.io.RandomAccessFile
Instances of this class allow both reading and writing to a MacBinary file. This class provides method for reading and writing all fields required in the header of a MacBinary file, as well as access to reding and writing the data fork and resource fork. The MacBinary file created complies with the Macintosh Binary Transfer Format ("MacBinary III") Standard Proposal as of December of 1996. Offset Length Contents ------ ------ -------- 000 Byte old version number, must be kept at zero for compatibility 001 Byte Length of filename (must be in the range 1-31) 002 1-63 Bytes filename (only "length" bytes are significant). 065 Long Word file type (normally expressed as four characters) 069 Long Word file creator (normally expressed as four characters) 073 Byte original Finder flags Bit 7 - isAlias. Bit 6 - isInvisible. Bit 5 - hasBundle. Bit 4 - nameLocked. Bit 3 - isStationery. Bit 2 - hasCustomIcon. Bit 1 - reserved. Bit 0 - hasBeenInited. 074 Byte zero fill, must be zero for compatibility 075 Word file's vertical position within its window. 077 Word file's horizontal position within its window. 079 Word file's window or folder ID. 081 Byte "Protected" flag (in low order bit). 082 Byte zero fill, must be zero for compatibility 083 Long Word Data Fork length (bytes, zero if no Data Fork). 087 Long Word Resource Fork length (bytes, zero if no R.F.). 091 Long Word File's creation date 095 Long Word File's "last modified" date. 099 Word length of Get Info comment to be sent after the resource fork (if implemented, see below). 101 Byte Finder Flags, bits 0-7. (Bits 8-15 are already in byte 73) Bit 7 - hasNoInits Bit 6 - isShared Bit 5 - requiresSwitchLaunch Bit 4 - ColorReserved Bits 1-3 - color Bit 0 - isOnDesk *102 Long Word signature for indentification purposes (ĉmBINĈ) *106 Byte script of file name (from the fdScript field of an fxInfo record) *107 Byte extended Finder flags (from the fdXFlags field of an fxInfo record) 108-115 Unused (must be zeroed by creators, must be ignored by readers) 116 Long Word Length of total files when packed files are unpacked. As of the writing of this document, this field has never been used. 120 Word Length of a secondary header. If this is non-zero, skip this many bytes (rounded up to the next multiple of 128). This is for future expansion only, when sending files with MacBinary, this word should be zero. *122 Byte Version number of MacBinary III that the uploading program is written for (the version is 130 for MacBinary III) 123 Byte Minimum MacBinary version needed to read this file (set this value at 129 for backwards compatibility with MacBinary II) 124 Word CRC of previous 124 bytes
| Field Summary | |
private boolean |
bFileClosed
|
private boolean |
bOpenedForWriting
|
static int |
BUFFER_SIZE
|
private static int |
HEADER_SIZE
|
private static long |
MAC_TIME_OFFSET
MAC_TIME_OFFSET is the number of seconds between the Mac OS epoch and Java epoch, i.e. |
private int |
nCommentLength
|
private int |
nDataForkLength
|
private int |
nDataForkPadding
|
private int |
nRsrcForkLength
|
private int |
nRsrcForkPadding
|
| Fields inherited from class java.io.RandomAccessFile |
|
| Constructor Summary | |
MacBinaryAccessFile(java.io.File binFile,
java.lang.String sMode)
Creates a random access file stream to read from, and optionally to write to, the Macbinary file specified by the File
argument. |
|
MacBinaryAccessFile(com.flexstor.common.io.xfile.FlexXFile xBinFile,
java.lang.String sMode)
Creates a random access file stream to read from, and optionally to write to, the Macbinary file specified by the File
argument. |
|
MacBinaryAccessFile(java.lang.String sBinFileName,
java.lang.String sMode)
Creates a random access file stream to read from, and optionally to write to, a MacBInary file with the specified name. |
|
| Method Summary | |
private void |
addCRC()
|
void |
close()
This method closes the file and frees up all file related system resources. |
void |
finalize()
Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed. |
java.io.ByteArrayInputStream |
getComment()
|
int |
getCommentLength()
|
private int |
getCommentOffset()
|
void |
getDataFork(java.lang.String sOutFile)
|
int |
getDataForkLength()
|
private int |
getDataForkOffset()
|
byte |
getExtendedFinderFlags()
|
int |
getFileCreationDate()
|
byte[] |
getFileCreator()
|
int |
getFileLastModifiedDate()
|
java.lang.String |
getFileName()
|
int |
getFileNameLength()
|
byte |
getFileNameScript()
|
byte[] |
getFileType()
|
byte |
getFirstByteOfFinderFlags()
|
byte[] |
getFolderId()
|
byte[] |
getHorizontalPosition()
|
int |
getOldVersionNumber()
|
private int |
getPadding(int nSize)
|
private static java.lang.String |
getPath(com.flexstor.common.io.xfile.FlexXFile xBinFile)
|
byte |
getProtectedFlag()
|
java.io.ByteArrayInputStream |
getResourceFork()
|
int |
getResourceForkLength()
|
private int |
getResourceForkOffset()
|
byte |
getSecondByteOfFinderFlags()
|
int |
getVersionNumber()
|
byte[] |
getVerticalPosition()
|
private boolean |
isMacBinaryIIICompatible()
|
private int |
javaToMacTime(long javaTime)
Convert a Java time to a Mac OS time, i.e. |
private byte |
readByte(long nPos)
|
private int |
readByteAsInt(long nPos)
|
private byte[] |
readBytes(long nPos,
int nLength)
|
private java.lang.String |
readBytesAsString(long nPos,
int nLength)
|
private int |
readInt(long nPos)
|
private int |
readShortAsInt(long nPos)
|
private java.lang.String |
replaceChar(java.lang.String str)
|
void |
setComment(java.io.InputStream input)
|
void |
setCommentLength(int nLength)
099 Word length of Get Info comment to be sent after the resource fork (if implemented) |
void |
setDataFork(java.lang.String sInFile)
|
void |
setDataForkLength(int nLength)
083 Long Word Data Fork length (bytes, zero if no Data Fork). |
void |
setExtendedFinderFlags(byte bFinderFlags)
107 Byte extended Finder flags (from the fdXFlags field of an fxInfo record) |
void |
setFileCreationDate(long nFileCreation)
|
void |
setFileCreator(byte[] baCreator)
069 Long Word file creator (normally expressed as four characters) |
void |
setFileLastModifiedDate(long nFileModified)
095 Long Word File's "last modified" date. |
void |
setFileName(java.lang.String sFileName)
002 1-63 Bytes filename (only "length" bytes are significant). |
void |
setFileNameLength(int nLength)
001 Byte Length of filename (must be in the range 1-31) |
void |
setFileNameScript(byte script)
106 Byte script of file name (from the fdScript field of an fxInfo record) |
void |
setFileType(byte[] baType)
065 Long Word file type (normally expressed as four characters) |
void |
setFirstByteOfFinderFlags(byte bFinderFlags)
073 Byte original Finder flags Bit 7 - isAlias. |
void |
setFolderId(byte[] baFolderId)
079 Word file's window or folder ID. |
void |
setHorizontalPosition(byte[] baHorizontalPosition)
077 Word file's horizontal position within its window. |
void |
setOldVersionNumber(int nOldVersion)
000 Byte old version number, must be kept at zero for compatibility |
void |
setProtectedFlag(byte protectedFlag)
081 Byte "Protected" flag (in low order bit). |
void |
setResourceFork(java.io.InputStream input)
|
void |
setResourceForkLength(int nLength)
087 Long Word Resource Fork length (bytes, zero if no R.F.). |
void |
setSecondByteOfFinderFlags(byte bFinderFlags)
101 Byte Finder Flags, bits 0-7. |
void |
setVerticalPosition(byte[] baVerticalPosition)
075 Word file's vertical position within its window. |
private java.lang.String |
substituteDecodedChars(java.lang.String sFileName)
Replaces the ocurrences of illegal characters by its :nn translation |
private java.lang.String |
substituteEncodedChars(java.lang.String sFileName)
Replaces the ocurrences of :nn characters with its right translation |
java.lang.String |
toString()
Prints the first 128 bytes of this MacBinary file |
private void |
writeByte(long nPos,
byte b)
|
private void |
writeBytes(long nPos,
byte[] ba,
int offset,
int length)
|
private void |
writeInt(long nPos,
int n)
|
private void |
writeIntAsByte(long nPos,
int n)
|
private void |
writeIntAsShort(long nPos,
int n)
|
private void |
writeShort(long nPos,
int n)
|
private void |
writeStringAsBytes(long nPos,
java.lang.String s)
|
| Methods inherited from class java.io.RandomAccessFile |
getChannel, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
BUFFER_SIZE
public static final int BUFFER_SIZE
- See Also:
- Constant Field Values
HEADER_SIZE
private static final int HEADER_SIZE
- See Also:
- Constant Field Values
MAC_TIME_OFFSET
private static final long MAC_TIME_OFFSET
- MAC_TIME_OFFSET is the number of seconds
between the Mac OS epoch and Java epoch, i.e. the respective t = 0 points.
Mac OS time-keeping starts 01 Jan 1904, Java at 01 Jan 1970.
This value does not account for the fact that Mac-time is in the local time-zone,
while Java-time is fundamentally in GMT.
- See Also:
- Constant Field Values
nDataForkLength
private int nDataForkLength
nDataForkPadding
private int nDataForkPadding
nRsrcForkLength
private int nRsrcForkLength
nRsrcForkPadding
private int nRsrcForkPadding
nCommentLength
private int nCommentLength
bOpenedForWriting
private boolean bOpenedForWriting
bFileClosed
private boolean bFileClosed
| Constructor Detail |
MacBinaryAccessFile
public MacBinaryAccessFile(com.flexstor.common.io.xfile.FlexXFile xBinFile, java.lang.String sMode) throws java.io.IOException
- Creates a random access file stream to read from, and optionally
to write to, the Macbinary file specified by the
Fileargument.The mode argument must either be equal to
"r"or to"rw", indicating either to open the file for input, or for both input and output, respectively.
MacBinaryAccessFile
public MacBinaryAccessFile(java.lang.String sBinFileName, java.lang.String sMode) throws java.io.IOException
- Creates a random access file stream to read from, and optionally
to write to, a MacBInary file with the specified name.
The mode argument must either be equal to
"r"or"rw", indicating either to open the file for input or for both input and output.
MacBinaryAccessFile
public MacBinaryAccessFile(java.io.File binFile, java.lang.String sMode) throws java.io.IOException
- Creates a random access file stream to read from, and optionally
to write to, the Macbinary file specified by the
Fileargument.The mode argument must either be equal to
"r"or to"rw", indicating either to open the file for input, or for both input and output, respectively.
| Method Detail |
isMacBinaryIIICompatible
private boolean isMacBinaryIIICompatible()
throws java.io.IOException
getVersionNumber
public int getVersionNumber()
throws java.io.IOException
setOldVersionNumber
public void setOldVersionNumber(int nOldVersion)
throws java.io.IOException
- 000 Byte old version number, must be kept at zero for compatibility
getOldVersionNumber
public int getOldVersionNumber()
throws java.io.IOException
setFileNameLength
public void setFileNameLength(int nLength)
throws java.io.IOException
- 001 Byte Length of filename (must be in the range 1-31)
getFileNameLength
public int getFileNameLength()
throws java.io.IOException
setFileName
public void setFileName(java.lang.String sFileName) throws java.io.IOException
- 002 1-63 Bytes filename (only "length" bytes are significant).
getFileName
public java.lang.String getFileName() throws java.io.IOException
setFileType
public void setFileType(byte[] baType)
throws java.io.IOException
- 065 Long Word file type (normally expressed as four characters)
getFileType
public byte[] getFileType()
throws java.io.IOException
setFileCreator
public void setFileCreator(byte[] baCreator)
throws java.io.IOException
- 069 Long Word file creator (normally expressed as four characters)
getFileCreator
public byte[] getFileCreator()
throws java.io.IOException
setFirstByteOfFinderFlags
public void setFirstByteOfFinderFlags(byte bFinderFlags)
throws java.io.IOException
- 073 Byte original Finder flags
Bit 7 - isAlias.
Bit 6 - isInvisible.
Bit 5 - hasBundle.
Bit 4 - nameLocked.
Bit 3 - isStationery.
Bit 2 - hasCustomIcon.
Bit 1 - reserved.
Bit 0 - hasBeenInited.
getFirstByteOfFinderFlags
public byte getFirstByteOfFinderFlags()
throws java.io.IOException
setVerticalPosition
public void setVerticalPosition(byte[] baVerticalPosition)
throws java.io.IOException
- 075 Word file's vertical position within its window.
getVerticalPosition
public byte[] getVerticalPosition()
throws java.io.IOException
setHorizontalPosition
public void setHorizontalPosition(byte[] baHorizontalPosition)
throws java.io.IOException
- 077 Word file's horizontal position within its window.
getHorizontalPosition
public byte[] getHorizontalPosition()
throws java.io.IOException
setFolderId
public void setFolderId(byte[] baFolderId)
throws java.io.IOException
- 079 Word file's window or folder ID.
getFolderId
public byte[] getFolderId()
throws java.io.IOException
setProtectedFlag
public void setProtectedFlag(byte protectedFlag)
throws java.io.IOException
- 081 Byte "Protected" flag (in low order bit).
getProtectedFlag
public byte getProtectedFlag()
throws java.io.IOException
setDataForkLength
public void setDataForkLength(int nLength)
throws java.io.IOException
- 083 Long Word Data Fork length (bytes, zero if no Data Fork).
getDataForkLength
public int getDataForkLength()
throws java.io.IOException
setResourceForkLength
public void setResourceForkLength(int nLength)
throws java.io.IOException
- 087 Long Word Resource Fork length (bytes, zero if no R.F.).
getResourceForkLength
public int getResourceForkLength()
throws java.io.IOException
setFileCreationDate
public void setFileCreationDate(long nFileCreation)
throws java.io.IOException
getFileCreationDate
public int getFileCreationDate()
throws java.io.IOException
setFileLastModifiedDate
public void setFileLastModifiedDate(long nFileModified)
throws java.io.IOException
- 095 Long Word File's "last modified" date.
getFileLastModifiedDate
public int getFileLastModifiedDate()
throws java.io.IOException
setCommentLength
public void setCommentLength(int nLength)
throws java.io.IOException
- 099 Word length of Get Info comment to be sent after the resource fork (if implemented)
getCommentLength
public int getCommentLength()
throws java.io.IOException
setSecondByteOfFinderFlags
public void setSecondByteOfFinderFlags(byte bFinderFlags)
throws java.io.IOException
- 101 Byte Finder Flags, bits 0-7. (Bits 8-15 are already in byte 73)
Bit 7 - hasNoInits
Bit 6 - isShared
Bit 5 - requiresSwitchLaunch
Bit 4 - ColorReserved
Bits 1-3 - color
Bit 0 - isOnDesk
getSecondByteOfFinderFlags
public byte getSecondByteOfFinderFlags()
throws java.io.IOException
setFileNameScript
public void setFileNameScript(byte script)
throws java.io.IOException
- 106 Byte script of file name (from the fdScript field of an fxInfo record)
getFileNameScript
public byte getFileNameScript()
throws java.io.IOException
setExtendedFinderFlags
public void setExtendedFinderFlags(byte bFinderFlags)
throws java.io.IOException
- 107 Byte extended Finder flags (from the fdXFlags field of an fxInfo record)
getExtendedFinderFlags
public byte getExtendedFinderFlags()
throws java.io.IOException
setDataFork
public void setDataFork(java.lang.String sInFile) throws java.io.IOException
getDataFork
public void getDataFork(java.lang.String sOutFile) throws java.io.IOException
setResourceFork
public void setResourceFork(java.io.InputStream input) throws java.io.IOException
getResourceFork
public java.io.ByteArrayInputStream getResourceFork() throws java.io.IOException
setComment
public void setComment(java.io.InputStream input) throws java.io.IOException
getComment
public java.io.ByteArrayInputStream getComment() throws java.io.IOException
getDataForkOffset
private int getDataForkOffset()
getResourceForkOffset
private int getResourceForkOffset()
getCommentOffset
private int getCommentOffset()
getPadding
private int getPadding(int nSize)
close
public void close()
throws java.io.IOException
- Description copied from class:
java.io.RandomAccessFile - This method closes the file and frees up all file related system
resources. Since most operating systems put a limit on how many files
may be opened at any given time, it is a good idea to close all files
when no longer needed to avoid hitting this limit
writeByte
private void writeByte(long nPos,
byte b)
throws java.io.IOException
readByte
private byte readByte(long nPos)
throws java.io.IOException
writeBytes
private void writeBytes(long nPos,
byte[] ba,
int offset,
int length)
throws java.io.IOException
readBytes
private byte[] readBytes(long nPos,
int nLength)
throws java.io.IOException
writeInt
private void writeInt(long nPos,
int n)
throws java.io.IOException
writeShort
private void writeShort(long nPos,
int n)
throws java.io.IOException
readInt
private int readInt(long nPos)
throws java.io.IOException
writeIntAsByte
private void writeIntAsByte(long nPos,
int n)
throws java.io.IOException
readByteAsInt
private int readByteAsInt(long nPos)
throws java.io.IOException
writeStringAsBytes
private void writeStringAsBytes(long nPos,
java.lang.String s)
throws java.io.IOException
readBytesAsString
private java.lang.String readBytesAsString(long nPos, int nLength) throws java.io.IOException
writeIntAsShort
private void writeIntAsShort(long nPos,
int n)
throws java.io.IOException
readShortAsInt
private int readShortAsInt(long nPos)
throws java.io.IOException
addCRC
private void addCRC()
throws java.io.IOException
substituteEncodedChars
private java.lang.String substituteEncodedChars(java.lang.String sFileName)
- Replaces the ocurrences of :nn characters with its right translation
replaceChar
private java.lang.String replaceChar(java.lang.String str)
substituteDecodedChars
private java.lang.String substituteDecodedChars(java.lang.String sFileName)
- Replaces the ocurrences of illegal characters by its :nn translation
finalize
public void finalize()
- Description copied from class:
java.lang.Object - Called on an object by the Virtual Machine at most once,
at some point after the Object is determined unreachable
but before it is destroyed. You would think that this
means it eventually is called on every Object, but this is
not necessarily the case. If execution terminates
abnormally, garbage collection does not always happen.
Thus you cannot rely on this method to always work.
For finer control over garbage collection, use references
from the
java.lang.refpackage.Virtual Machines are free to not call this method if they can determine that it does nothing important; for example, if your class extends Object and overrides finalize to do simply
super.finalize().finalize() will be called by a java.lang.Thread that has no locks on any Objects, and may be called concurrently. There are no guarantees on the order in which multiple objects are finalized. This means that finalize() is usually unsuited for performing actions that must be thread-safe, and that your implementation must be use defensive programming if it is to always work.
If an Exception is thrown from finalize() during garbage collection, it will be patently ignored and the Object will still be destroyed.
It is allowed, although not typical, for user code to call finalize() directly. User invocation does not affect whether automatic invocation will occur. It is also permitted, although not recommended, for a finalize() method to "revive" an object by making it reachable from normal code again.
Unlike constructors, finalize() does not get called for an object's superclass unless the implementation specifically calls
super.finalize().The default implementation does nothing.
javaToMacTime
private int javaToMacTime(long javaTime)
- Convert a Java time to a Mac OS time, i.e. seconds since midnight 01 Jan 1904 local-time.
Since Mac OS time is local-time, and Java is GMT, account for the
given GMT-offset, which is negative for locations west of prime meridian,
positive for locations east. That is, it's the GMT-offset of local-time, in minutes.
toString
public java.lang.String toString()
- Prints the first 128 bytes of this MacBinary file
getPath
private static java.lang.String getPath(com.flexstor.common.io.xfile.FlexXFile xBinFile)
|
|||||||||
| Home >> All >> com >> flexstor >> common >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC