biz.c24.io.api.presentation
Class Source

java.lang.Object
  extended by biz.c24.io.api.presentation.Source
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
BinarySource, DefaultSource, FixedLengthSource, FIXSource, JavaClassSource, JsonSource, SAXSource, SSSource, SwiftPreParser, SwiftSource, TextualSource, XMLSource

public abstract class Source
extends Object
implements Cloneable, Serializable

A class used to read data objects from an input stream or reader in a specific format.
This class is subclassed by format specific specialisations.
The input stream or reader used by this class will never be closed - it is the responsibility of the calling class to maintain a reference to the appropriate object so that it can be closed when no longer required.
If character data is required and no input stream has been set then the stream will be wrapped by an InputStreamReader using the default charset. Therefore if an encoding other than the default is required, an java.io.InputStreamReader should be instantiated with that encoding and then supplied to this class.

See Also:
Serialized Form

Constructor Summary
Source()
          Constructs a new instance.
Source(InputStream stream)
          Constructs a new instance which will read from stream (optional operation).
Source(Reader reader)
          Constructs a new instance which will read from reader (optional operation).
 
Method Summary
protected  void checkInit()
          Used by subclasses to ensure a reader or input stream has been set.
abstract  Object clone()
           
 String getEncoding()
          Get the character encoding for a byte stream.
 InputStream getInputStream()
          Returns the input stream (optional operation).
 InputStream getMarkableInputStream()
           
 ParseListener getParseListener()
          Returns the parse listener that will be notified of batch processing events.
 Reader getReader()
          Returns the reader (optional operation).
 URI getSystemId()
          Gets the optional System ID.
protected  Reader reader()
          Used by subclasses to get a reference to the reader object responsible for reading the data.
abstract  void readObject(ComplexDataObject object)
          Reads an object from the the reader or input stream that has been set (optional operation).
abstract  ComplexDataObject readObject(Element element)
          Reads an object from the the reader or input stream that has been set.
 boolean ready()
          Tests whether the underlying stream or reader contains more data waiting to be parsed.
 void setEncoding(String encoding)
          Set the character encoding for a byte stream.
 void setInputStream(InputStream stream)
          Sets the input stream (optional operation).
 void setInputStream(InputStream stream, URI systemId)
          Sets the input stream and system ID (optional operation).
 void setParseListener(ParseListener listener)
          Sets the parse listener that will be notified of batch processing events.
 void setReader(Reader reader)
          Sets the reader (optional operation).
 void setReader(Reader reader, URI systemId)
          Sets the reader (optional operation).
 void setSystemId(URI systemId)
          Sets the optional System ID.
protected  InputStream stream()
          Used by subclasses to get a reference to the input stream object responsible for reading the data.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Source

public Source()
Constructs a new instance.


Source

public Source(Reader reader)
Constructs a new instance which will read from reader (optional operation).

Parameters:
reader - The reader to read the data from.
Throws:
UnsupportedOperationException - If this source does not support input from a java.io.Reader, in which case a java.io.InputStream should be used.

Source

public Source(InputStream stream)
Constructs a new instance which will read from stream (optional operation).

Parameters:
stream - The stream to read the data from.
Throws:
UnsupportedOperationException - If this source does not support input from a java.io.InputStream, in which case a java.io.Reader should be used.
Method Detail

setReader

public void setReader(Reader reader)
Sets the reader (optional operation). This method will also clear the system ID.

Parameters:
reader - The new value.
Throws:
UnsupportedOperationException - If this source does not support input from a java.io.Reader, in which case a java.io.InputStream should be used.

setReader

public void setReader(Reader reader,
                      URI systemId)
Sets the reader (optional operation).

Parameters:
reader - The new value.
systemId - The system ID identifying the reader.
Throws:
UnsupportedOperationException - If this source does not support input from a java.io.Reader, in which case a java.io.InputStream should be used.

getReader

public Reader getReader()
Returns the reader (optional operation).

Returns:
The reader.
Throws:
UnsupportedOperationException - If this source does not support input from a java.io.Reader, in which case a java.io.InputStream should be used.

setInputStream

public void setInputStream(InputStream stream)
Sets the input stream (optional operation).

This method will also clear the system ID.

Parameters:
stream - The new value.
Throws:
UnsupportedOperationException - If this source does not support input from a java.io.InputStream, in which case a java.io.Reader should be used.

setInputStream

public void setInputStream(InputStream stream,
                           URI systemId)
Sets the input stream and system ID (optional operation).

Parameters:
stream - The new value.
systemId - The system ID identifying the stream.
Throws:
UnsupportedOperationException - If this source does not support input from a java.io.InputStream, in which case a java.io.Reader should be used.

getInputStream

public InputStream getInputStream()
Returns the input stream (optional operation).

Returns:
The stream.
Throws:
UnsupportedOperationException - If this source does not support input from a java.io.InputStream, in which case a java.io.Reader should be used.

setEncoding

public void setEncoding(String encoding)
Set the character encoding for a byte stream. This method has no effect when the application provides a writer or when a source instance load binary data.

Parameters:
encoding - A string describing the character encoding. If null then UTF-8 will be used by default.

getEncoding

public String getEncoding()
Get the character encoding for a byte stream. This value will be ignored when the application provides a writer or when a source instance load binary data.

Returns:
The encoding, or null if none was supplied.

getSystemId

public URI getSystemId()
Gets the optional System ID.

Returns:
The system ID, or null if none has been set.

setSystemId

public void setSystemId(URI systemId)
Sets the optional System ID.

This gives an optional indication as to the location of the underlying stream being read.

Parameters:
systemId - The new value.

ready

public boolean ready()
Tests whether the underlying stream or reader contains more data waiting to be parsed.
This method should be called in preference to Reader.ready() and InputStream.available() since it may need to take into account data which has been buffered by the Source implementation.

Returns:
Whether there is unparsed data available.

getParseListener

public ParseListener getParseListener()
Returns the parse listener that will be notified of batch processing events.

Returns:
the parse listener.
See Also:
ParseListener

setParseListener

public void setParseListener(ParseListener listener)
Sets the parse listener that will be notified of batch processing events.

Parameters:
listener - the new listener.
See Also:
ParseListener

readObject

public abstract void readObject(ComplexDataObject object)
                         throws IOException
Reads an object from the the reader or input stream that has been set (optional operation).

Parameters:
object - The object into which the input data should be parsed.
Throws:
IOException - If the complete object could not be read for any reason.
IllegalArgumentException - If neither a reader nor an input stream has been set.
UnsupportedOperationException - If this source does not support this method, in which case readObject(Element) should be used.

readObject

public abstract ComplexDataObject readObject(Element element)
                                      throws IOException
Reads an object from the the reader or input stream that has been set.

Parameters:
element - The element declaration to which the input data is expected to adhere.
Returns:
The newly created object.
Throws:
IOException - If the complete object could not be read for any reason.
IllegalArgumentException - If neither a reader nor an input stream has been set.

getMarkableInputStream

public InputStream getMarkableInputStream()

stream

protected InputStream stream()
Used by subclasses to get a reference to the input stream object responsible for reading the data.

Returns:
The input stream.

reader

protected Reader reader()
                 throws UnsupportedEncodingException
Used by subclasses to get a reference to the reader object responsible for reading the data.

Returns:
The reader.
Throws:
UnsupportedEncodingException - If the encoding is not supported.

checkInit

protected void checkInit()
Used by subclasses to ensure a reader or input stream has been set.

Throws:
IllegalArgumentException - If neither a reader nor an input stream has been set.

clone

public abstract Object clone()
Overrides:
clone in class Object


C24 Technologies © 2002-2012: All Rights Reserved.