package ch.werner_randelshofer.iff;/*Copyright (C) 1999 Werner Randelshoferwerner.randelshofer@mythen.chhttp://www.mythen.ch/w.randelshofer/    Permission to use this release of MC68000InputStream is herebygranted without fee provided that the complete copyrightnotice and this permission notice appear in all copiesand in supporting documentation.*/import java.io.*;/**A MC 68000 input stream lets an application read primitive datatypes in the MC 68000 CPU format from an underlying input stream.<p>This stream filter is suitable for IFF-EA85 files.@author	Werner Randelshofer, Staldenmattweg 2, CH-6405 Immensee, Switzerland@version	1999-01-02	Created.*/public class MC68000InputStreamextends FilterInputStream	{	private long scan_, mark_;	/**	Creates a new instance.	 	@param  in   the input stream.	*/	public MC68000InputStream(InputStream in)    	{ super(in); }	/**	Read 1 byte from the input stream and interpret	them as an MC 68000 8 Bit unsigned UBYTE value.	*/	public int readUBYTE()	throws IOException		{		int l =	in.read() & 0xff;		scan_ += 1;		return l;		}	/**	Read 2 bytes from the input stream and interpret	them as an MC 68000 16 Bit signed WORD value.	*/	public short readWORD()	throws IOException		{		int l =	((in.read()&0xff) << 8) +				((in.read()&0xff) << 0);		scan_ += 2;		return (short)l;		}	/**	Read 2 bytes from the input stream and interpret	them as an MC 68000 16 Bit unsigned UWORD value.	*/	public int readUWORD()	throws IOException		{		int l =	((in.read()&0xff) << 8) +				((in.read()&0xff) << 0);		scan_ += 2;		return l;		}	/**	Read 4 bytes from the input stream and interpret	them as an MC 68000 32 Bit signed LONG value.	*/	public int readLONG()	throws IOException		{		int l = ((in.read()&0xff) << 24) +				((in.read()&0xff) << 16) +				((in.read()&0xff) << 8) +				((in.read()&0xff) << 0);		scan_ += 4;		return l;		}	/**	Read 4 Bytes from the input Stream and interpret	them as an unsigned Integer value of MC 68000	type ULONG.	*/	public long readULONG()	throws IOException		{		return (long)(readLONG()) & 0x00ffffffff;		}	/**	Align to an even byte position in the input stream.	This will skip one byte in the stream if the current	read position is not even.	*/	public void align()	throws IOException		{		if (scan_ % 2 == 1)			{			in.skip(1);			scan_++;			}		}	/**	Get the current read position within the file (as seen	by this input stream filter).	*/		public long getScan()		{ return scan_; }	/**	Reads one byte.	*/	public int read()	throws IOException		{		int data = in.read();		scan_++;		return data;		}	/**	Reads a sequence of bytes.	*/	public int read(byte[] b,int offset, int length)	throws IOException		{		int count = 0;		while (count < length)			{			count += in.read(b,offset+count,length-count);			}		scan_ += count;		return count;		}	/**	Marks the input stream.	@param	readlimit	The maximum limit of bytes that can be read before                    	the mark position becomes invalid.	*/	public void mark(int readlimit)		{		in.mark(readlimit);		mark_ = scan_;		}	/**	Repositions the stream at the previously marked position.	    @exception  IOException  If the stream has not been marked or if the    			             mark has been invalidated.    */	public void reset()	throws IOException		{		in.reset();		scan_ = mark_;		}		public long skip(long n)	throws IOException		{		long skipped = in.skip(n);		scan_ += skipped;		return skipped;		}	}