javax.xml.transform.stream

Class StreamResult

Implemented Interfaces:
Result

public class StreamResult
extends java.lang.Object
implements Result

Acts as an holder for a transformation result, which may be XML, plain Text, HTML, or some other form of markup.
Author:
Jeff Suttor

Field Summary

static String
FEATURE
If TransformerFactory.getFeature(String) returns true when passed this value as an argument, the Transformer supports Result output of this type.

Fields inherited from interface javax.xml.transform.Result

PI_DISABLE_OUTPUT_ESCAPING, PI_ENABLE_OUTPUT_ESCAPING

Constructor Summary

StreamResult()
Zero-argument default constructor.
StreamResult(File f)
Construct a StreamResult from a File.
StreamResult(OutputStream outputStream)
Construct a StreamResult from a byte stream.
StreamResult(String systemId)
Construct a StreamResult from a URL.
StreamResult(Writer writer)
Construct a StreamResult from a character stream.

Method Summary

OutputStream
getOutputStream()
Get the byte stream that was set with setOutputStream.
String
getSystemId()
Get the system identifier that was set with setSystemId.
Writer
getWriter()
Get the character stream that was set with setWriter.
void
setOutputStream(OutputStream outputStream)
Set the ByteStream that is to be written to.
void
setSystemId(File f)
Set the system ID from a File reference.
void
setSystemId(String systemId)
Set the systemID that may be used in association with the byte or character stream, or, if neither is set, use this value as a writeable URI (probably a file name).
void
setWriter(Writer writer)
Set the writer that is to receive the result.

Field Details

FEATURE

public static final String FEATURE
If TransformerFactory.getFeature(String) returns true when passed this value as an argument, the Transformer supports Result output of this type.

Constructor Details

StreamResult

public StreamResult()
Zero-argument default constructor.

StreamResult

public StreamResult(File f)
Construct a StreamResult from a File.
Parameters:
f - Must a non-null File reference.

StreamResult

public StreamResult(OutputStream outputStream)
Construct a StreamResult from a byte stream. Normally, a stream should be used rather than a reader, so that the transformer may use instructions contained in the transformation instructions to control the encoding.
Parameters:
outputStream - A valid OutputStream reference.

StreamResult

public StreamResult(String systemId)
Construct a StreamResult from a URL.
Parameters:
systemId - Must be a String that conforms to the URI syntax.

StreamResult

public StreamResult(Writer writer)
Construct a StreamResult from a character stream. Normally, a stream should be used rather than a reader, so that the transformer may use instructions contained in the transformation instructions to control the encoding. However, there are times when it is useful to write to a character stream, such as when using a StringWriter.
Parameters:
writer - A valid Writer reference.

Method Details

getOutputStream

public OutputStream getOutputStream()
Get the byte stream that was set with setOutputStream.
Returns:
The byte stream that was set with setOutputStream, or null if setOutputStream or the ByteStream constructor was not called.

getSystemId

public String getSystemId()
Get the system identifier that was set with setSystemId.
Specified by:
getSystemId in interface Result
Returns:
The system identifier that was set with setSystemId, or null if setSystemId was not called.

getWriter

public Writer getWriter()
Get the character stream that was set with setWriter.
Returns:
The character stream that was set with setWriter, or null if setWriter or the Writer constructor was not called.

setOutputStream

public void setOutputStream(OutputStream outputStream)
Set the ByteStream that is to be written to. Normally, a stream should be used rather than a reader, so that the transformer may use instructions contained in the transformation instructions to control the encoding.
Parameters:
outputStream - A valid OutputStream reference.

setSystemId

public void setSystemId(File f)
Set the system ID from a File reference.

Note the use of File.toURI() and File.toURL(). toURI() is prefered and used if possible. To allow JAXP 1.3 to run on J2SE 1.3, toURL() is used if a NoSuchMethodException is thrown by the attempt to use toURI().

Parameters:
f - Must a non-null File reference.

setSystemId

public void setSystemId(String systemId)
Set the systemID that may be used in association with the byte or character stream, or, if neither is set, use this value as a writeable URI (probably a file name).
Specified by:
setSystemId in interface Result
Parameters:
systemId - The system identifier as a URI string.

setWriter

public void setWriter(Writer writer)
Set the writer that is to receive the result. Normally, a stream should be used rather than a writer, so that the transformer may use instructions contained in the transformation instructions to control the encoding. However, there are times when it is useful to write to a writer, such as when using a StringWriter.
Parameters:
writer - A valid Writer reference.