Java Code Examples for javax.xml.transform.stream.StreamResult#getWriter()

The following examples show how to use javax.xml.transform.stream.StreamResult#getWriter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractXMLOutputFactory.java    From jettison with Apache License 2.0 6 votes vote down vote up
public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException {
    // Can only support simplest of Result impls:
    if (result instanceof StreamResult) {
        StreamResult sr = (StreamResult) result;
        OutputStream out = sr.getOutputStream();
        if (out != null) {
            return createXMLStreamWriter(out);
        }
        Writer w = sr.getWriter();
        if (w != null) {
            return createXMLStreamWriter(w);
        }
        throw new UnsupportedOperationException("Only those javax.xml.transform.stream.StreamResult instances supported that have an OutputStream or Writer");
    }
    throw new UnsupportedOperationException("Only javax.xml.transform.stream.StreamResult type supported");
}
 
Example 2
Source File: XMLStreamWriterImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
Example 3
Source File: StreamSerializer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}
 
Example 4
Source File: AbstractMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Template method for handling {@code StreamResult}s.
 * <p>This implementation delegates to {@code marshalOutputStream} or {@code marshalWriter},
 * depending on what is contained in the {@code StreamResult}
 * @param graph the root of the object graph to marshal
 * @param streamResult the {@code StreamResult}
 * @throws IOException if an I/O Exception occurs
 * @throws XmlMappingException if the given object cannot be marshalled to the result
 * @throws IllegalArgumentException if {@code streamResult} does neither
 * contain an {@code OutputStream} nor a {@code Writer}
 */
protected void marshalStreamResult(Object graph, StreamResult streamResult)
		throws XmlMappingException, IOException {

	if (streamResult.getOutputStream() != null) {
		marshalOutputStream(graph, streamResult.getOutputStream());
	}
	else if (streamResult.getWriter() != null) {
		marshalWriter(graph, streamResult.getWriter());
	}
	else {
		throw new IllegalArgumentException("StreamResult contains neither OutputStream nor Writer");
	}
}
 
Example 5
Source File: XMLStreamWriterImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
Example 6
Source File: StreamSerializer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}
 
Example 7
Source File: XMLStreamWriterImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
Example 8
Source File: StreamSerializer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}
 
Example 9
Source File: XMLStreamWriterImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
Example 10
Source File: StreamSerializer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}
 
Example 11
Source File: AbstractMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Template method for handling {@code StreamResult}s.
 * <p>This implementation delegates to {@code marshalOutputStream} or {@code marshalWriter},
 * depending on what is contained in the {@code StreamResult}
 * @param graph the root of the object graph to marshal
 * @param streamResult the {@code StreamResult}
 * @throws IOException if an I/O Exception occurs
 * @throws XmlMappingException if the given object cannot be marshalled to the result
 * @throws IllegalArgumentException if {@code streamResult} does neither
 * contain an {@code OutputStream} nor a {@code Writer}
 */
protected void marshalStreamResult(Object graph, StreamResult streamResult)
		throws XmlMappingException, IOException {

	if (streamResult.getOutputStream() != null) {
		marshalOutputStream(graph, streamResult.getOutputStream());
	}
	else if (streamResult.getWriter() != null) {
		marshalWriter(graph, streamResult.getWriter());
	}
	else {
		throw new IllegalArgumentException("StreamResult contains neither OutputStream nor Writer");
	}
}
 
Example 12
Source File: XMLStreamWriterImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
Example 13
Source File: StreamSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}
 
Example 14
Source File: XMLStreamWriterImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
Example 15
Source File: StreamSerializer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}
 
Example 16
Source File: XMLStreamWriterImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
Example 17
Source File: StreamSerializer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}
 
Example 18
Source File: AbstractMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Template method for handling {@code StreamResult}s.
 * <p>This implementation delegates to {@code marshalOutputStream} or {@code marshalWriter},
 * depending on what is contained in the {@code StreamResult}
 * @param graph the root of the object graph to marshal
 * @param streamResult the {@code StreamResult}
 * @throws IOException if an I/O Exception occurs
 * @throws XmlMappingException if the given object cannot be marshalled to the result
 * @throws IllegalArgumentException if {@code streamResult} does neither
 * contain an {@code OutputStream} nor a {@code Writer}
 */
protected void marshalStreamResult(Object graph, StreamResult streamResult)
		throws XmlMappingException, IOException {

	if (streamResult.getOutputStream() != null) {
		marshalOutputStream(graph, streamResult.getOutputStream());
	}
	else if (streamResult.getWriter() != null) {
		marshalWriter(graph, streamResult.getWriter());
	}
	else {
		throw new IllegalArgumentException("StreamResult contains neither OutputStream nor Writer");
	}
}
 
Example 19
Source File: XMLStreamWriterImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
Example 20
Source File: StreamSerializer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}