org.gjt.convert.binhex
Class BinHex4InputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--org.gjt.convert.binhex.BinHex4InputStream

public class BinHex4InputStream
extends java.io.InputStream

This class completely decodes a BinHex4 file in three parts: the header, the data fork and the resource fork. By default, all the InputStream-derived methods work on the data fork. With the methods useDataFork and useResourceFork the caller can select from which fork this stream will read. However, because this stream obtains the BinHex4 file through a stream, one can only read the forks in the order that they are in the BinHex4 file, which is: first the data fork, then the resource fork. A future version of this class that obtains it's data from a RandomAccessFile may be able to switch to reading from data and resource fork at any time.

Lacks something that translates between Unicode and the Mac character set to deal with foreign characters in filenames, types and creators. Anyone who has such a thing under a GPL license is invited to send it to me.

Author:
Erwin Bolwidt

Inner Class Summary
static class BinHex4InputStream.Header
          Representation of a BinHex4 header section.
 
Constructor Summary
BinHex4InputStream(java.io.InputStream source)
          Constructs a BinHex4InputStream from a stream that is a source of 7-bit Hqx7 encoded data.
BinHex4InputStream(java.io.InputStream source, boolean eightBit)
          Constructs a BinHex4InputStream from a stream that is either a source of 7-bit Hqx7 encoded data or of pure 8-bit data in Hqx8 format.
 
Method Summary
 BinHex4InputStream.Header getHeader()
          Returns the header section of this BinHex file in a Header object.
static void main(java.lang.String[] args)
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 void useDataFork()
          Switch reading from the data fork.
 void useResourceFork()
          Swtich to reading from the resource fork.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinHex4InputStream

public BinHex4InputStream(java.io.InputStream source)
Constructs a BinHex4InputStream from a stream that is a source of 7-bit Hqx7 encoded data. This is the typical use for files fetched from the Internet or through e-mail.

BinHex4InputStream

public BinHex4InputStream(java.io.InputStream source,
                          boolean eightBit)
Constructs a BinHex4InputStream from a stream that is either a source of 7-bit Hqx7 encoded data or of pure 8-bit data in Hqx8 format. The flag eightBit tells this class what to expect.
Parameters:
source - the data source
eightBit - if true, the data source must supply 8-bit data in Hqx8 format. If false, the data source must supply 7-bit data in Hqx7 format.
Method Detail

getHeader

public BinHex4InputStream.Header getHeader()
                                    throws java.io.IOException
Returns the header section of this BinHex file in a Header object.

useDataFork

public void useDataFork()
                 throws java.io.IOException
Switch reading from the data fork. All methods derived from InputStream will apply to the data fork. This method cannot be called after any method has thrown an IOException, or after useResourceFork has been called.

useResourceFork

public void useResourceFork()
                     throws java.io.IOException
Swtich to reading from the resource fork. All methods derived from InputStream will apply to the resource fork. This method cannot be called after any method has thrown an IOException.

read

public int read()
         throws java.io.IOException
Overrides:
read in class java.io.InputStream

read

public int read(byte[] b)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream

main

public static void main(java.lang.String[] args)