com.softwareag.tamino.db.api.objectModel.stream
Class TStreamWriter

java.lang.Object
  extended by com.softwareag.tamino.db.api.objectModel.stream.TStreamWriter

public class TStreamWriter
extends java.lang.Object

TStreamWriter is capable to write byte or character input streams containing XML to byte or character output streams by making use of the SAX based event model. By doing this, it can always be ensured that well formed XML content is written to the specific character or byte output strea. It uses a SAX parser and internally acts as an event handler. By doing this it can be ensured that wellformed XML content is passed without I18N problems to the given sunk stream.

Version:
$Revision: 1.25 $
Author:
Marcus Schreyer

Constructor Summary
TStreamWriter()
          Default Constructor.
TStreamWriter(java.io.InputStream inputStream)
          Initializs the writer with the given byte input stream.
TStreamWriter(java.io.InputStream inputStream, int bufferSize)
          Initializs the writer with the given byte input stream and buffer size.
TStreamWriter(java.io.InputStream inputStream, java.lang.String systemId)
          Initializs the writer with the given byte input stream.
TStreamWriter(java.io.InputStream inputStream, java.lang.String systemId, int bufferSize)
          Initializs the writer with the given byte input stream and buffer size.
TStreamWriter(java.io.Reader reader)
          Initializs the writer with the given byte input stream.
TStreamWriter(java.io.Reader reader, int bufferSize)
          Initializs the writer with the given character input stream and buffer size.
TStreamWriter(java.io.Reader reader, java.lang.String systemId)
          Initializs the writer with the given byte input stream.
TStreamWriter(java.io.Reader reader, java.lang.String systemId, int bufferSize)
          Initializs the writer with the given character input stream and buffer size.
 
Method Summary
 java.lang.String getDocname()
          Gets the ino:docname from the underlying streams element.
 java.lang.String getId()
          Gets the ino:id if one is available.
 org.xml.sax.InputSource getInputSource()
          Gets the current input source.
 java.util.Locale getLocale()
          Gets the locale.
 java.lang.String getStartTag()
          Gets the name of the start tag.
 boolean hasWritableStream()
          Indicates whether the writer currently contains a writable stream.
 void setDocname(java.lang.String docname)
          Sets the ino:docname on the underlying streams element.
 void setId(java.lang.String id)
          Sets the ino:id on the underlying streams element.
 void setLocale(java.util.Locale locale)
          Sets the locale.
 void setWritableStream(java.io.InputStream inputStream)
          Sets a new writable byte input stream on the writer.
 void setWritableStream(java.io.InputStream inputStream, java.lang.String systemId)
          Sets a new writable byte input stream on the writer.
 void setWritableStream(java.io.Reader reader)
          Sets a new writable character input stream on the writer.
 void setWritableStream(java.io.Reader reader, java.lang.String systemId)
          Sets a new writable character input stream on the writer.
 void writeTo(java.io.OutputStream outputStream, java.lang.String encoding)
          Serializes the currently given underlying input stream to the given byte output stream.
 void writeTo(java.io.Writer writer, java.lang.String encoding)
          Serializes the currently given underlying input stream to the given character output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TStreamWriter

public TStreamWriter()
              throws java.lang.Exception
Default Constructor. Initializes the instance in a state where it cannot write a stream containing XML to a data sunk. This is due to the fact that no such input stream is given.

Throws:
java.lang.Exception

TStreamWriter

public TStreamWriter(java.io.InputStream inputStream,
                     int bufferSize)
              throws java.lang.Exception
Initializs the writer with the given byte input stream and buffer size. The buffer size indicates in which buffer range the entire stream content resides. This constructor only needs to be used if it is sure that the entire content resides within the first 1MB byte relative to the start of the input stream.

Parameters:
inputStream - denotes the byte input stream which XML content should be written to a data sunk
bufferSize - indicates the range in which the entire content. If it is less or equal 0 the default size of 1MB is taken.
Throws:
java.lang.Exception

TStreamWriter

public TStreamWriter(java.io.InputStream inputStream)
              throws java.lang.Exception
Initializs the writer with the given byte input stream. Please note, that the prerequesite here is that the entire start element is supposed to be within the first 1024 byte of the given input stream. If this is not the case use the overloaded constructor that takes the additional buffer size parameter.

Parameters:
inputStream - denotes the byte input stream which XML content should be written to a data sunk
Throws:
java.lang.Exception

TStreamWriter

public TStreamWriter(java.io.Reader reader,
                     int bufferSize)
              throws java.lang.Exception
Initializs the writer with the given character input stream and buffer size. The buffer size indicates in which buffer range the entire start element resides. This constructor only needs to be used if it is sure that the entire start tag might not be within the first 1024 byte relative to the start of the input stream.

Parameters:
reader - denotes the character input stream which XML content should be written to a data sunk
bufferSize - indicates the range in which the entire start element resides. If it is less or equal 0 the default size of 1024 is taken.
Throws:
java.lang.Exception

TStreamWriter

public TStreamWriter(java.io.Reader reader)
              throws java.lang.Exception
Initializs the writer with the given byte input stream. Please note, that the prerequesite here is that the entire start element is supposed to be within the first 1024 byte of the given input stream. If this is not the case use the overloaded constructor that takes the additional buffer size parameter.

Parameters:
reader - denotes the character input stream which XML content should be written to a data sunk
inputStream - denotes the byte input stream which XML content should be written to a data sunk
Throws:
java.lang.Exception

TStreamWriter

public TStreamWriter(java.io.InputStream inputStream,
                     java.lang.String systemId,
                     int bufferSize)
              throws java.lang.Exception
Initializs the writer with the given byte input stream and buffer size. The buffer size indicates in which buffer range the entire stream content resides. This constructor only needs to be used if it is sure that the entire content resides within the first 1MB byte relative to the start of the input stream.

Parameters:
inputStream - denotes the byte input stream which XML content should be written to a data sunk
bufferSize - indicates the range in which the entire content. If it is less or equal 0 the default size of 1MB is taken.
Throws:
java.lang.Exception

TStreamWriter

public TStreamWriter(java.io.InputStream inputStream,
                     java.lang.String systemId)
              throws java.lang.Exception
Initializs the writer with the given byte input stream. Please note, that the prerequesite here is that the entire start element is supposed to be within the first 1024 byte of the given input stream. If this is not the case use the overloaded constructor that takes the additional buffer size parameter.

Parameters:
inputStream - denotes the byte input stream which XML content should be written to a data sunk
Throws:
java.lang.Exception

TStreamWriter

public TStreamWriter(java.io.Reader reader,
                     java.lang.String systemId,
                     int bufferSize)
              throws java.lang.Exception
Initializs the writer with the given character input stream and buffer size. The buffer size indicates in which buffer range the entire start element resides. This constructor only needs to be used if it is sure that the entire start tag might not be within the first 1024 byte relative to the start of the input stream.

Parameters:
reader - denotes the character input stream which XML content should be written to a data sunk
bufferSize - indicates the range in which the entire start element resides. If it is less or equal 0 the default size of 1024 is taken.
Throws:
java.lang.Exception

TStreamWriter

public TStreamWriter(java.io.Reader reader,
                     java.lang.String systemId)
              throws java.lang.Exception
Initializs the writer with the given byte input stream. Please note, that the prerequesite here is that the entire start element is supposed to be within the first 1024 byte of the given input stream. If this is not the case use the overloaded constructor that takes the additional buffer size parameter.

Parameters:
reader - denotes the character input stream which XML content should be written to a data sunk
inputStream - denotes the byte input stream which XML content should be written to a data sunk
Throws:
java.lang.Exception
Method Detail

setDocname

public void setDocname(java.lang.String docname)
Sets the ino:docname on the underlying streams element.

Parameters:
docname - is the ino:docname attribute of the data object.

setId

public void setId(java.lang.String id)
Sets the ino:id on the underlying streams element.

Parameters:
id - denotes the ino:id that has to be set on the underlying element.

getDocname

public java.lang.String getDocname()
Gets the ino:docname from the underlying streams element.

Returns:
the ino:docname of the element, an empty string if none is available.

getId

public java.lang.String getId()
Gets the ino:id if one is available.

Returns:
the ino:id of the element, an empty string if none is available.

getStartTag

public java.lang.String getStartTag()
Gets the name of the start tag.

Returns:
the name of the start tag, en empty string if none is currently given.

setWritableStream

public void setWritableStream(java.io.InputStream inputStream)
                       throws java.lang.Exception
Sets a new writable byte input stream on the writer. Once this is done attributes can be retrieved and the underlying stream can be written to an output stream.

Parameters:
inputStream - denotes the byte input stream that shall be written to an output stream.
Throws:
java.lang.Exception

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale.


getLocale

public java.util.Locale getLocale()
Gets the locale.

Returns:
the locale.

setWritableStream

public void setWritableStream(java.io.InputStream inputStream,
                              java.lang.String systemId)
                       throws java.lang.Exception
Sets a new writable byte input stream on the writer. Once this is done attributes can be retrieved and the underlying stream can be written to an output stream.

Parameters:
inputStream - denotes the byte input stream that shall be written to an output stream.
systemId - the base URI of the data to resolve relative references.
Throws:
java.lang.Exception

setWritableStream

public void setWritableStream(java.io.Reader reader)
                       throws java.lang.Exception
Sets a new writable character input stream on the writer. Once this is done attributes can be retrieved and the underlying stream can be written to an output stream.

Parameters:
inputStream - denotes the character input stream that shall be written to an output stream.
Throws:
java.lang.Exception

setWritableStream

public void setWritableStream(java.io.Reader reader,
                              java.lang.String systemId)
                       throws java.lang.Exception
Sets a new writable character input stream on the writer. Once this is done attributes can be retrieved and the underlying stream can be written to an output stream.

Parameters:
inputStream - denotes the character input stream that shall be written to an output stream.
systemId - the base URI to resolve relative references.
Throws:
java.lang.Exception

writeTo

public void writeTo(java.io.Writer writer,
                    java.lang.String encoding)
             throws TStreamWriteException
Serializes the currently given underlying input stream to the given character output stream.

Parameters:
writer - denotes the character output stream to which the underlying stream shall be written to.
encoding - the enconding string set in the XML declaration.
Throws:
TStreamWriteException

writeTo

public void writeTo(java.io.OutputStream outputStream,
                    java.lang.String encoding)
             throws TStreamWriteException
Serializes the currently given underlying input stream to the given byte output stream.

Parameters:
writer - denotes the byte output stream to which the underlying stream shall be written to.
encoding - the enconding string set in the XML declaration.
Throws:
TStreamWriteException

hasWritableStream

public boolean hasWritableStream()
Indicates whether the writer currently contains a writable stream. If this is the case invoking of writeTo leads to the serialization of the writable stream to the relevant data sunk.

Returns:
true if currently a writable thus serializable stream is given, false otherwise.

getInputSource

public org.xml.sax.InputSource getInputSource()
Gets the current input source. Please note that obtaining and manipulating this input source might lead to conflicts when reusing this TStreamWriter without changing its change regarding the invocation of setWritableStream.

Returns:
the current InputSource.


Copyright (c) 2012 Software AG. All Rights Reserved.