[Git][java-team/jackson-dataformat-xml][upstream] New upstream version 2.9.8
Markus Koschany
gitlab at salsa.debian.org
Wed Dec 19 10:00:22 GMT 2018
Markus Koschany pushed to branch upstream at Debian Java Maintainers / jackson-dataformat-xml
Commits:
b86d18ff by Markus Koschany at 2018-12-19T09:50:31Z
New upstream version 2.9.8
- - - - -
7 changed files:
- pom.xml
- release-notes/VERSION-2.x
- src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java
- src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser294Test.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/ser/TestBinaryStreamToXMLSerialization.java
Changes:
=====================================
pom.xml
=====================================
@@ -4,11 +4,11 @@
<parent>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-base</artifactId>
- <version>2.9.7</version>
+ <version>2.9.8</version>
</parent>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
- <version>2.9.7</version>
+ <version>2.9.8</version>
<name>Jackson-dataformat-XML</name>
<packaging>bundle</packaging>
<description>Data format extension for Jackson (http://jackson.codehaus.org) to offer
@@ -21,7 +21,7 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
<connection>scm:git:git at github.com:FasterXML/jackson-dataformat-xml.git</connection>
<developerConnection>scm:git:git at github.com:FasterXML/jackson-dataformat-xml.git</developerConnection>
<url>http://github.com/FasterXML/jackson-dataformat-xml</url>
- <tag>jackson-dataformat-xml-2.9.7</tag>
+ <tag>jackson-dataformat-xml-2.9.8</tag>
</scm>
<properties>
<packageVersion.dir>com/fasterxml/jackson/dataformat/xml</packageVersion.dir>
@@ -103,6 +103,18 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
</dependency>
</dependencies>
+ <!-- Alas, need to include snapshot reference since otherwise can not find
+ snapshot of parent... -->
+ <repositories>
+ <repository>
+ <id>sonatype-nexus-snapshots</id>
+ <name>Sonatype Nexus Snapshots</name>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ <snapshots><enabled>true</enabled></snapshots>
+ </repository>
+ </repositories>
+
<build>
<plugins>
<plugin>
@@ -134,16 +146,4 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
</plugins>
</build>
- <profiles>
- <!-- 19-Feb-2012, tatu: Since we have some failing tests, may need to force release -->
- <profile>
- <id>force-release</id>
- <properties>
- <maven.test.skip>true</maven.test.skip>
- <skipTests>true</skipTests>
- </properties>
- </profile>
- </profiles>
- <!-- NOTE: repositories from parent POM -->
-
</project>
=====================================
release-notes/VERSION-2.x
=====================================
@@ -4,6 +4,13 @@ Project: jackson-dataformat-xml
= Releases
------------------------------------------------------------------------
+2.9.8 (15-Dec-2018)
+
+#270: Add support for `writeBinary()` with `InputStream` to `ToXMLGenerator`
+ (requested by csbxvs at github; contributed by marc-christian-schulze at github)
+#323: Replace slow string concatenation with faster `StringBuilder` (for
+ long text content)
+
2.9.7 (19-Sep-2018)
No changes since 2.9.6
=====================================
src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java
=====================================
@@ -377,11 +377,11 @@ public class XmlTokenStream
return "";
}
- String text = null;
+ CharSequence chars = null;
while (true) {
switch (_xmlReader.next()) {
case XMLStreamConstants.START_ELEMENT:
- return (text == null) ? "" : text;
+ return (chars == null) ? "" : chars.toString();
case XMLStreamConstants.END_ELEMENT:
case XMLStreamConstants.END_DOCUMENT:
@@ -389,26 +389,29 @@ public class XmlTokenStream
// as `null`, by below, but that breaks existing tests so not
// done at least until 3.0.
/*
- if (text == null) {
+ if (chars == null) {
if (FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures)) {
return null;
}
return "";
}
- return text;
+ return chars;
*/
- return (text == null) ? "" : text;
-
+ return (chars == null) ? "" : chars.toString();
+
// note: SPACE is ignorable (and seldom seen), not to be included
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.CDATA:
// 17-Jul-2017, tatu: as per [dataformat-xml#236], need to try to...
{
String str = _getText(_xmlReader);
- if (text == null) {
- text = str;
- } else {
- text += str;
+ if (chars == null) {
+ chars = str;
+ } else {
+ if (chars instanceof String) {
+ chars = new StringBuilder(chars);
+ }
+ ((StringBuilder)chars).append(str);
}
}
break;
=====================================
src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java
=====================================
@@ -840,6 +840,69 @@ public final class ToXmlGenerator
}
}
+ @Override
+ public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) throws IOException
+ {
+ if (data == null) {
+ writeNull();
+ return 0;
+ }
+ _verifyValueWrite("write Binary value");
+ if (_nextName == null) {
+ handleMissingName();
+ }
+ try {
+ if (_nextIsAttribute) {
+ // Stax2 API only has 'full buffer' write method:
+ byte[] fullBuffer = toFullBuffer(data, dataLength);
+ _xmlWriter.writeBinaryAttribute("", _nextName.getNamespaceURI(), _nextName.getLocalPart(), fullBuffer);
+ } else if (checkNextIsUnwrapped()) {
+ // should we consider pretty-printing or not?
+ writeStreamAsBinary(data, dataLength);
+
+ } else {
+ if (_xmlPrettyPrinter != null) {
+ _xmlPrettyPrinter.writeLeafElement(_xmlWriter,
+ _nextName.getNamespaceURI(), _nextName.getLocalPart(),
+ toFullBuffer(data, dataLength), 0, dataLength);
+ } else {
+ _xmlWriter.writeStartElement(_nextName.getNamespaceURI(), _nextName.getLocalPart());
+ writeStreamAsBinary(data, dataLength);
+ _xmlWriter.writeEndElement();
+ }
+ }
+ } catch (XMLStreamException e) {
+ StaxUtil.throwAsGenerationException(e, this);
+ }
+
+ return dataLength;
+ }
+
+ private void writeStreamAsBinary(InputStream data, int len) throws IOException, XMLStreamException
+ {
+ // base64 encodes up to 3 bytes into a 4 bytes string
+ byte[] tmp = new byte[3];
+ int offset = 0;
+ int read;
+ while((read = data.read(tmp, offset, Math.min(3 - offset, len))) != -1) {
+ offset += read;
+ len -= read;
+ if(offset == 3) {
+ offset = 0;
+ _xmlWriter.writeBinary(tmp, 0, 3);
+ }
+ if (len == 0) {
+ break;
+ }
+ }
+
+ // we still have < 3 bytes in the buffer
+ if(offset > 0) {
+ _xmlWriter.writeBinary(tmp, 0, offset);
+ }
+ }
+
+
private byte[] toFullBuffer(byte[] data, int offset, int len)
{
// might already be ok:
@@ -852,7 +915,22 @@ public final class ToXmlGenerator
}
return result;
}
-
+
+ private byte[] toFullBuffer(InputStream data, final int len) throws IOException
+ {
+ byte[] result = new byte[len];
+ int offset = 0;
+
+ for (; offset < len; ) {
+ int count = data.read(result, offset, len - offset);
+ if (count < 0) {
+ _reportError("Too few bytes available: missing "+(len - offset)+" bytes (out of "+len+")");
+ }
+ offset += count;
+ }
+ return result;
+ }
+
/*
/**********************************************************
/* Output method implementations, primitive
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java
=====================================
@@ -1,7 +1,5 @@
package com.fasterxml.jackson.dataformat.xml.deser.builder;
-import java.util.*;
-
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.Version;
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser294Test.java
=====================================
@@ -2,7 +2,6 @@ package com.fasterxml.jackson.dataformat.xml.failing;
import java.util.*;
-import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/ser/TestBinaryStreamToXMLSerialization.java
=====================================
@@ -0,0 +1,61 @@
+package com.fasterxml.jackson.dataformat.xml.ser;
+
+import java.nio.*;
+
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
+
+/**
+ * See <a href="https://github.com/FasterXML/jackson-dataformat-xml/issues/270">issue #270</a>
+ * for details
+ */
+public class TestBinaryStreamToXMLSerialization extends XmlTestBase
+{
+ private final XmlMapper MAPPER = new XmlMapper();
+
+ public void testWith0Bytes() throws Exception
+ {
+ String xml = MAPPER.writeValueAsString(createPojo());
+ assertEquals("<TestPojo><field/></TestPojo>", xml);
+ }
+
+ public void testWith1Byte() throws Exception
+ {
+ String xml = MAPPER.writeValueAsString(createPojo( 'A' ));
+ assertEquals("<TestPojo><field>QQ==</field></TestPojo>", xml);
+ }
+
+ public void testWith2Bytes() throws Exception
+ {
+ String xml = MAPPER.writeValueAsString(createPojo( 'A', 'B' ));
+ assertEquals("<TestPojo><field>QUI=</field></TestPojo>", xml);
+ }
+
+ public void testWith3Bytes() throws Exception
+ {
+ String xml = MAPPER.writeValueAsString(createPojo( 'A', 'B', 'C' ));
+ assertEquals("<TestPojo><field>QUJD</field></TestPojo>", xml);
+ }
+
+ public void testWith4Bytes() throws Exception
+ {
+ String xml = MAPPER.writeValueAsString(createPojo( 'A', 'B', 'C', 'D' ));
+ assertEquals("<TestPojo><field>QUJDRA==</field></TestPojo>", xml);
+ }
+
+ private TestPojo createPojo(char... content) {
+ TestPojo obj = new TestPojo();
+ // DirectByteBuffer does not have an underlying array
+ // so the ByteArraySerializer has to fallback to stream writing
+ obj.field = ByteBuffer.allocateDirect(content.length);
+ for(char b : content) {
+ obj.field.put((byte) b);
+ }
+ obj.field.position(0);
+ return obj;
+ }
+
+ public static class TestPojo {
+ public ByteBuffer field;
+ }
+}
View it on GitLab: https://salsa.debian.org/java-team/jackson-dataformat-xml/commit/b86d18ff331d0748354e65243fed113d45847311
--
View it on GitLab: https://salsa.debian.org/java-team/jackson-dataformat-xml/commit/b86d18ff331d0748354e65243fed113d45847311
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20181219/89ec35cf/attachment.html>
More information about the pkg-java-commits
mailing list