FileDocCategorySizeDatePackage
StreamResult.javaAPI DocJava SE 5 API6448Fri Aug 26 14:58:24 BST 2005javax.xml.transform.stream

StreamResult

public class StreamResult extends 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

Fields Summary
public static final String
FEATURE
If {@link javax.xml.transform.TransformerFactory#getFeature} returns true when passed this value as an argument, the Transformer supports Result output of this type.
private String
systemId
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).
private OutputStream
outputStream
The byte stream that is to be written to.
private Writer
writer
The character stream that is to be written to.
Constructors Summary
public StreamResult()
Zero-argument default constructor.


            
      
    
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.

param
outputStream A valid OutputStream reference.

        setOutputStream(outputStream);
    
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.

param
writer A valid Writer reference.

        setWriter(writer);
    
public StreamResult(String systemId)
Construct a StreamResult from a URL.

param
systemId Must be a String that conforms to the URI syntax.

        this.systemId = systemId;
    
public StreamResult(File f)
Construct a StreamResult from a File.

param
f Must a non-null File reference.

        setSystemId(f);
    
Methods Summary
public java.io.OutputStreamgetOutputStream()
Get the byte stream that was set with setOutputStream.

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

        return outputStream;
    
public java.lang.StringgetSystemId()
Get the system identifier that was set with setSystemId.

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

        return systemId;
    
public java.io.WritergetWriter()
Get the character stream that was set with setWriter.

return
The character stream that was set with setWriter, or null if setWriter or the Writer constructor was not called.

        return writer;
    
public voidsetOutputStream(java.io.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.

param
outputStream A valid OutputStream reference.

        this.outputStream = outputStream;
    
public voidsetSystemId(java.lang.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).

param
systemId The system identifier as a URI string.

        this.systemId = systemId;
    
public voidsetSystemId(java.io.File f)

Set the system ID from a File reference.

Note the use of {@link File#toURI()} and {@link 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 {@link NoSuchMethodException} is thrown by the attempt to use toURI().

param
f Must a non-null File reference.

    	
    	try {
    		// assume >= 1.4
    		this.systemId = f.toURI().toString();
    	} catch (java.lang.NoSuchMethodError nme) {
    		// running on J2SE 1.3?
    		try {
        		this.systemId = f.toURL().toString();
    		} catch (MalformedURLException malformedURLException) {
    			this.systemId = null;
    			throw new RuntimeException(
    					"javax.xml.transform.stream.StreamResult#setSystemId(File f) with MalformedURLException: "
    					+ malformedURLException.toString()
    			);
    		}
        } catch (Exception exception) {
    		throw new RuntimeException(
    				"javax.xml.transform.stream.StreamResult#setSystemId(File f):"
    				+ " unexpected Exception: " + exception.toString()
			);
    		
        }
    
public voidsetWriter(java.io.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.

param
writer A valid Writer reference.

        this.writer = writer;