XStreamMarshaller supports stream directly
XStreamMarshaller now supports writing to OutputStreams and reading from InputStreams directly, as opposed to wrapping streams in a OutputStreamWriter or InputStreamReader. Issue: SPR-9663
This commit is contained in:
parent
4e0977ccdd
commit
7187a2435e
|
|
@ -425,7 +425,12 @@ public class XStreamMarshaller extends AbstractMarshaller implements Initializin
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException {
|
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
|
@Override
|
||||||
|
|
@ -483,12 +488,7 @@ public class XStreamMarshaller extends AbstractMarshaller implements Initializin
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("DOMSource contains neither Document nor Element");
|
throw new IllegalArgumentException("DOMSource contains neither Document nor Element");
|
||||||
}
|
}
|
||||||
try {
|
return unmarshal(streamReader);
|
||||||
return getXStream().unmarshal(streamReader);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
throw convertXStreamException(ex, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -504,36 +504,27 @@ public class XStreamMarshaller extends AbstractMarshaller implements Initializin
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException {
|
protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException {
|
||||||
try {
|
return unmarshal(new StaxReader(new QNameMap(), streamReader));
|
||||||
HierarchicalStreamReader hierarchicalStreamReader =
|
|
||||||
new StaxReader(new QNameMap(),streamReader);
|
|
||||||
return getXStream().unmarshal(hierarchicalStreamReader);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
throw convertXStreamException(ex, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
|
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
|
@Override
|
||||||
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
|
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
|
||||||
try {
|
if (this.streamDriver != null) {
|
||||||
HierarchicalStreamReader streamReader;
|
return unmarshal(this.streamDriver.createReader(reader));
|
||||||
if (this.streamDriver != null) {
|
}
|
||||||
streamReader = this.streamDriver.createReader(reader);
|
else {
|
||||||
}
|
return unmarshal(new XppReader(reader));
|
||||||
else {
|
}
|
||||||
streamReader = new XppReader(reader);
|
|
||||||
}
|
|
||||||
return getXStream().unmarshal(streamReader);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
throw convertXStreamException(ex, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -544,7 +535,21 @@ public class XStreamMarshaller extends AbstractMarshaller implements Initializin
|
||||||
"XStreamMarshaller does not support unmarshalling using SAX XMLReaders");
|
"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
|
* Convert the given XStream exception to an appropriate exception from the
|
||||||
* <code>org.springframework.oxm</code> hierarchy.
|
* <code>org.springframework.oxm</code> hierarchy.
|
||||||
* <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
|
* <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue