org.apache.axiom.om.ds
Class InputStreamDataSource

java.lang.Object
  extended by org.apache.axiom.om.ds.OMDataSourceExtBase
      extended by org.apache.axiom.om.ds.InputStreamDataSource
All Implemented Interfaces:
OMDataSource, OMDataSourceExt

public class InputStreamDataSource
extends OMDataSourceExtBase

InputStream is an example OMDataSourceExt. Use it to insert a (InputStream, encoding) into an OM Tree. This data source is useful for placing an InputStream into an OM tree, instead of having a deeply nested tree.


Nested Class Summary
 class InputStreamDataSource.Data
          Object containing the InputStream/encoding pair
 
Field Summary
private static int BUFFER_LEN
           
(package private)  InputStreamDataSource.Data data
           
 
Fields inherited from class org.apache.axiom.om.ds.OMDataSourceExtBase
map
 
Constructor Summary
InputStreamDataSource(java.io.InputStream is, java.lang.String encoding)
          Constructor
 
Method Summary
 void close()
          Close the DataSource and free its resources.
 OMDataSourceExt copy()
          Return a InputStreamDataSource backed by a ByteArrayInputStream
 java.lang.Object getObject()
          Returns the backing Object.
 javax.xml.stream.XMLStreamReader getReader()
          Get parser for element data.
 byte[] getXMLBytes(java.lang.String encoding)
          Returns a byte[] representing the xml data
 java.io.InputStream getXMLInputStream(java.lang.String encoding)
          Returns a InputStream representing the xml data
private static void inputStream2OutputStream(java.io.InputStream is, java.io.OutputStream os)
          Private utility to write the InputStream contents to the OutputStream.
 boolean isDestructiveRead()
          Returns true if reading the backing object is destructive.
 boolean isDestructiveWrite()
          Returns true if writing the backing object is destructive.
private static void reader2writer(javax.xml.stream.XMLStreamReader reader, javax.xml.stream.XMLStreamWriter writer)
          Simple utility that takes an XMLStreamReader and writes it to an XMLStreamWriter
 void serialize(java.io.OutputStream output, OMOutputFormat format)
          Serializes element data directly to stream.
 void serialize(javax.xml.stream.XMLStreamWriter xmlWriter)
          Serializes element data directly to StAX writer.
 
Methods inherited from class org.apache.axiom.om.ds.OMDataSourceExtBase
getProperty, hasProperty, serialize, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

InputStreamDataSource.Data data

BUFFER_LEN

private static final int BUFFER_LEN
See Also:
Constant Field Values
Constructor Detail

InputStreamDataSource

public InputStreamDataSource(java.io.InputStream is,
                             java.lang.String encoding)
Constructor

Parameters:
bytes -
encoding -
Method Detail

serialize

public void serialize(java.io.OutputStream output,
                      OMOutputFormat format)
               throws javax.xml.stream.XMLStreamException
Description copied from interface: OMDataSource
Serializes element data directly to stream.

Specified by:
serialize in interface OMDataSource
Specified by:
serialize in interface OMDataSourceExt
Overrides:
serialize in class OMDataSourceExtBase
Parameters:
output - destination stream for element XML text
format - output format information (null if none; may be ignored if not supported by data binding even if supplied)
Throws:
javax.xml.stream.XMLStreamException
See Also:
OMDataSourceExt

serialize

public void serialize(javax.xml.stream.XMLStreamWriter xmlWriter)
               throws javax.xml.stream.XMLStreamException
Description copied from interface: OMDataSource
Serializes element data directly to StAX writer.

Specified by:
serialize in interface OMDataSource
Specified by:
serialize in interface OMDataSourceExt
Overrides:
serialize in class OMDataSourceExtBase
Parameters:
xmlWriter - destination writer
Throws:
javax.xml.stream.XMLStreamException
See Also:
OMDataSourceExt

getReader

public javax.xml.stream.XMLStreamReader getReader()
                                           throws javax.xml.stream.XMLStreamException
Description copied from interface: OMDataSource
Get parser for element data. In the general case this may require the data source to serialize data as XML text and then parse that text.

Returns:
element parser
Throws:
javax.xml.stream.XMLStreamException

getXMLInputStream

public java.io.InputStream getXMLInputStream(java.lang.String encoding)
                                      throws java.io.UnsupportedEncodingException
Description copied from interface: OMDataSourceExt
Returns a InputStream representing the xml data

Specified by:
getXMLInputStream in interface OMDataSourceExt
Overrides:
getXMLInputStream in class OMDataSourceExtBase
Parameters:
encoding - String encoding of InputStream
Returns:
InputStream
Throws:
java.io.UnsupportedEncodingException

getObject

public java.lang.Object getObject()
Description copied from interface: OMDataSourceExt
Returns the backing Object.

Returns:
Object

isDestructiveRead

public boolean isDestructiveRead()
Description copied from interface: OMDataSourceExt
Returns true if reading the backing object is destructive. An example of an object with a destructive read is an InputSteam. The owning OMSourcedElement uses this information to detemine if OM tree expansion is needed when reading the OMDataSourceExt.

Returns:
boolean

isDestructiveWrite

public boolean isDestructiveWrite()
Description copied from interface: OMDataSourceExt
Returns true if writing the backing object is destructive. An example of an object with a destructive write is an InputStream. The owning OMSourcedElement uses this information to detemine if OM tree expansion is needed when writing the OMDataSourceExt.

Returns:
boolean

getXMLBytes

public byte[] getXMLBytes(java.lang.String encoding)
                   throws java.io.UnsupportedEncodingException
Description copied from interface: OMDataSourceExt
Returns a byte[] representing the xml data

Parameters:
encoding - String encoding of InputStream
Returns:
byte[]
Throws:
java.io.UnsupportedEncodingException
See Also:
getXMLInputStream

close

public void close()
Description copied from interface: OMDataSourceExt
Close the DataSource and free its resources.


copy

public OMDataSourceExt copy()
Return a InputStreamDataSource backed by a ByteArrayInputStream

Returns:
OMDataSourceExt

inputStream2OutputStream

private static void inputStream2OutputStream(java.io.InputStream is,
                                             java.io.OutputStream os)
                                      throws java.io.IOException
Private utility to write the InputStream contents to the OutputStream.

Parameters:
is -
os -
Throws:
java.io.IOException

reader2writer

private static void reader2writer(javax.xml.stream.XMLStreamReader reader,
                                  javax.xml.stream.XMLStreamWriter writer)
                           throws javax.xml.stream.XMLStreamException
Simple utility that takes an XMLStreamReader and writes it to an XMLStreamWriter

Parameters:
reader -
writer -
Throws:
javax.xml.stream.XMLStreamException