Skip to content

Commit

Permalink
XStreamMarshaller supports stream directly
Browse files Browse the repository at this point in the history
XStreamMarshaller now supports writing to OutputStreams and reading from
InputStreams directly, as opposed to wrapping streams in a
OutputStreamWriter or InputStreamReader.

Issue: SPR-9663
  • Loading branch information
poutsma committed Aug 13, 2012
1 parent 4e0977c commit 7187a24
Showing 1 changed file with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,12 @@ protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter

@Override
protected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException {
marshalWriter(graph, new OutputStreamWriter(outputStream, this.encoding));
if (this.streamDriver != null) {
marshal(graph, this.streamDriver.createWriter(outputStream));
}
else {
marshalWriter(graph, new OutputStreamWriter(outputStream, this.encoding));
}
}

@Override
Expand Down Expand Up @@ -483,12 +488,7 @@ else if (node instanceof Element) {
else {
throw new IllegalArgumentException("DOMSource contains neither Document nor Element");
}
try {
return getXStream().unmarshal(streamReader);
}
catch (Exception ex) {
throw convertXStreamException(ex, false);
}
return unmarshal(streamReader);
}

@Override
Expand All @@ -504,36 +504,27 @@ protected Object unmarshalXmlEventReader(XMLEventReader eventReader) throws XmlM

@Override
protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException {
try {
HierarchicalStreamReader hierarchicalStreamReader =
new StaxReader(new QNameMap(),streamReader);
return getXStream().unmarshal(hierarchicalStreamReader);
}
catch (Exception ex) {
throw convertXStreamException(ex, false);
}
return unmarshal(new StaxReader(new QNameMap(), streamReader));
}

@Override
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
return unmarshalReader(new InputStreamReader(inputStream, this.encoding));
if (this.streamDriver != null) {
return unmarshal(this.streamDriver.createReader(inputStream));
}
else {
return unmarshalReader(new InputStreamReader(inputStream, this.encoding));
}
}

@Override
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
try {
HierarchicalStreamReader streamReader;
if (this.streamDriver != null) {
streamReader = this.streamDriver.createReader(reader);
}
else {
streamReader = new XppReader(reader);
}
return getXStream().unmarshal(streamReader);
}
catch (Exception ex) {
throw convertXStreamException(ex, false);
}
if (this.streamDriver != null) {
return unmarshal(this.streamDriver.createReader(reader));
}
else {
return unmarshal(new XppReader(reader));
}
}

@Override
Expand All @@ -544,7 +535,21 @@ protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource
"XStreamMarshaller does not support unmarshalling using SAX XMLReaders");
}

/**
/**
* Unmarshals the given graph to the given XStream HierarchicalStreamWriter.
* Converts exceptions using {@link #convertXStreamException}.
*/
private Object unmarshal(HierarchicalStreamReader streamReader) {
try {
return getXStream().unmarshal(streamReader);
}
catch (Exception ex) {
throw convertXStreamException(ex, false);
}
}


/**
* Convert the given XStream exception to an appropriate exception from the
* <code>org.springframework.oxm</code> hierarchy.
* <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
Expand Down

0 comments on commit 7187a24

Please sign in to comment.