package com.xagasoft.gats; import java.io.InputStream; import java.io.DataInputStream; /** * Facilitates reading GatsObjects from an InputStream. This doesn't really * inherit from InputStream, so maybe it would make more sense to call it * something else. Use the readObject function to read an entire object from * the InputStream. *
* At the moment this class will require all data to be available in continuous * read operations from teh provided InputStream. This means that only complete * packets can be read from files on the disk, or that if a socket is provided * it is in blocking or synchronous I/O mode. In java, this should rarely be * an issue. *
* Each call to readObject returns a new GatsObject read from the InputStream or * null if nothing else could be read. While reading, all zero bytes discovered * in between packets will be considered padding and will be ignored. *
* Like with the GatsOutputStream, there are generally many small reads * performed during a single readObject operation, so it is a good idea to * provide some sort of buffered input stream. *@see com.xagasoft.gats.GatsOutputStream */ public class GatsInputStream { private InputStream is; private int iVer = 0; private int iSize; public GatsInputStream( InputStream is ) { this.is = is; } /** * Reads an object from the input and returns it. */ public GatsObject readObject() throws java.io.IOException { do { iVer = is.read(); } while( iVer == 0 ); switch( iVer ) { case 1: DataInputStream dis = new DataInputStream( is ); iSize = dis.readInt(); return GatsObject.read( is ); } return null; } };