biz.c24.io.api.presentation
Class Sink

java.lang.Object
  extended by biz.c24.io.api.presentation.Sink
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
BinarySink, DefaultSink, InterchangeSink, JavaClassSink, JsonSink, SAXSink, SSSink, SwiftSink, TagValuePairSink, TextualSink, XMLSink

public abstract class Sink
extends Object
implements Cloneable, Serializable

A class used to write data objects to an output stream or writer in a specific format.
This class is subclassed by format specific specialisations.
The output stream or writer 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 output stream has been set then the stream will be wrapped by a OutputStreamWriter using the default charset. Therefore if an encoding other than the default is required, a java.io.OutputStreamWriter should be instatiated with that encoding and then supplied to this class.

See Also:
Serialized Form

Constructor Summary
Sink()
          Constructs a new instance.
Sink(OutputStream stream)
          Constructs a new instance which will write to stream (optional operation).
Sink(Writer writer)
          Constructs a new instance which will write to writer (optional operation).
 
Method Summary
protected  void checkInit()
          Used by subclasses to ensure a writer or output stream has been set.
 void clearBatchIterators()
          Clears all batch iterators registered with this Sink.
abstract  Object clone()
           
 String getEncoding()
          Get the character encoding for a byte stream.
 OutputStream getOutputStream()
          Returns the output stream (optional operation).
 Writer getWriter()
          Returns the writer (optional operation).
 void registerBatchIterator(Class batchedClass, Iterator batchIterator)
          Register a batch iterator against a particular class of batch entry.
 void setEncoding(String encoding)
          Set the character encoding for a byte stream.
 void setOutputStream(OutputStream stream)
          Sets the output stream (optional operation).
 void setWriter(Writer writer)
          Sets the writer (optional operation).
protected  OutputStream stream()
          Used by subclasses to get a reference to the output stream object responsible for writing the data.
 void unregisterBatchIterator(Class batchedClass)
          Unregisters an iterator from a particular class of batch entry.
abstract  void writeObject(ComplexDataObject obj)
          Writes an object to the writer or output stream that has been set.
protected  Writer writer()
          Used by subclasses to get a reference to the object responsible for writing the data.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sink

public Sink()
Constructs a new instance.


Sink

public Sink(Writer writer)
Constructs a new instance which will write to writer (optional operation).

Parameters:
writer - The writer to write the data to.
Throws:
UnsupportedOperationException - If this source does not support output to a java.io.Writer, in which case a java.io.OutputStream should be used.

Sink

public Sink(OutputStream stream)
Constructs a new instance which will write to stream (optional operation).

Parameters:
stream - The stream to write the data to.
Throws:
UnsupportedOperationException - If this source does not support output to a java.io.OutputStream, in which case a java.io.Writer should be used.
Method Detail

setWriter

public void setWriter(Writer writer)
Sets the writer (optional operation).

Parameters:
writer - The new value.
Throws:
UnsupportedOperationException - If this source does not support output to a java.io.Writer, in which case a java.io.OutputStream should be used.

getWriter

public Writer getWriter()
Returns the writer (optional operation).

Returns:
The writer.
Throws:
UnsupportedOperationException - If this source does not support output to a java.io.Writer, in which case a java.io.OutputStream should be used.

setOutputStream

public void setOutputStream(OutputStream stream)
Sets the output stream (optional operation).

Parameters:
stream - The new value.
Throws:
UnsupportedOperationException - If this source does not support output to a java.io.OutputStream, in which case a java.io.Writer should be used.

getOutputStream

public OutputStream getOutputStream()
Returns the output stream (optional operation).

Returns:
The stream.
Throws:
UnsupportedOperationException - If this source does not support output to a java.io.OutputStream, in which case a java.io.Writer 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 sink instance store 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 sink instance store binary data.

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

writeObject

public abstract void writeObject(ComplexDataObject obj)
                          throws IOException
Writes an object to the writer or output stream that has been set.

Parameters:
obj - The object to be written.
Throws:
IOException - If the complete object could not be written for any reason.
IllegalArgumentException - If neither a writer nor an output stream has been set.

stream

protected OutputStream stream()
Used by subclasses to get a reference to the output stream object responsible for writing the data.

Returns:
The output stream.

writer

protected Writer writer()
                 throws UnsupportedEncodingException
Used by subclasses to get a reference to the object responsible for writing the data.

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

checkInit

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

Throws:
IllegalArgumentException - If neither a writer nor an output stream has been set.

registerBatchIterator

public void registerBatchIterator(Class batchedClass,
                                  Iterator batchIterator)
Register a batch iterator against a particular class of batch entry.
Batch iterators provide a hook by which any number of instances can returned from the iterator and therefore appear in the output even though they are not referenced by the object supplied to the writeObject(biz.c24.io.api.data.ComplexDataObject) method.

Parameters:
batchedClass - The class of the generated Element, DataType, or ComplexDataObject to register the iterator against.
batchIterator - The iterator which will return the instances.
Throws:
NullPointerException - If either argument is null
IllegalArgumentException - If either of the arguments are not of the correct type or are taken directly from the C24 Integration Objects API. \

unregisterBatchIterator

public void unregisterBatchIterator(Class batchedClass)
Unregisters an iterator from a particular class of batch entry.

Parameters:
batchedClass - The class which should be cleared from the map.
See Also:
registerBatchIterator(Class, java.util.Iterator)

clearBatchIterators

public void clearBatchIterators()
Clears all batch iterators registered with this Sink.


clone

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


C24 Technologies © 2002-2012: All Rights Reserved.