com.sun.faban.harness.webclient
Class XMLInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.sun.faban.harness.webclient.XMLInputStream
All Implemented Interfaces:
Closeable

public class XMLInputStream
extends FilterInputStream

The XML input stream rudimentary parses an xml input file for completion. It checks that the outermost element is properly closed. Otherwise the stream will not end.


Nested Class Summary
static interface XMLInputStream.EOFListener
          A listener to listen to end-of-file events of XMLInputStream.
 
Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
XMLInputStream(File file)
          Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.
XMLInputStream(FileDescriptor fdObj)
          Creates a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.
XMLInputStream(String name)
          Creates a XMLInputStream by opening a connection to an actual file, the file named by the path name name in the file system.
 
Method Summary
 void addEOFListener(XMLInputStream.EOFListener listener)
          Adds the EOF listener.
 void mark(int readlimit)
          Marks the current position in this input stream.
 boolean markSupported()
          Tests if this input stream supports the mark and reset methods.
 int read()
          Reads a byte of data from this input stream.
 int read(byte[] b)
          Reads up to byte.length bytes of data from this input stream into an array of bytes.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from this input stream into an array of bytes.
 void reset()
          Repositions this stream to the position at the time the mark method was last called on this input stream.
 long skip(long n)
          

This method actually reads the skipped bytes from the stream.

 
Methods inherited from class java.io.FilterInputStream
available, close
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLInputStream

public XMLInputStream(String name)
               throws FileNotFoundException
Creates a XMLInputStream by opening a connection to an actual file, the file named by the path name name in the file system. A new FileDescriptor object is created to represent this file connection.

First, if there is a security manager, its checkRead method is called with the name argument as its argument.

If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.

Parameters:
name - the system-dependent file name.
Throws:
FileNotFoundException - if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.
SecurityException - if a security manager exists and its checkRead method denies read access to the file.
See Also:
SecurityManager.checkRead(String)

XMLInputStream

public XMLInputStream(File file)
               throws FileNotFoundException
Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system. A new FileDescriptor object is created to represent this file connection.

First, if there is a security manager, its checkRead method is called with the path represented by the file argument as its argument.

If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.

Parameters:
file - the file to be opened for reading.
Throws:
FileNotFoundException - if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.
SecurityException - if a security manager exists and its checkRead method denies read access to the file.
See Also:
File.getPath(), SecurityManager.checkRead(String)

XMLInputStream

public XMLInputStream(FileDescriptor fdObj)
Creates a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.

If there is a security manager, its checkRead method is called with the file descriptor fdObj as its argument to see if it's ok to read the file descriptor. If read access is denied to the file descriptor a SecurityException is thrown.

If fdObj is null then a NullPointerException is thrown.

Parameters:
fdObj - the file descriptor to be opened for reading.
Throws:
SecurityException - if a security manager exists and its checkRead method denies read access to the file descriptor.
See Also:
SecurityManager.checkRead(java.io.FileDescriptor)
Method Detail

addEOFListener

public void addEOFListener(XMLInputStream.EOFListener listener)
Adds the EOF listener.

Parameters:
listener - The listener to add

read

public int read()
         throws IOException
Reads a byte of data from this input stream. This method blocks if no input is yet available.

Overrides:
read in class FilterInputStream
Returns:
the next byte of data, or -1 if the end of the file is reached.
Throws:
IOException - if an I/O error occurs.

read

public int read(byte[] b)
         throws IOException
Reads up to byte.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

This method simply performs the call read(b, 0, b.length) and returns the result. It is important that it does not do in.read(b) instead; certain subclasses of FilterInputStream depend on the implementation strategy actually used.

Overrides:
read in class FilterInputStream
Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.
See Also:
FilterInputStream.read(byte[], int, int)

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Overrides:
read in class FilterInputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset in the destination array b
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
Throws:
NullPointerException - If b is null.
IndexOutOfBoundsException - If off is negative, len is negative, or len is greater than b.length - off
IOException - if an I/O error occurs.

markSupported

public boolean markSupported()
Tests if this input stream supports the mark and reset methods. This method always returns false. Mark is not supported in XMLInputStream.

Overrides:
markSupported in class FilterInputStream
Returns:
true if this stream type supports the mark and reset method; false otherwise.
See Also:
FilterInputStream.in, InputStream.mark(int), InputStream.reset()

skip

public long skip(long n)
          throws IOException

This method actually reads the skipped bytes from the stream.

Overrides:
skip in class FilterInputStream
Throws:
IOException

mark

public void mark(int readlimit)
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

Since mark is not supported in XMLInputStream, this method is a NOOP.

Overrides:
mark in class FilterInputStream
Parameters:
readlimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
See Also:
FilterInputStream.in, FilterInputStream.reset()

reset

public void reset()
           throws IOException
Repositions this stream to the position at the time the mark method was last called on this input stream.

This method simply performs in.reset().

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.

Overrides:
reset in class FilterInputStream
Throws:
IOException - if the stream has not been marked or if the mark has been invalidated.
See Also:
FilterInputStream.in, FilterInputStream.mark(int)