APIdia Launch Partner
Top Description Fields Constructors Methods
javax.xml.transform.stream

public Class StreamSource

extends Object
implements Source
Class Inheritance
All Implemented Interfaces
javax.xml.transform.Source
Imports
java.io.File, .IOException, .InputStream, .Reader, javax.xml.transform.Result, .Source

Acts as an holder for a transformation Source in the form of a stream of XML markup.

Note

Due to their internal use of either a Reader or InputStream instance, StreamSource instances may only be used once.

Author
Jeff Suttor
Since
1.4

Field Summary

Modifier and TypeField and Description
public static final String
FEATURE

If javax.xml.transform.TransformerFactory#getFeature returns true when passed this value as an argument, the Transformer supports Source input of this type.

private InputStream
inputStream

The byte stream for this Source, or null.

private String
publicId

The public identifier for this input source, or null.

private Reader
reader

The character stream for this Source, or null.

private String
systemId

The system identifier as a URL string, or null.

Constructor Summary

AccessConstructor and Description
public
StreamSource()

Zero-argument default constructor.

public
StreamSource(InputStream
A valid InputStream reference to an XML stream.
inputStream
)

Construct a StreamSource from a byte stream.

public
StreamSource(InputStream
A valid InputStream reference to an XML stream.
inputStream
,
String
Must be a String that conforms to the URI syntax.
systemId
)

Construct a StreamSource from a byte stream.

public
StreamSource(Reader
A valid Reader reference to an XML character stream.
reader
)

Construct a StreamSource from a character reader.

public
StreamSource(Reader
A valid Reader reference to an XML character stream.
reader
,
String
Must be a String that conforms to the URI syntax.
systemId
)

Construct a StreamSource from a character reader.

public
StreamSource(String
Must be a String that conforms to the URI syntax.
systemId
)

Construct a StreamSource from a URL.

public
StreamSource(File
Must a non-null File reference.
f
)

Construct a StreamSource from a File.

Method Summary

Modifier and TypeMethod and Description
public InputStream

Returns:

The byte stream that was set with setByteStream, or null if setByteStream or the ByteStream constructor was not called.
getInputStream
()

Get the byte stream that was set with setByteStream.

public String

Returns:

The public identifier that was set with setPublicId, or null if setPublicId was not called.
getPublicId
()

Get the public identifier that was set with setPublicId.

public Reader

Returns:

The character stream that was set with setReader, or null if setReader or the Reader constructor was not called.
getReader
()

Get the character stream that was set with setReader.

public String

Returns:

The system identifier that was set with setSystemId, or null if setSystemId was not called.
getSystemId
()

Implements javax.xml.transform.Source.getSystemId.

Get the system identifier that was set with setSystemId.

public boolean

Returns:

true if the StreamSource object is empty, false otherwise
isEmpty
()

Overrides default javax.xml.transform.Source.isEmpty.

Indicates whether the StreamSource object is empty.

private boolean
public void
setInputStream(InputStream
A valid InputStream reference to an XML stream.
inputStream
)

Set the byte stream to be used as input.

public void
setPublicId(String
The public identifier as a string.
publicId
)

Set the public identifier for this Source.

public void
setReader(Reader
A valid Reader reference to an XML CharacterStream.
reader
)

Set the input to be a character reader.

public void
setSystemId(String
The system identifier as a URL string.
systemId
)

Implements javax.xml.transform.Source.setSystemId.

Set the system identifier for this Source.

public void
setSystemId(File
Must a non-null File reference.
f
)

Set the system ID from a File reference.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FEATUREback to summary
public static final String FEATURE

If javax.xml.transform.TransformerFactory#getFeature returns true when passed this value as an argument, the Transformer supports Source input of this type.

inputStreamback to summary
private InputStream inputStream

The byte stream for this Source, or null.

publicIdback to summary
private String publicId

The public identifier for this input source, or null.

readerback to summary
private Reader reader

The character stream for this Source, or null.

systemIdback to summary
private String systemId

The system identifier as a URL string, or null.

Constructor Detail

StreamSourceback to summary
public StreamSource()

Zero-argument default constructor. If this constructor is used, and no Stream source is set using setInputStream(java.io.InputStream inputStream) or setReader(java.io.Reader reader), then the Transformer will create an empty source java.io.InputStream using new InputStream().

See Also
javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget)
StreamSourceback to summary
public StreamSource(InputStream inputStream)

Construct a StreamSource from a byte stream. Normally, a stream should be used rather than a reader, so the XML parser can resolve character encoding specified by the XML declaration.

If this constructor is used to process a stylesheet, normally setSystemId should also be called, so that relative URI references can be resolved.

Parameters
inputStream:InputStream

A valid InputStream reference to an XML stream.

StreamSourceback to summary
public StreamSource(InputStream inputStream, String systemId)

Construct a StreamSource from a byte stream. Normally, a stream should be used rather than a reader, so that the XML parser can resolve character encoding specified by the XML declaration.

This constructor allows the systemID to be set in addition to the input stream, which allows relative URIs to be processed.

Parameters
inputStream:InputStream

A valid InputStream reference to an XML stream.

systemId:String

Must be a String that conforms to the URI syntax.

StreamSourceback to summary
public StreamSource(Reader reader)

Construct a StreamSource from a character reader. Normally, a stream should be used rather than a reader, so that the XML parser can resolve character encoding specified by the XML declaration. However, in many cases the encoding of the input stream is already resolved, as in the case of reading XML from a StringReader.

Parameters
reader:Reader

A valid Reader reference to an XML character stream.

StreamSourceback to summary
public StreamSource(Reader reader, String systemId)

Construct a StreamSource from a character reader. Normally, a stream should be used rather than a reader, so that the XML parser may resolve character encoding specified by the XML declaration. However, in many cases the encoding of the input stream is already resolved, as in the case of reading XML from a StringReader.

Parameters
reader:Reader

A valid Reader reference to an XML character stream.

systemId:String

Must be a String that conforms to the URI syntax.

StreamSourceback to summary
public StreamSource(String systemId)

Construct a StreamSource from a URL.

Parameters
systemId:String

Must be a String that conforms to the URI syntax.

StreamSourceback to summary
public StreamSource(File f)

Construct a StreamSource from a File.

Parameters
f:File

Must a non-null File reference.

Method Detail

getInputStreamback to summary
public InputStream getInputStream()

Get the byte stream that was set with setByteStream.

Returns:InputStream

The byte stream that was set with setByteStream, or null if setByteStream or the ByteStream constructor was not called.

getPublicIdback to summary
public String getPublicId()

Get the public identifier that was set with setPublicId.

Returns:String

The public identifier that was set with setPublicId, or null if setPublicId was not called.

getReaderback to summary
public Reader getReader()

Get the character stream that was set with setReader.

Returns:Reader

The character stream that was set with setReader, or null if setReader or the Reader constructor was not called.

getSystemIdback to summary
public String getSystemId()

Implements javax.xml.transform.Source.getSystemId.

Get the system identifier that was set with setSystemId.

Returns:String

The system identifier that was set with setSystemId, or null if setSystemId was not called.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides default javax.xml.transform.Source.isEmpty.

Indicates whether the StreamSource object is empty. Empty is defined as follows:

  • All of the input sources, including the public identifier, system identifier, byte stream, and character stream, are null.
  • The public identifier and system identifier are null, and byte and character stream are either null or contain no byte or character.

    Note that this method will reset the byte stream if it is provided, or the character stream if the byte stream is not provided.

In case of error while checking the byte or character stream, the method will return false to allow the XML processor to handle the error.

Returns:boolean

true if the StreamSource object is empty, false otherwise

Annotations
@Override
isStreamEmptyback to summary
private boolean isStreamEmpty()
setInputStreamback to summary
public void setInputStream(InputStream inputStream)

Set the byte stream to be used as input. Normally, a stream should be used rather than a reader, so that the XML parser can resolve character encoding specified by the XML declaration.

If this Source object is used to process a stylesheet, normally setSystemId should also be called, so that relative URL references can be resolved.

Parameters
inputStream:InputStream

A valid InputStream reference to an XML stream.

setPublicIdback to summary
public void setPublicId(String publicId)

Set the public identifier for this Source.

The public identifier is always optional: if the application writer includes one, it will be provided as part of the location information.

Parameters
publicId:String

The public identifier as a string.

setReaderback to summary
public void setReader(Reader reader)

Set the input to be a character reader. Normally, a stream should be used rather than a reader, so that the XML parser can resolve character encoding specified by the XML declaration. However, in many cases the encoding of the input stream is already resolved, as in the case of reading XML from a StringReader.

Parameters
reader:Reader

A valid Reader reference to an XML CharacterStream.

setSystemIdback to summary
public void setSystemId(String systemId)

Implements javax.xml.transform.Source.setSystemId.

Set the system identifier for this Source.

The system identifier is optional if there is a byte stream or a character stream, but it is still useful to provide one, since the application can use it to resolve relative URIs and can include it in error messages and warnings (the parser will attempt to open a connection to the URI only if there is no byte stream or character stream specified).

Parameters
systemId:String

The system identifier as a URL string.

Annotations
@Override
setSystemIdback to summary
public void setSystemId(File f)

Set the system ID from a File reference.

Parameters
f:File

Must a non-null File reference.