Codebase list libxstream-java / debian/1.4.18-1
Drop support for mxparser Markus Koschany 2 years ago
5 changed file(s) with 2022 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
22 * Team upload.
33 * New upstream version 1.4.18.
44 * Declare compliance with Debian Policy 4.6.0.
5 * Drop support for mxparser for now.
56
67 -- Markus Koschany <apo@debian.org> Fri, 27 Aug 2021 16:20:01 +0200
78
0 Description: Replaces the call to Method.isDefault() by a reflexive call to compile with Java 7
1 Author: Emmanuel Bourg <ebourg@apache.org>
0 From: Emmanuel Bourg <ebourg@apache.org>
1 Date: Fri, 27 Aug 2021 16:26:02 +0200
2 Subject: Replaces the call to Method.isDefault() by a reflexive call to
3 compile with Java 7
4
25 Forwarded: not-needed
6 ---
7 .../src/java/com/thoughtworks/xstream/mapper/LambdaMapper.java | 10 +++++++++-
8 1 file changed, 9 insertions(+), 1 deletion(-)
9
10 diff --git a/xstream/src/java/com/thoughtworks/xstream/mapper/LambdaMapper.java b/xstream/src/java/com/thoughtworks/xstream/mapper/LambdaMapper.java
11 index 6416105..15c02bb 100644
312 --- a/xstream/src/java/com/thoughtworks/xstream/mapper/LambdaMapper.java
413 +++ b/xstream/src/java/com/thoughtworks/xstream/mapper/LambdaMapper.java
5 @@ -42,7 +42,7 @@
14 @@ -42,7 +42,7 @@ public class LambdaMapper extends MapperWrapper {
615 for (int i = 0; replacement == null && i < interfaces.length; i++) {
716 final Class<?> iface = interfaces[i];
817 for (final Method method : iface.getMethods()) {
1120 replacement = iface;
1221 break;
1322 }
14 @@ -57,4 +57,12 @@
23 @@ -57,4 +57,12 @@ public class LambdaMapper extends MapperWrapper {
1524 }
1625 return super.serializedClass(replacement == null ? type : replacement);
1726 }
0 Description: Removes the dependency on the com.bea.xml.stream package (not needed, allows us to drop the StAX dependency)
1 Author: Emmanuel Bourg <ebourg@apache.org>
0 From: Emmanuel Bourg <ebourg@apache.org>
1 Date: Fri, 27 Aug 2021 16:26:02 +0200
2 Subject: Removes the dependency on the com.bea.xml.stream package (not
3 needed, allows us to drop the StAX dependency)
4
25 Forwarded: not-needed
6 ---
7 .../com/thoughtworks/xstream/io/xml/BEAStaxDriver.java | 14 --------------
8 1 file changed, 14 deletions(-)
9
10 diff --git a/xstream/src/java/com/thoughtworks/xstream/io/xml/BEAStaxDriver.java b/xstream/src/java/com/thoughtworks/xstream/io/xml/BEAStaxDriver.java
11 index a4c30d1..9b2b17c 100644
312 --- a/xstream/src/java/com/thoughtworks/xstream/io/xml/BEAStaxDriver.java
413 +++ b/xstream/src/java/com/thoughtworks/xstream/io/xml/BEAStaxDriver.java
514 @@ -10,8 +10,6 @@
1120 import com.thoughtworks.xstream.io.naming.NameCoder;
1221
1322 import javax.xml.stream.XMLInputFactory;
14 @@ -71,16 +69,4 @@
23 @@ -71,16 +69,4 @@ public class BEAStaxDriver extends StaxDriver {
1524 super(nameCoder);
1625 }
1726
0 From: Markus Koschany <apo@debian.org>
1 Date: Fri, 27 Aug 2021 16:37:25 +0200
2 Subject: no mxparser
3
4 ---
5 .../benchmark/jmh/ConverterTypeBenchmark.java | 288 ---------------
6 .../xstream/benchmark/jmh/ParserBenchmark.java | 387 --------------------
7 .../benchmark/jmh/StringConverterBenchmark.java | 334 -----------------
8 .../xstream/io/xml/MXParserDomDriver.java | 53 ---
9 .../xstream/io/xml/MXParserDriver.java | 55 ---
10 .../acceptance/MultipleObjectsInOneStreamTest.java | 397 ---------------------
11 .../xstream/io/DriverEndToEndTestSuite.java | 187 ----------
12 .../xstream/io/binary/BinaryStreamTest.java | 92 -----
13 .../io/copy/HierarchicalStreamCopierTest.java | 74 ----
14 .../xstream/io/xml/MXParserReaderTest.java | 41 ---
15 10 files changed, 1908 deletions(-)
16 delete mode 100644 xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/ConverterTypeBenchmark.java
17 delete mode 100644 xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/ParserBenchmark.java
18 delete mode 100644 xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/StringConverterBenchmark.java
19 delete mode 100644 xstream/src/java/com/thoughtworks/xstream/io/xml/MXParserDomDriver.java
20 delete mode 100644 xstream/src/java/com/thoughtworks/xstream/io/xml/MXParserDriver.java
21 delete mode 100644 xstream/src/test/com/thoughtworks/acceptance/MultipleObjectsInOneStreamTest.java
22 delete mode 100644 xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java
23 delete mode 100644 xstream/src/test/com/thoughtworks/xstream/io/binary/BinaryStreamTest.java
24 delete mode 100644 xstream/src/test/com/thoughtworks/xstream/io/copy/HierarchicalStreamCopierTest.java
25 delete mode 100644 xstream/src/test/com/thoughtworks/xstream/io/xml/MXParserReaderTest.java
26
27 diff --git a/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/ConverterTypeBenchmark.java b/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/ConverterTypeBenchmark.java
28 deleted file mode 100644
29 index 8b01de1..0000000
30 --- a/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/ConverterTypeBenchmark.java
31 +++ /dev/null
32 @@ -1,288 +0,0 @@
33 -/*
34 - * Copyright (C) 2015, 2017, 2021 XStream Committers.
35 - * All rights reserved.
36 - *
37 - * The software in this package is published under the terms of the BSD
38 - * style license a copy of which has been included with this distribution in
39 - * the LICENSE.txt file.
40 - *
41 - * Created on 20 November 2015 by Joerg Schaible
42 - */
43 -package com.thoughtworks.xstream.benchmark.jmh;
44 -
45 -import java.math.BigInteger;
46 -import java.util.UUID;
47 -import java.util.concurrent.TimeUnit;
48 -
49 -import org.openjdk.jmh.annotations.Benchmark;
50 -import org.openjdk.jmh.annotations.BenchmarkMode;
51 -import org.openjdk.jmh.annotations.Fork;
52 -import org.openjdk.jmh.annotations.Level;
53 -import org.openjdk.jmh.annotations.Measurement;
54 -import org.openjdk.jmh.annotations.Mode;
55 -import org.openjdk.jmh.annotations.OutputTimeUnit;
56 -import org.openjdk.jmh.annotations.Scope;
57 -import org.openjdk.jmh.annotations.Setup;
58 -import org.openjdk.jmh.annotations.State;
59 -import org.openjdk.jmh.annotations.Threads;
60 -import org.openjdk.jmh.annotations.Warmup;
61 -import org.openjdk.jmh.infra.BenchmarkParams;
62 -
63 -import com.thoughtworks.xstream.XStream;
64 -import com.thoughtworks.xstream.converters.ConversionException;
65 -import com.thoughtworks.xstream.converters.Converter;
66 -import com.thoughtworks.xstream.converters.MarshallingContext;
67 -import com.thoughtworks.xstream.converters.UnmarshallingContext;
68 -import com.thoughtworks.xstream.converters.javabean.JavaBeanConverter;
69 -import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
70 -import com.thoughtworks.xstream.io.HierarchicalStreamReader;
71 -import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
72 -import com.thoughtworks.xstream.io.xml.MXParserDriver;
73 -import com.thoughtworks.xstream.security.ArrayTypePermission;
74 -import com.thoughtworks.xstream.security.NoTypePermission;
75 -import com.thoughtworks.xstream.security.PrimitiveTypePermission;
76 -
77 -
78 -/**
79 - * Benchmark for the different converter types.
80 - *
81 - * @author J&ouml;rg Schaible
82 - * @since 1.4.9
83 - */
84 -@BenchmarkMode(Mode.AverageTime)
85 -@Fork(value = 1)
86 -@Measurement(iterations = 16)
87 -@OutputTimeUnit(TimeUnit.NANOSECONDS)
88 -@State(Scope.Benchmark)
89 -@Threads(4)
90 -@Warmup(iterations = 5)
91 -public class ConverterTypeBenchmark {
92 -
93 - private XStream xstream;
94 - private Model array[];
95 - private String xml;
96 -
97 - @SuppressWarnings("javadoc")
98 - public static class Model {
99 - private char ch;
100 - private int i;
101 - private String s;
102 - private double d;
103 - private float f;
104 - private BigInteger bi;
105 - private UUID uuid;
106 -
107 - public Model() {
108 - ch = 0;
109 - i = 0;
110 - d = 0.0;
111 - f = 0.0f;
112 - }
113 -
114 - public Model(final int i) {
115 - ch = (char)(i % 256);
116 - this.i = i;
117 - s = Integer.toString(i, 2);
118 - d = Math.PI * i;
119 - f = (float)(Math.E * i);
120 - bi = new BigInteger(s, 2);
121 - uuid = UUID.randomUUID();
122 - }
123 -
124 - public char getCh() {
125 - return ch;
126 - }
127 -
128 - public void setCh(final char ch) {
129 - this.ch = ch;
130 - }
131 -
132 - public int getI() {
133 - return i;
134 - }
135 -
136 - public void setI(final int i) {
137 - this.i = i;
138 - }
139 -
140 - public String getS() {
141 - return s;
142 - }
143 -
144 - public void setS(final String s) {
145 - this.s = s;
146 - }
147 -
148 - public Double getD() {
149 - return d;
150 - }
151 -
152 - public void setD(final Double d) {
153 - this.d = d;
154 - }
155 -
156 - public Float getF() {
157 - return f;
158 - }
159 -
160 - public void setF(final Float f) {
161 - this.f = f;
162 - }
163 -
164 - public BigInteger getBi() {
165 - return bi;
166 - }
167 -
168 - public void setBi(final BigInteger bi) {
169 - this.bi = bi;
170 - }
171 -
172 - public UUID getUuid() {
173 - return uuid;
174 - }
175 -
176 - public void setUuid(final UUID uuid) {
177 - this.uuid = uuid;
178 - }
179 - }
180 -
181 - /**
182 - * Converter for a Model.
183 - *
184 - * @since 1.4.9
185 - */
186 - public static final class ModelConverter implements Converter {
187 -
188 - public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) {
189 - return type == Model.class;
190 - }
191 -
192 - public void marshal(final Object source, final HierarchicalStreamWriter writer,
193 - final MarshallingContext context) {
194 - final Model type = Model.class.cast(source);
195 - writeElement(writer, "ch", String.valueOf(type.getCh()));
196 - writeElement(writer, "i", String.valueOf(type.getI()));
197 - writeElement(writer, "s", type.getS());
198 - writeElement(writer, "d", String.valueOf(type.getD()));
199 - writeElement(writer, "f", String.valueOf(type.getF()));
200 - writeElement(writer, "bi", type.getBi().toString());
201 - writeElement(writer, "uuid", type.getUuid().toString());
202 - }
203 -
204 - private void writeElement(final HierarchicalStreamWriter writer, final String name, final String value) {
205 - writer.startNode(name);
206 - writer.setValue(value);
207 - writer.endNode();
208 - }
209 -
210 - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
211 - final Model type = new Model();
212 - while (reader.hasMoreChildren()) {
213 - reader.moveDown();
214 - final String value = reader.getValue();
215 - final String name = reader.getNodeName();
216 - if (name.equals("ch")) {
217 - if (value.length() != 1) {
218 - throw new ConversionException("Not a single character");
219 - }
220 - type.setCh(value.charAt(0));
221 - } else if (name.equals("i")) {
222 - type.setI(Integer.parseInt(value));
223 - } else if (name.equals("s")) {
224 - type.setS(value);
225 - } else if (name.equals("d")) {
226 - type.setD(Double.parseDouble(value));
227 - } else if (name.equals("f")) {
228 - type.setF(Float.parseFloat(value));
229 - } else if (name.equals("bi")) {
230 - type.setBi(new BigInteger(value));
231 - } else if (name.equals("uuid")) {
232 - type.setUuid(UUID.fromString(value));
233 - } else {
234 - throw new ConversionException("Unkown element");
235 - }
236 - reader.moveUp();
237 - }
238 -
239 - return type;
240 - }
241 -
242 - }
243 -
244 - /**
245 - * Initialize the XML string to deserialize.
246 - *
247 - * @since 1.4.9
248 - */
249 - @Setup
250 - public void init() {
251 - array = new Model[1000];
252 - for (int i = 0; i < array.length; ++i) {
253 - array[i] = new Model(i);
254 - }
255 - }
256 -
257 - /**
258 - * Setup the data to deserialize.
259 - *
260 - * @param params the parameters of the benchmark
261 - * @since 1.4.9
262 - */
263 - @Setup(Level.Trial)
264 - public void setUp(final BenchmarkParams params) {
265 - xstream = new XStream(new MXParserDriver());
266 - xstream.addPermission(NoTypePermission.NONE);
267 - xstream.addPermission(ArrayTypePermission.ARRAYS);
268 - xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
269 - xstream.allowTypes(new Class[]{Model.class, String.class, BigInteger.class, UUID.class});
270 - final String benchmark = params.getBenchmark();
271 - final String name = benchmark.substring(ConverterTypeBenchmark.class.getName().length() + 1);
272 - if (name.equals("reflection")) {
273 - xstream.registerConverter(new ReflectionConverter(xstream.getMapper(), xstream.getReflectionProvider(),
274 - Model.class));
275 - } else if (name.equals("javaBean")) {
276 - xstream.registerConverter(new JavaBeanConverter(xstream.getMapper(), Model.class));
277 - } else if (name.equals("custom")) {
278 - xstream.registerConverter(new ModelConverter());
279 - } else {
280 - throw new IllegalStateException("Unsupported benchmark type: " + benchmark);
281 - }
282 - xml = xstream.toXML(array);
283 - // System.out.println(xstream.toXML(array[0]));
284 - }
285 -
286 - /**
287 - * Use ReflectionConverter.
288 - *
289 - * @since 1.4.9
290 - */
291 - @Benchmark
292 - public void reflection() {
293 - run();
294 - }
295 -
296 - /**
297 - * Use JavaBeanConverter.
298 - *
299 - * @since 1.4.9
300 - */
301 - @Benchmark
302 - public void javaBean() {
303 - run();
304 - }
305 -
306 - /**
307 - * Use custom converter.
308 - *
309 - * @since 1.4.9
310 - */
311 - @Benchmark
312 - public void custom() {
313 - run();
314 - }
315 -
316 - private void run() {
317 - final Object o = xstream.fromXML(xml);
318 - assert xstream.toXML(o).equals(xml) : "XML differs";
319 - }
320 -}
321 diff --git a/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/ParserBenchmark.java b/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/ParserBenchmark.java
322 deleted file mode 100644
323 index b2f83bd..0000000
324 --- a/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/ParserBenchmark.java
325 +++ /dev/null
326 @@ -1,387 +0,0 @@
327 -/*
328 - * Copyright (C) 2015, 2017, 2021 XStream Committers.
329 - * All rights reserved.
330 - *
331 - * The software in this package is published under the terms of the BSD
332 - * style license a copy of which has been included with this distribution in
333 - * the LICENSE.txt file.
334 - *
335 - * Created on 25. October 2015 by Joerg Schaible
336 - */
337 -package com.thoughtworks.xstream.benchmark.jmh;
338 -
339 -import java.io.ByteArrayInputStream;
340 -import java.io.ByteArrayOutputStream;
341 -import java.io.Writer;
342 -import java.util.ArrayList;
343 -import java.util.Arrays;
344 -import java.util.List;
345 -import java.util.concurrent.TimeUnit;
346 -
347 -import org.openjdk.jmh.annotations.Benchmark;
348 -import org.openjdk.jmh.annotations.BenchmarkMode;
349 -import org.openjdk.jmh.annotations.Fork;
350 -import org.openjdk.jmh.annotations.Level;
351 -import org.openjdk.jmh.annotations.Measurement;
352 -import org.openjdk.jmh.annotations.Mode;
353 -import org.openjdk.jmh.annotations.OutputTimeUnit;
354 -import org.openjdk.jmh.annotations.Param;
355 -import org.openjdk.jmh.annotations.Scope;
356 -import org.openjdk.jmh.annotations.Setup;
357 -import org.openjdk.jmh.annotations.State;
358 -import org.openjdk.jmh.annotations.Threads;
359 -import org.openjdk.jmh.annotations.Warmup;
360 -import org.openjdk.jmh.infra.BenchmarkParams;
361 -
362 -import com.thoughtworks.xstream.XStream;
363 -import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
364 -import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
365 -import com.thoughtworks.xstream.io.binary.BinaryStreamDriver;
366 -import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
367 -import com.thoughtworks.xstream.io.xml.BEAStaxDriver;
368 -import com.thoughtworks.xstream.io.xml.Dom4JDriver;
369 -import com.thoughtworks.xstream.io.xml.DomDriver;
370 -import com.thoughtworks.xstream.io.xml.JDom2Driver;
371 -import com.thoughtworks.xstream.io.xml.JDomDriver;
372 -import com.thoughtworks.xstream.io.xml.KXml2Driver;
373 -import com.thoughtworks.xstream.io.xml.MXParserDriver;
374 -import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
375 -import com.thoughtworks.xstream.io.xml.StandardStaxDriver;
376 -import com.thoughtworks.xstream.io.xml.WstxDriver;
377 -import com.thoughtworks.xstream.io.xml.XomDriver;
378 -import com.thoughtworks.xstream.io.xml.Xpp3Driver;
379 -import com.thoughtworks.xstream.security.ArrayTypePermission;
380 -import com.thoughtworks.xstream.security.NoTypePermission;
381 -import com.thoughtworks.xstream.security.PrimitiveTypePermission;
382 -
383 -
384 -/**
385 - * Benchmark for the different {@link HierarchicalStreamDriver} implementations.
386 - *
387 - * @author J&ouml;rg Schaible
388 - * @since 1.4.9
389 - */
390 -@BenchmarkMode(Mode.AverageTime)
391 -@Fork(value = 1)
392 -@Measurement(iterations = 15)
393 -@OutputTimeUnit(TimeUnit.NANOSECONDS)
394 -@State(Scope.Benchmark)
395 -@Threads(1)
396 -@Warmup(iterations = 5)
397 -public class ParserBenchmark {
398 -
399 - /**
400 - * Driver factory. Enum values used as parameter for the parser benchmark methods.
401 - *
402 - * @author J&ouml;rg Schaible
403 - * @since 1.4.9
404 - */
405 - public enum DriverFactory {
406 - /**
407 - * Factory for the {@link MXParserDriver}.
408 - *
409 - * @since 1.4.16
410 - */
411 - MXParser(new MXParserDriver()), //
412 - /**
413 - * Factory for the {@link Xpp3Driver}.
414 - *
415 - * @since 1.4.9
416 - */
417 - Xpp3(new Xpp3Driver()), //
418 - /**
419 - * Factory for the {@link KXml2Driver}.
420 - *
421 - * @since 1.4.9
422 - */
423 - kXML2(new KXml2Driver()), //
424 - /**
425 - * Factory for the {@link StandardStaxDriver}.
426 - *
427 - * @since 1.4.9
428 - */
429 - JDKStax(new StandardStaxDriver()), //
430 - /**
431 - * Factory for the {@link WstxDriver}.
432 - *
433 - * @since 1.4.9
434 - */
435 - Woodstox(new WstxDriver()), //
436 - /**
437 - * Factory for the {@link BEAStaxDriver}.
438 - *
439 - * @since 1.4.9
440 - */
441 - BEAStax(new BEAStaxDriver()), //
442 - /**
443 - * Factory for the {@link DomDriver}.
444 - *
445 - * @since 1.4.9
446 - */
447 - DOM(new DomDriver()), //
448 - /**
449 - * Factory for the {@link Dom4JDriver}.
450 - *
451 - * @since 1.4.9
452 - */
453 - DOM4J(new Dom4JDriver() { // XML writer of DOM4J fails
454 - @Override
455 - public HierarchicalStreamWriter createWriter(final Writer out) {
456 - return new PrettyPrintWriter(out, getNameCoder());
457 - }
458 - }), //
459 - /**
460 - * Factory for the {@link JDomDriver}.
461 - *
462 - * @since 1.4.9
463 - */
464 - JDom(new JDomDriver()), //
465 - /**
466 - * Factory for the {@link JDom2Driver}.
467 - *
468 - * @since 1.4.9
469 - */
470 - JDom2(new JDom2Driver()), //
471 - /**
472 - * Factory for the {@link XomDriver}.
473 - *
474 - * @since 1.4.9
475 - */
476 - Xom(new XomDriver()), //
477 - /**
478 - * Factory for the {@link BinaryStreamDriver}.
479 - *
480 - * @since 1.4.9
481 - */
482 - Binary(new BinaryStreamDriver()), //
483 - /**
484 - * Factory for the {@link JettisonMappedXmlDriver}.
485 - *
486 - * @since 1.4.9
487 - */
488 - Jettison(new JettisonMappedXmlDriver());
489 -
490 - private final HierarchicalStreamDriver driver;
491 -
492 - private DriverFactory(final HierarchicalStreamDriver driver) {
493 - this.driver = driver;
494 - }
495 -
496 - /**
497 - * Request the driver of the instantiated factory.
498 - *
499 - * @return the driver
500 - * @since 1.4.9
501 - */
502 - public HierarchicalStreamDriver getDriver() {
503 - return driver;
504 - }
505 - }
506 -
507 - /**
508 - * Data factory. Enum values used as data generator and checker for the individual parser benchmark methods. Method
509 - * names define the data factory to use for the benchmark.
510 - *
511 - * @author J&ouml;rg Schaible
512 - * @since 1.4.9
513 - */
514 - public enum DataFactory {
515 - /**
516 - * A single element with a text of 100.000 characters.
517 - *
518 - * @author J&ouml;rg Schaible
519 - * @since 1.4.9
520 - */
521 - BigText {
522 - private int length;
523 - private String start;
524 - private String end;
525 -
526 - @Override
527 - public void writeData(final HierarchicalStreamWriter writer) {
528 - int length = 100000;
529 - final StringBuilder builder = new StringBuilder(length);
530 - int i = 0;
531 - while (length > 0) {
532 - final int codePoint = i % Character.MAX_CODE_POINT;
533 - if (Character.isLetterOrDigit(codePoint)) {
534 - builder.appendCodePoint(codePoint);
535 - --length;
536 - }
537 - ++i;
538 - }
539 - final String s = builder.toString();
540 - this.length = s.length();
541 - start = s.substring(0, 100);
542 - end = s.substring(this.length - 100);
543 -
544 - writer.startNode("string");
545 - writer.setValue(s);
546 - writer.endNode();
547 - }
548 -
549 - @Override
550 - public void checkData(final Object o) {
551 - final String s = String.class.cast(o);
552 - assert length == s.length() : BigText + " fails length";
553 - assert start.equals(s.substring(0, 100)) : BigText + " fails start";
554 - assert end.equals(s.substring(length - 100)) : BigText + " fails end";
555 - }
556 - },
557 - /**
558 - * Nested list in list structure, 500 elements deep.
559 - *
560 - * @author J&ouml;rg Schaible
561 - * @since 1.4.9
562 - */
563 - NestedElements {
564 - private static final int DEPTH = 1000;
565 - private List<Integer> list;
566 -
567 - @Override
568 - public void writeData(final HierarchicalStreamWriter writer) {
569 - for (int i = 0; i < DEPTH; ++i) {
570 - writer.startNode("list");
571 - }
572 - list = new ArrayList<Integer>(Arrays.asList(42, 7, 3, -17));
573 - for (final Integer i : list) {
574 - writer.startNode("int");
575 - writer.setValue(i.toString());
576 - writer.endNode();
577 - }
578 - for (int i = 0; i < DEPTH; ++i) {
579 - writer.endNode();
580 - }
581 - }
582 -
583 - @Override
584 - public void checkData(final Object o) {
585 - List<?> list = List.class.cast(o);
586 - int depth = DEPTH;
587 - while (depth-- > 1) {
588 - assert list.size() == 1 : NestedElements + " fails list size";
589 - list = List.class.cast(list.get(0));
590 - }
591 - assert this.list.equals(list) : NestedElements + " fails inner list";
592 - }
593 - },
594 - /**
595 - * An array with 1.000 elements.
596 - *
597 - * @author J&ouml;rg Schaible
598 - * @since 1.4.9
599 - */
600 - ManyChildren {
601 - private static final int LENGTH = 1000;
602 -
603 - @Override
604 - public void writeData(final HierarchicalStreamWriter writer) {
605 - int length = LENGTH;
606 - writer.startNode("int-array");
607 - while (length-- > 0) {
608 - writer.startNode("int");
609 - writer.setValue(String.valueOf(length));
610 - writer.endNode();
611 - }
612 - writer.endNode();
613 - }
614 -
615 - @Override
616 - public void checkData(final Object o) {
617 - final int[] array = int[].class.cast(o);
618 - assert LENGTH == array.length : ManyChildren + " fails length";
619 - assert LENGTH - 1 == array[0] : ManyChildren + " fails start";
620 - assert 0 == array[LENGTH - 1] : ManyChildren + " fails end";
621 - }
622 - };
623 - /**
624 - * Write the data of the factory into the writer of the hierarchical stream.
625 - *
626 - * @param writer the writer of the data
627 - * @since 1.4.9
628 - */
629 - public abstract void writeData(HierarchicalStreamWriter writer);
630 -
631 - /**
632 - * Check the deserialized object.
633 - *
634 - * @param o the object to check
635 - * @since 1.4.9
636 - */
637 - public abstract void checkData(Object o);
638 - }
639 -
640 - @Param
641 - private DriverFactory driverFactory;
642 - private DataFactory dataFactory;
643 - private byte[] data;
644 - private XStream xstream;
645 - private HierarchicalStreamDriver driver;
646 -
647 - /**
648 - * Initialize the XStream instance and instantiate the driver for the benchmark.
649 - *
650 - * @since 1.4.9
651 - */
652 - @Setup
653 - public void init() {
654 - xstream = new XStream();
655 - xstream.addPermission(NoTypePermission.NONE);
656 - xstream.addPermission(ArrayTypePermission.ARRAYS);
657 - xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
658 - xstream.allowTypes(new Class[]{List.class, String.class});
659 - xstream.setMode(XStream.NO_REFERENCES);
660 - driver = driverFactory.getDriver();
661 - }
662 -
663 - /**
664 - * Setup the data to deserialize.
665 - *
666 - * @param params the parameters of the benchmark
667 - * @since 1.4.9
668 - */
669 - @Setup(Level.Trial)
670 - public void setUp(final BenchmarkParams params) {
671 - final String benchmark = params.getBenchmark();
672 - dataFactory = DataFactory.valueOf(benchmark.substring(benchmark.lastIndexOf('.') + 6));
673 -
674 - final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024 * 1024);
675 - final HierarchicalStreamWriter writer = driver.createWriter(baos);
676 - dataFactory.writeData(writer);
677 - writer.close();
678 - data = baos.toByteArray();
679 - }
680 -
681 - /**
682 - * Parse an element with a big text as value.
683 - *
684 - * @since 1.4.9
685 - */
686 - @Benchmark
687 - public void parseBigText() {
688 - final Object o = xstream.unmarshal(driver.createReader(new ByteArrayInputStream(data)));
689 - dataFactory.checkData(o);
690 - }
691 -
692 - /**
693 - * Parse a deeply nested structure.
694 - *
695 - * @since 1.4.9
696 - */
697 - @Benchmark
698 - public void parseNestedElements() {
699 - final Object o = xstream.unmarshal(driver.createReader(new ByteArrayInputStream(data)));
700 - dataFactory.checkData(o);
701 - }
702 -
703 - /**
704 - * Parse an element with a lot of simple children.
705 - *
706 - * @since 1.4.9
707 - */
708 - @Benchmark
709 - public void parseManyChildren() {
710 - final Object o = xstream.unmarshal(driver.createReader(new ByteArrayInputStream(data)));
711 - dataFactory.checkData(o);
712 - }
713 -}
714 diff --git a/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/StringConverterBenchmark.java b/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/StringConverterBenchmark.java
715 deleted file mode 100644
716 index 5a74fdb..0000000
717 --- a/xstream-jmh/src/java/com/thoughtworks/xstream/benchmark/jmh/StringConverterBenchmark.java
718 +++ /dev/null
719 @@ -1,334 +0,0 @@
720 -/*
721 - * Copyright (C) 2015, 2017, 2021 XStream Committers.
722 - * All rights reserved.
723 - *
724 - * The software in this package is published under the terms of the BSD
725 - * style license a copy of which has been included with this distribution in
726 - * the LICENSE.txt file.
727 - *
728 - * Created on 8. November 2015 by Joerg Schaible
729 - */
730 -package com.thoughtworks.xstream.benchmark.jmh;
731 -
732 -import java.io.StringWriter;
733 -import java.util.Collections;
734 -import java.util.Map;
735 -import java.util.UUID;
736 -import java.util.concurrent.ConcurrentHashMap;
737 -import java.util.concurrent.ConcurrentMap;
738 -import java.util.concurrent.TimeUnit;
739 -
740 -import org.openjdk.jmh.annotations.Benchmark;
741 -import org.openjdk.jmh.annotations.BenchmarkMode;
742 -import org.openjdk.jmh.annotations.Fork;
743 -import org.openjdk.jmh.annotations.Level;
744 -import org.openjdk.jmh.annotations.Measurement;
745 -import org.openjdk.jmh.annotations.Mode;
746 -import org.openjdk.jmh.annotations.OutputTimeUnit;
747 -import org.openjdk.jmh.annotations.Scope;
748 -import org.openjdk.jmh.annotations.Setup;
749 -import org.openjdk.jmh.annotations.State;
750 -import org.openjdk.jmh.annotations.Threads;
751 -import org.openjdk.jmh.annotations.Warmup;
752 -import org.openjdk.jmh.infra.BenchmarkParams;
753 -
754 -import com.thoughtworks.xstream.XStream;
755 -import com.thoughtworks.xstream.converters.SingleValueConverter;
756 -import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
757 -import com.thoughtworks.xstream.core.util.WeakCache;
758 -import com.thoughtworks.xstream.io.xml.CompactWriter;
759 -import com.thoughtworks.xstream.io.xml.MXParserDriver;
760 -import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
761 -import com.thoughtworks.xstream.io.xml.Xpp3Driver;
762 -import com.thoughtworks.xstream.security.ArrayTypePermission;
763 -import com.thoughtworks.xstream.security.NoTypePermission;
764 -
765 -
766 -/**
767 - * Benchmark for different StringConverter implementations.
768 - *
769 - * @author J&ouml;rg Schaible
770 - * @since 1.4.9
771 - */
772 -@BenchmarkMode(Mode.AverageTime)
773 -@Fork(value = 1)
774 -@Measurement(iterations = 16)
775 -@OutputTimeUnit(TimeUnit.NANOSECONDS)
776 -@State(Scope.Benchmark)
777 -@Threads(4)
778 -@Warmup(iterations = 5)
779 -public class StringConverterBenchmark {
780 -
781 - private XStream xstream;
782 - private String xml;
783 -
784 - /**
785 - * No memory usage for cache, but any string is a separate instance after deserialization. Memory consumption of the
786 - * deserialized array is nearly 3 times compared to a converter that caches and reuses the strings.
787 - *
788 - * @since 1.4.9
789 - */
790 - public static final class NonCachingStringConverter extends AbstractSingleValueConverter {
791 -
792 - @Override
793 - public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) {
794 - return type == String.class;
795 - }
796 -
797 - @Override
798 - public Object fromString(final String str) {
799 - return str;
800 - }
801 - }
802 -
803 - /**
804 - * Cache based on String.intern(). Uses PermGenSpace for Java 7 and below.
805 - *
806 - * @since 1.4.9
807 - */
808 - public static final class InternStringConverter extends AbstractSingleValueConverter {
809 -
810 - @Override
811 - public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) {
812 - return type == String.class;
813 - }
814 -
815 - @Override
816 - public Object fromString(final String str) {
817 - return str.intern();
818 - }
819 - }
820 -
821 - /**
822 - * Cache based on a synchronized WeakHashMap with weak keys. Ensures that the deserialized strings vanish when the
823 - * deserialized object is GC'ed.
824 - *
825 - * @since 1.4.9
826 - */
827 - public class SynchronizedWeakCacheStringConverter extends AbstractSingleValueConverter {
828 -
829 - private final Map<String, String> cache;
830 - private final int lengthLimit;
831 -
832 - private SynchronizedWeakCacheStringConverter(final Map<String, String> map, final int lengthLimit) {
833 - cache = map;
834 - this.lengthLimit = lengthLimit;
835 - }
836 -
837 - /**
838 - * Constructs a SynchronizedWeakCacheStringConverter.
839 - *
840 - * @param lengthLimit length limit for cached strings
841 - * @since 1.4.9
842 - */
843 - @SuppressWarnings("unchecked")
844 - public SynchronizedWeakCacheStringConverter(final int lengthLimit) {
845 - this(Collections.synchronizedMap(new WeakCache()), lengthLimit);
846 - }
847 -
848 - @Override
849 - public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) {
850 - return type.equals(String.class);
851 - }
852 -
853 - @Override
854 - public Object fromString(final String str) {
855 - if (cache != null && str != null && (lengthLimit < 0 || str.length() <= lengthLimit)) {
856 - String s = cache.get(str);
857 -
858 - if (s == null) {
859 - // fill cache
860 - cache.put(str, str);
861 -
862 - s = str;
863 - }
864 -
865 - return s;
866 - } else {
867 - return str;
868 - }
869 - }
870 - }
871 -
872 - /**
873 - * Cache based on a ConcurrentMap. Cache is never flushed.
874 - *
875 - * @since 1.4.9
876 - */
877 - public class ConcurrentHashMapStringConverter extends AbstractSingleValueConverter {
878 -
879 - private final ConcurrentMap<String, String> cache;
880 - private final int lengthLimit;
881 -
882 - private ConcurrentHashMapStringConverter(final ConcurrentMap<String, String> map, final int lengthLimit) {
883 - cache = map;
884 - this.lengthLimit = lengthLimit;
885 - }
886 -
887 - /**
888 - * Constructs a ConcurrentHashMapStringConverter.
889 - *
890 - * @param lengthLimit length limit for cached strings
891 - * @since 1.4.9
892 - */
893 - public ConcurrentHashMapStringConverter(final int lengthLimit) {
894 - this(new ConcurrentHashMap<String, String>(), lengthLimit);
895 - }
896 -
897 - @Override
898 - public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) {
899 - return type.equals(String.class);
900 - }
901 -
902 - @Override
903 - public Object fromString(final String str) {
904 - if (cache != null && str != null && (lengthLimit < 0 || str.length() <= lengthLimit)) {
905 - final String s = cache.putIfAbsent(str, str);
906 - return s == null ? str : s;
907 - } else {
908 - return str;
909 - }
910 - }
911 - }
912 -
913 - /**
914 - * Initialize the XML string to deserialize.
915 - *
916 - * @since 1.4.9
917 - */
918 - @Setup
919 - public void init() {
920 - final String array[] = new String[300];
921 - for (int i = 0; i < 100;) {
922 - array[i] = String.valueOf(++i);
923 - }
924 - for (int i = 100; i < 200;) {
925 - array[i] = "Binary value " + i + ": " + Integer.toString(++i, 2);
926 - }
927 - for (int i = 200; i < 300;) {
928 - array[i++] = UUID.randomUUID().toString().replace('-', ':');
929 - }
930 -
931 - final StringWriter stringWriter = new StringWriter();
932 - final PrettyPrintWriter writer = new CompactWriter(stringWriter);
933 - writer.startNode("string-array");
934 - for (int i = 0; i < 10000; ++i) {
935 - writer.startNode("string");
936 - final String s;
937 - if ((i & 1) == 1) {
938 - s = array[(i >> 1) % 100];
939 - } else if ((i & 2) == 2) {
940 - s = array[100 + (i >> 2) % 100];
941 - } else if ((i & 4) == 4) {
942 - s = array[200 + (i >> 3) % 100];
943 - } else {
944 - s = "Random UUID: " + UUID.randomUUID().toString();
945 - }
946 - writer.setValue(s);
947 - writer.endNode();
948 - }
949 - writer.endNode();
950 - writer.close();
951 - xml = stringWriter.toString();
952 - }
953 -
954 - /**
955 - * Setup the data to deserialize.
956 - *
957 - * @param params the parameters of the benchmark
958 - * @since 1.4.9
959 - */
960 - @Setup(Level.Trial)
961 - public void setUp(final BenchmarkParams params) {
962 - final String benchmark = params.getBenchmark();
963 - final SingleValueConverter converter;
964 - final String name = benchmark.substring(StringConverterBenchmark.class.getName().length() + 1);
965 - if ("nonCaching".equals(name)) {
966 - converter = new NonCachingStringConverter();
967 - } else if ("intern".equals(name)) {
968 - converter = new InternStringConverter();
969 - } else if ("unlimitedSynchronizedWeakCache".equals(name)) {
970 - converter = new SynchronizedWeakCacheStringConverter(Integer.MAX_VALUE);
971 - } else if ("limitedSynchronizedWeakCache".equals(name)) {
972 - converter = new SynchronizedWeakCacheStringConverter(UUID.randomUUID().toString().length() + 2);
973 - } else if ("unlimitedConcurrentMap".equals(name)) {
974 - converter = new SynchronizedWeakCacheStringConverter(Integer.MAX_VALUE);
975 - } else if ("limitedConcurrentMap".equals(name)) {
976 - converter = new SynchronizedWeakCacheStringConverter(UUID.randomUUID().toString().length() + 2);
977 - } else {
978 - throw new IllegalStateException("Unsupported benchmark type: " + benchmark);
979 - }
980 - xstream = new XStream(new MXParserDriver());
981 - xstream.addPermission(NoTypePermission.NONE);
982 - xstream.addPermission(ArrayTypePermission.ARRAYS);
983 - xstream.allowTypes(new Class[] {String.class});
984 - xstream.registerConverter(converter);
985 - }
986 -
987 - /**
988 - * No cache for deserialized strings, each string is an own instance.
989 - *
990 - * @since 1.4.9
991 - */
992 - @Benchmark
993 - public void nonCaching() {
994 - run();
995 - }
996 -
997 - /**
998 - * Any string is stored also in the String's internal memory space.
999 - *
1000 - * @since 1.4.9
1001 - */
1002 - @Benchmark
1003 - public void intern() {
1004 - run();
1005 - }
1006 -
1007 - /**
1008 - * Any string is cached in a weak entry.
1009 - *
1010 - * @since 1.4.9
1011 - */
1012 - @Benchmark
1013 - public void unlimitedSynchronizedWeakCache() {
1014 - run();
1015 - }
1016 -
1017 - /**
1018 - * Strings of 38 characters or less are cached in a weak entry.
1019 - *
1020 - * @since 1.4.9
1021 - */
1022 - @Benchmark
1023 - public void limitedSynchronizedWeakCache() {
1024 - run();
1025 - }
1026 -
1027 - /**
1028 - * Any string is cached in a concurrent map.
1029 - *
1030 - * @since 1.4.9
1031 - */
1032 - @Benchmark
1033 - public void unlimitedConcurrentMap() {
1034 - run();
1035 - }
1036 -
1037 - /**
1038 - * Strings of 38 characters or less are cached in a concurrent map.
1039 - *
1040 - * @since 1.4.9
1041 - */
1042 - @Benchmark
1043 - public void limitedConcurrentMap() {
1044 - run();
1045 - }
1046 -
1047 - private void run() {
1048 - final String[] array = (String[])xstream.fromXML(xml);
1049 - assert array.length == 10000 : "array length is " + array.length;
1050 - assert array[1].equals("1") : "2nd element was: " + array[1];
1051 - assert array[9999].equals("100") : "last element was: " + array[9999];
1052 - }
1053 -}
1054 diff --git a/xstream/src/java/com/thoughtworks/xstream/io/xml/MXParserDomDriver.java b/xstream/src/java/com/thoughtworks/xstream/io/xml/MXParserDomDriver.java
1055 deleted file mode 100644
1056 index da75574..0000000
1057 --- a/xstream/src/java/com/thoughtworks/xstream/io/xml/MXParserDomDriver.java
1058 +++ /dev/null
1059 @@ -1,53 +0,0 @@
1060 -/*
1061 - * Copyright (C) 2021 XStream Committers.
1062 - * All rights reserved.
1063 - *
1064 - * The software in this package is published under the terms of the BSD
1065 - * style license a copy of which has been included with this distribution in
1066 - * the LICENSE.txt file.
1067 - *
1068 - * Created on 02. January 2021 by Joerg Schaible
1069 - */
1070 -package com.thoughtworks.xstream.io.xml;
1071 -
1072 -import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
1073 -import com.thoughtworks.xstream.io.naming.NameCoder;
1074 -
1075 -import io.github.xstream.mxparser.MXParser;
1076 -
1077 -import org.xmlpull.v1.XmlPullParser;
1078 -
1079 -/**
1080 - * A {@link HierarchicalStreamDriver} for XPP DOM using the MXParser fork.
1081 - *
1082 - * @author J&ouml;rg Schaible
1083 - * @since 1.4.16
1084 - */
1085 -public class MXParserDomDriver extends AbstractXppDomDriver {
1086 -
1087 - /**
1088 - * Construct an MXParserDomDriver.
1089 - *
1090 - * @since 1.4.16
1091 - */
1092 - public MXParserDomDriver() {
1093 - super(new XmlFriendlyNameCoder());
1094 - }
1095 -
1096 - /**
1097 - * Construct an Xpp3DomDriver.
1098 - *
1099 - * @param nameCoder the replacer for XML friendly names
1100 - * @since 1.4
1101 - */
1102 - public MXParserDomDriver(NameCoder nameCoder) {
1103 - super(nameCoder);
1104 - }
1105 -
1106 - /**
1107 - * {@inheritDoc}
1108 - */
1109 - protected XmlPullParser createParser() {
1110 - return new MXParser();
1111 - }
1112 -}
1113 diff --git a/xstream/src/java/com/thoughtworks/xstream/io/xml/MXParserDriver.java b/xstream/src/java/com/thoughtworks/xstream/io/xml/MXParserDriver.java
1114 deleted file mode 100644
1115 index 3ecf312..0000000
1116 --- a/xstream/src/java/com/thoughtworks/xstream/io/xml/MXParserDriver.java
1117 +++ /dev/null
1118 @@ -1,55 +0,0 @@
1119 -/*
1120 - * Copyright (C) 2021 XStream Committers.
1121 - * All rights reserved.
1122 - *
1123 - * The software in this package is published under the terms of the BSD
1124 - * style license a copy of which has been included with this distribution in
1125 - * the LICENSE.txt file.
1126 - *
1127 - * Created on 2. January 2021 by Joerg Schaible
1128 - */
1129 -package com.thoughtworks.xstream.io.xml;
1130 -
1131 -
1132 -import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
1133 -import com.thoughtworks.xstream.io.naming.NameCoder;
1134 -
1135 -import io.github.xstream.mxparser.MXParser;
1136 -
1137 -import org.xmlpull.v1.XmlPullParser;
1138 -
1139 -
1140 -/**
1141 - * A {@link HierarchicalStreamDriver} using the MXParser fork.
1142 - *
1143 - * @author J&ouml;rg Schaible
1144 - * @since 1.4.16
1145 - */
1146 -public class MXParserDriver extends AbstractXppDriver {
1147 -
1148 - /**
1149 - * Construct an MXParserDriver.
1150 - *
1151 - * @since 1.4.16
1152 - */
1153 - public MXParserDriver() {
1154 - super(new XmlFriendlyNameCoder());
1155 - }
1156 -
1157 - /**
1158 - * Construct an Xpp3Driver.
1159 - *
1160 - * @param nameCoder the replacer for XML friendly names
1161 - * @since 1.4.16
1162 - */
1163 - public MXParserDriver(NameCoder nameCoder) {
1164 - super(nameCoder);
1165 - }
1166 -
1167 - /**
1168 - * {@inheritDoc}
1169 - */
1170 - protected XmlPullParser createParser() {
1171 - return new MXParser();
1172 - }
1173 -}
1174 diff --git a/xstream/src/test/com/thoughtworks/acceptance/MultipleObjectsInOneStreamTest.java b/xstream/src/test/com/thoughtworks/acceptance/MultipleObjectsInOneStreamTest.java
1175 deleted file mode 100644
1176 index 557e792..0000000
1177 --- a/xstream/src/test/com/thoughtworks/acceptance/MultipleObjectsInOneStreamTest.java
1178 +++ /dev/null
1179 @@ -1,397 +0,0 @@
1180 -/*
1181 - * Copyright (C) 2005, 2006 Joe Walnes.
1182 - * Copyright (C) 2006, 2007, 2008, 2009, 2018, 2021 XStream Committers.
1183 - * All rights reserved.
1184 - *
1185 - * The software in this package is published under the terms of the BSD
1186 - * style license a copy of which has been included with this distribution in
1187 - * the LICENSE.txt file.
1188 - *
1189 - * Created on 09. December 2005 by Joe Walnes
1190 - */
1191 -package com.thoughtworks.acceptance;
1192 -
1193 -import com.thoughtworks.acceptance.objects.Software;
1194 -import com.thoughtworks.acceptance.objects.StandardObject;
1195 -import com.thoughtworks.xstream.MarshallingStrategy;
1196 -import com.thoughtworks.xstream.converters.ConversionException;
1197 -import com.thoughtworks.xstream.converters.ConverterLookup;
1198 -import com.thoughtworks.xstream.converters.DataHolder;
1199 -import com.thoughtworks.xstream.core.ReferenceByIdMarshaller;
1200 -import com.thoughtworks.xstream.core.ReferenceByIdUnmarshaller;
1201 -import com.thoughtworks.xstream.io.HierarchicalStreamReader;
1202 -import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
1203 -import com.thoughtworks.xstream.io.ReaderWrapper;
1204 -import com.thoughtworks.xstream.io.xml.MXParserDriver;
1205 -import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
1206 -import com.thoughtworks.xstream.io.xml.XppReader;
1207 -import com.thoughtworks.xstream.mapper.Mapper;
1208 -import com.thoughtworks.xstream.testutil.CallLog;
1209 -
1210 -import java.io.ByteArrayInputStream;
1211 -import java.io.ByteArrayOutputStream;
1212 -import java.io.EOFException;
1213 -import java.io.IOException;
1214 -import java.io.InputStreamReader;
1215 -import java.io.ObjectInputStream;
1216 -import java.io.ObjectOutputStream;
1217 -import java.io.OutputStreamWriter;
1218 -import java.io.Reader;
1219 -import java.io.StringReader;
1220 -import java.io.StringWriter;
1221 -import java.io.Writer;
1222 -import java.util.zip.Deflater;
1223 -import java.util.zip.DeflaterOutputStream;
1224 -import java.util.zip.Inflater;
1225 -import java.util.zip.InflaterInputStream;
1226 -
1227 -
1228 -public class MultipleObjectsInOneStreamTest extends AbstractAcceptanceTest {
1229 -
1230 - public static class Person extends StandardObject {
1231 -
1232 - private String firstName;
1233 - private String lastName;
1234 - private Person secretary;
1235 -
1236 - public Person(String firstName, String lastName) {
1237 - this.firstName = firstName;
1238 - this.lastName = lastName;
1239 - }
1240 -
1241 - }
1242 -
1243 - public void testReadAndWriteMultipleObjectsInOneStream() {
1244 - xstream.alias("person", Person.class);
1245 - StringWriter buffer = new StringWriter();
1246 -
1247 - // serialize
1248 - HierarchicalStreamWriter writer = new PrettyPrintWriter(buffer);
1249 - writer.startNode("people");
1250 - xstream.marshal(new Person("Postman", "Pat"), writer);
1251 - xstream.marshal(new Person("Bob", "Builder"), writer);
1252 - xstream.marshal(new Person("Tinky", "Winky"), writer);
1253 - writer.endNode();
1254 -
1255 - assertEquals(""
1256 - + "<people>\n"
1257 - + " <person>\n"
1258 - + " <firstName>Postman</firstName>\n"
1259 - + " <lastName>Pat</lastName>\n"
1260 - + " </person>\n"
1261 - + " <person>\n"
1262 - + " <firstName>Bob</firstName>\n"
1263 - + " <lastName>Builder</lastName>\n"
1264 - + " </person>\n"
1265 - + " <person>\n"
1266 - + " <firstName>Tinky</firstName>\n"
1267 - + " <lastName>Winky</lastName>\n"
1268 - + " </person>\n"
1269 - + "</people>", buffer.toString());
1270 -
1271 - // deserialize
1272 - HierarchicalStreamReader reader = new XppReader(new StringReader(buffer.toString()));
1273 -
1274 - assertTrue("should be another object to read (1)", reader.hasMoreChildren());
1275 - reader.moveDown();
1276 - assertEquals(new Person("Postman", "Pat"), xstream.unmarshal(reader));
1277 - reader.moveUp();
1278 -
1279 - assertTrue("should be another object to read (2)", reader.hasMoreChildren());
1280 - reader.moveDown();
1281 - assertEquals(new Person("Bob", "Builder"), xstream.unmarshal(reader));
1282 - reader.moveUp();
1283 -
1284 - assertTrue("should be another object to read (3)", reader.hasMoreChildren());
1285 - reader.moveDown();
1286 - assertEquals(new Person("Tinky", "Winky"), xstream.unmarshal(reader));
1287 - reader.moveUp();
1288 -
1289 - assertFalse("should be no more objects", reader.hasMoreChildren());
1290 - }
1291 -
1292 - public void testDrivenThroughObjectStream() throws IOException, ClassNotFoundException {
1293 - Writer writer = new StringWriter();
1294 - xstream.alias("software", Software.class);
1295 -
1296 - ObjectOutputStream oos = xstream.createObjectOutputStream(writer);
1297 - oos.writeInt(123);
1298 - oos.writeObject("hello");
1299 - oos.writeObject(new Software("tw", "xs"));
1300 - oos.close();
1301 -
1302 - String expectedXml = ""
1303 - + "<object-stream>\n"
1304 - + " <int>123</int>\n"
1305 - + " <string>hello</string>\n"
1306 - + " <software>\n"
1307 - + " <vendor>tw</vendor>\n"
1308 - + " <name>xs</name>\n"
1309 - + " </software>\n"
1310 - + "</object-stream>";
1311 -
1312 - assertEquals(expectedXml, writer.toString());
1313 -
1314 - ObjectInputStream ois = xstream.createObjectInputStream(new StringReader(writer
1315 - .toString()));
1316 - assertEquals(123, ois.readInt());
1317 - assertEquals("hello", ois.readObject());
1318 - assertEquals(new Software("tw", "xs"), ois.readObject());
1319 -
1320 - try {
1321 - ois.readObject(); // As far as I can see this is the only clue the
1322 - // ObjectInputStream gives that it's done.
1323 - fail("Expected EOFException");
1324 - } catch (EOFException expectedException) {
1325 - // good
1326 - }
1327 - }
1328 -
1329 - public void testDrivenThroughCompressedObjectStream()
1330 - throws IOException, ClassNotFoundException {
1331 - ByteArrayOutputStream baos = new ByteArrayOutputStream();
1332 - Writer writer = new OutputStreamWriter(new DeflaterOutputStream(baos, new Deflater(
1333 - Deflater.BEST_COMPRESSION)), "UTF-8");
1334 - xstream.alias("software", Software.class);
1335 -
1336 - ObjectOutputStream oos = xstream.createObjectOutputStream(writer);
1337 - oos.writeInt(123);
1338 - oos.writeObject("hello");
1339 - oos.writeObject(new Software("tw", "xs"));
1340 - oos.flush();
1341 - oos.close();
1342 -
1343 - byte[] data = baos.toByteArray();
1344 - assertTrue("Too less data: " + data.length, data.length > 2);
1345 -
1346 - ObjectInputStream ois = xstream.createObjectInputStream(new InputStreamReader(
1347 - new InflaterInputStream(new ByteArrayInputStream(data), new Inflater()), "UTF-8"));
1348 - assertEquals(123, ois.readInt());
1349 - assertEquals("hello", ois.readObject());
1350 - assertEquals(new Software("tw", "xs"), ois.readObject());
1351 -
1352 - try {
1353 - ois.readObject(); // As far as I can see this is the only clue the
1354 - // ObjectInputStream gives that it's done.
1355 - fail("Expected EOFException");
1356 - } catch (EOFException expectedException) {
1357 - // good
1358 - }
1359 - }
1360 -
1361 - private static class LevelTrackingReader extends ReaderWrapper {
1362 - private int level;
1363 - protected LevelTrackingReader(HierarchicalStreamReader reader) {
1364 - super(reader);
1365 - }
1366 -
1367 - public void moveDown() {
1368 - ++level;
1369 - super.moveDown();
1370 - }
1371 -
1372 - public void moveUp() {
1373 - super.moveUp();
1374 - --level;
1375 - }
1376 -
1377 - public int getLevel() {
1378 - return level;
1379 - }
1380 - }
1381 -
1382 - public void testFailSafeDeserialization() throws IOException, ClassNotFoundException {
1383 - final String xml = ""
1384 - + "<object-stream>\n"
1385 - + " <string>top</string>\n"
1386 - + " <list>\n"
1387 - + " <string>first</string>\n"
1388 - + " <int-array>\n"
1389 - + " <int>1</int>\n"
1390 - + " <int>invalid</int>\n" // deserialization will fail here
1391 - + " <int>3</int>\n"
1392 - + " </int-array>\n"
1393 - + " <string>last</string>\n"
1394 - + " </list>\n"
1395 - + " <string>bottom</string>\n"
1396 - + "</object-stream>";
1397 -
1398 - final LevelTrackingReader reader = new LevelTrackingReader(new MXParserDriver().createReader(new StringReader(xml)));
1399 - final ObjectInputStream ois = xstream.createObjectInputStream(reader);
1400 - final int level = reader.getLevel();
1401 - assertEquals("top", ois.readObject());
1402 - try {
1403 - ois.readObject();
1404 - fail("Thrown " + ConversionException.class.getName() + " expected");
1405 - } catch (final ConversionException e) {
1406 - assertEquals(3, reader.getLevel() - level);
1407 - do {
1408 - reader.moveUp();
1409 - } while (level != reader.getLevel());
1410 - }
1411 - assertEquals("bottom", ois.readObject());
1412 - ois.close();
1413 - }
1414 -
1415 - public void testObjectOutputStreamPropagatesCloseAndFlushEvents() throws IOException {
1416 - // setup
1417 - final CallLog log = new CallLog();
1418 - Writer loggingWriter = new Writer() {
1419 - public void close() {
1420 - log.actual("close");
1421 - }
1422 -
1423 - public void flush() {
1424 - log.actual("flush");
1425 - }
1426 -
1427 - public void write(char cbuf[], int off, int len) {
1428 - // don't care about this
1429 - }
1430 - };
1431 -
1432 - // expectations
1433 - log.expect("flush"); // TWO flushes are currently caused. Only one is needed, but
1434 - // this is no big deal.
1435 - log.expect("flush");
1436 - log.expect("close");
1437 -
1438 - // execute
1439 - ObjectOutputStream objectOutputStream = xstream.createObjectOutputStream(loggingWriter);
1440 - objectOutputStream.flush();
1441 - objectOutputStream.close();
1442 -
1443 - // verify
1444 - log.verify();
1445 - }
1446 -
1447 - public void testObjectInputStreamPropegatesCloseEvent() throws IOException {
1448 - // setup
1449 - final CallLog log = new CallLog();
1450 - Reader loggingReader = new StringReader("<int>1</int>") {
1451 - public void close() {
1452 - log.actual("close");
1453 - }
1454 - };
1455 -
1456 - // expectations
1457 - log.expect("close");
1458 -
1459 - // execute
1460 - ObjectInputStream objectInputStream = xstream.createObjectInputStream(loggingReader);
1461 - objectInputStream.close();
1462 -
1463 - // verify
1464 - log.verify();
1465 - }
1466 -
1467 - public void testByDefaultDoesNotPreserveReferencesAcrossDifferentObjectsInStream()
1468 - throws Exception {
1469 - xstream.alias("person", Person.class);
1470 -
1471 - // Setup initial data: two object, one referencing another...
1472 - Person alice = new Person("Alice", "Thing");
1473 - Person jane = new Person("Jane", "Blah");
1474 - jane.secretary = alice;
1475 -
1476 - // Serialize the two individual objects.
1477 - StringWriter writer = new StringWriter();
1478 - ObjectOutputStream out = xstream.createObjectOutputStream(writer);
1479 - out.writeObject(alice);
1480 - out.writeObject(jane);
1481 - out.close();
1482 -
1483 - // Deserialize the two objects.
1484 - ObjectInputStream in = xstream.createObjectInputStream(new StringReader(writer
1485 - .toString()));
1486 - alice = (Person)in.readObject();
1487 - jane = (Person)in.readObject();
1488 - in.close();
1489 -
1490 - assertNotSame(alice, jane.secretary); // NOT SAME
1491 - }
1492 -
1493 - static class ReusingReferenceByIdMarshallingStrategy implements MarshallingStrategy {
1494 -
1495 - private ReferenceByIdMarshaller marshaller;
1496 - private ReferenceByIdUnmarshaller unmarshaller;
1497 -
1498 - public void marshal(HierarchicalStreamWriter writer, Object obj,
1499 - ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder) {
1500 - if (marshaller == null) {
1501 - marshaller = new ReferenceByIdMarshaller(writer, converterLookup, mapper);
1502 - }
1503 - marshaller.start(obj, dataHolder);
1504 - }
1505 -
1506 - public Object unmarshal(Object root, HierarchicalStreamReader reader,
1507 - DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper) {
1508 - if (unmarshaller == null) {
1509 - unmarshaller = new ReferenceByIdUnmarshaller(
1510 - root, reader, converterLookup, mapper);
1511 - }
1512 - return unmarshaller.start(dataHolder);
1513 - }
1514 - }
1515 -
1516 - public void testSupportsOptionToPreserveReferencesAcrossDifferentObjectsInStream()
1517 - throws Exception {
1518 - xstream.alias("person", Person.class);
1519 - xstream.setMarshallingStrategy(new ReusingReferenceByIdMarshallingStrategy());
1520 -
1521 - // Setup initial data: two object, one referencing another...
1522 - Person alice = new Person("Alice", "Thing");
1523 - Person jane = new Person("Jane", "Blah");
1524 - jane.secretary = alice;
1525 -
1526 - // Serialize the two individual objects.
1527 - StringWriter writer = new StringWriter();
1528 - ObjectOutputStream out = xstream.createObjectOutputStream(writer);
1529 - out.writeObject(alice);
1530 - out.writeObject(jane);
1531 - out.close();
1532 -
1533 - // Deserialize the two objects.
1534 - ObjectInputStream in = xstream.createObjectInputStream(new StringReader(writer
1535 - .toString()));
1536 - alice = (Person)in.readObject();
1537 - jane = (Person)in.readObject();
1538 - in.close();
1539 -
1540 - assertSame(alice, jane.secretary);
1541 - }
1542 -
1543 - public void testReadUnsignedValuesFromInputStream() throws IOException {
1544 - final Writer writer = new StringWriter();
1545 - final ObjectOutputStream oos = xstream.createObjectOutputStream(writer);
1546 - oos.writeByte(1);
1547 - oos.writeByte(-1);
1548 - oos.writeByte(Byte.MIN_VALUE);
1549 - oos.writeShort(1);
1550 - oos.writeShort(-1);
1551 - oos.writeShort(Short.MIN_VALUE);
1552 - oos.close();
1553 -
1554 - final String expectedXml = ""
1555 - + "<object-stream>\n"
1556 - + " <byte>1</byte>\n"
1557 - + " <byte>-1</byte>\n"
1558 - + " <byte>-128</byte>\n"
1559 - + " <short>1</short>\n"
1560 - + " <short>-1</short>\n"
1561 - + " <short>-32768</short>\n"
1562 - + "</object-stream>";
1563 -
1564 - assertEquals(expectedXml, writer.toString());
1565 -
1566 - final ObjectInputStream ois = xstream.createObjectInputStream(new StringReader(writer.toString()));
1567 - assertEquals(1, ois.readUnsignedByte());
1568 - assertEquals(255, ois.readUnsignedByte());
1569 - assertEquals(128, ois.readUnsignedByte());
1570 - assertEquals(1, ois.readUnsignedShort());
1571 - assertEquals(65535, ois.readUnsignedShort());
1572 - assertEquals(32768, ois.readUnsignedShort());
1573 -
1574 - ois.close();
1575 - }
1576 -}
1577 diff --git a/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java b/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java
1578 deleted file mode 100644
1579 index f5aa906..0000000
1580 --- a/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java
1581 +++ /dev/null
1582 @@ -1,187 +0,0 @@
1583 -/*
1584 - * Copyright (C) 2005 Joe Walnes.
1585 - * Copyright (C) 2006, 2007, 2011, 2013, 2016, 2017, 2021 XStream Committers.
1586 - * All rights reserved.
1587 - *
1588 - * The software in this package is published under the terms of the BSD
1589 - * style license a copy of which has been included with this distribution in
1590 - * the LICENSE.txt file.
1591 - *
1592 - * Created on 30. April 2005 by Joe Walnes
1593 - */
1594 -package com.thoughtworks.xstream.io;
1595 -
1596 -import java.io.ByteArrayInputStream;
1597 -import java.io.ByteArrayOutputStream;
1598 -import java.util.ArrayList;
1599 -
1600 -import com.thoughtworks.acceptance.objects.SampleLists;
1601 -import com.thoughtworks.xstream.XStream;
1602 -import com.thoughtworks.xstream.converters.UnmarshallingContext;
1603 -import com.thoughtworks.xstream.converters.collections.CollectionConverter;
1604 -import com.thoughtworks.xstream.core.JVM;
1605 -import com.thoughtworks.xstream.io.binary.BinaryStreamDriver;
1606 -import com.thoughtworks.xstream.io.xml.BEAStaxDriver;
1607 -import com.thoughtworks.xstream.io.xml.Dom4JDriver;
1608 -import com.thoughtworks.xstream.io.xml.DomDriver;
1609 -import com.thoughtworks.xstream.io.xml.JDomDriver;
1610 -import com.thoughtworks.xstream.io.xml.KXml2DomDriver;
1611 -import com.thoughtworks.xstream.io.xml.KXml2Driver;
1612 -import com.thoughtworks.xstream.io.xml.MXParserDomDriver;
1613 -import com.thoughtworks.xstream.io.xml.MXParserDriver;
1614 -import com.thoughtworks.xstream.io.xml.StaxDriver;
1615 -import com.thoughtworks.xstream.io.xml.WstxDriver;
1616 -import com.thoughtworks.xstream.io.xml.XomDriver;
1617 -import com.thoughtworks.xstream.io.xml.Xpp3DomDriver;
1618 -import com.thoughtworks.xstream.io.xml.Xpp3Driver;
1619 -import com.thoughtworks.xstream.io.xml.XppDomDriver;
1620 -import com.thoughtworks.xstream.io.xml.XppDriver;
1621 -
1622 -import junit.framework.Assert;
1623 -import junit.framework.AssertionFailedError;
1624 -import junit.framework.Test;
1625 -import junit.framework.TestCase;
1626 -import junit.framework.TestSuite;
1627 -
1628 -
1629 -public class DriverEndToEndTestSuite extends TestSuite {
1630 -
1631 - public static Test suite() {
1632 - return new DriverEndToEndTestSuite();
1633 - }
1634 -
1635 - public DriverEndToEndTestSuite() {
1636 - super(DriverEndToEndTestSuite.class.getName());
1637 - addDriverTest(new BEAStaxDriver());
1638 - addDriverTest(new BinaryStreamDriver());
1639 - addDriverTest(new Dom4JDriver());
1640 - addDriverTest(new DomDriver());
1641 - addDriverTest(new JDomDriver());
1642 - if (JVM.is15()) {
1643 - final Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.xml.JDom2Driver");
1644 - try {
1645 - addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
1646 - } catch (final InstantiationException e) {
1647 - throw new AssertionFailedError("Cannot instantiate " + driverType.getName());
1648 - } catch (final IllegalAccessException e) {
1649 - throw new AssertionFailedError("Cannot access default constructor of " + driverType.getName());
1650 - }
1651 - }
1652 - addDriverTest(new KXml2DomDriver());
1653 - addDriverTest(new KXml2Driver());
1654 - addDriverTest(new StaxDriver());
1655 - if (JVM.is16()) {
1656 - final Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.xml.StandardStaxDriver");
1657 - try {
1658 - addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
1659 - } catch (final InstantiationException e) {
1660 - throw new AssertionFailedError("Cannot instantiate " + driverType.getName());
1661 - } catch (final IllegalAccessException e) {
1662 - throw new AssertionFailedError("Cannot access default constructor of " + driverType.getName());
1663 - }
1664 - }
1665 - addDriverTest(new WstxDriver());
1666 - addDriverTest(new XomDriver());
1667 - addDriverTest(new MXParserDomDriver());
1668 - addDriverTest(new MXParserDriver());
1669 - addDriverTest(new Xpp3DomDriver());
1670 - addDriverTest(new Xpp3Driver());
1671 - addDriverTest(new XppDomDriver());
1672 - addDriverTest(new XppDriver());
1673 - if (JVM.is14()) {
1674 - final Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver");
1675 - try {
1676 - addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
1677 - } catch (final InstantiationException e) {
1678 - throw new AssertionFailedError("Cannot instantiate " + driverType.getName());
1679 - } catch (final IllegalAccessException e) {
1680 - throw new AssertionFailedError("Cannot access default constructor of " + driverType.getName());
1681 - }
1682 - }
1683 - }
1684 -
1685 - private void testObject(final HierarchicalStreamDriver driver) {
1686 - final XStream xstream = new XStream(driver);
1687 - xstream.allowTypes(new Class[] { SampleLists.class });
1688 - xstream.registerConverter(new CollectionConverter(xstream.getMapper()) {
1689 -
1690 - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
1691 - final ExtendedHierarchicalStreamReader exReader = (ExtendedHierarchicalStreamReader)reader;
1692 - if (exReader.peekNextChild() == null) {
1693 - return new ArrayList();
1694 - }
1695 - return super.unmarshal(reader, context);
1696 - }
1697 -
1698 - });
1699 -
1700 - final SampleLists in = new SampleLists();
1701 - in.good.add("one");
1702 - in.good.add("two");
1703 - in.good.add("three");
1704 - in.bad.add(Boolean.TRUE);
1705 - in.bad.add(Boolean.FALSE);
1706 - final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
1707 - xstream.toXML(in, buffer);
1708 - final Object out = xstream.fromXML(new ByteArrayInputStream(buffer.toByteArray()));
1709 -
1710 - Assert.assertEquals(in, out);
1711 - }
1712 -
1713 - private void testStream(final HierarchicalStreamDriver driver) {
1714 - final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
1715 - final HierarchicalStreamWriter writer = driver.createWriter(buffer);
1716 - writer.startNode("root");
1717 - writer.startNode("child1");
1718 - writer.startNode("baby");
1719 - writer.endNode();
1720 - writer.endNode();
1721 - writer.startNode("child2");
1722 - writer.addAttribute("A", "a");
1723 - writer.setValue("v");
1724 - writer.endNode();
1725 - writer.endNode();
1726 - writer.close();
1727 -
1728 - final HierarchicalStreamReader reader = driver.createReader(new ByteArrayInputStream(buffer.toByteArray()));
1729 - Assert.assertEquals("root", reader.getNodeName());
1730 - Assert.assertTrue(reader.hasMoreChildren());
1731 - reader.moveDown();
1732 - Assert.assertEquals("child1", reader.getNodeName());
1733 - Assert.assertEquals(0, reader.getAttributeCount());
1734 - Assert.assertNull(reader.getAttribute("foo"));
1735 - Assert.assertTrue(reader.hasMoreChildren());
1736 - reader.moveUp();
1737 - Assert.assertTrue(reader.hasMoreChildren());
1738 - reader.moveDown();
1739 - Assert.assertEquals("child2", reader.getNodeName());
1740 - Assert.assertEquals(1, reader.getAttributeCount());
1741 - Assert.assertEquals("a", reader.getAttribute("A"));
1742 - Assert.assertNull(reader.getAttribute("foo"));
1743 - //Assert.assertNull(reader.getAttribute(1));
1744 - Assert.assertFalse(reader.hasMoreChildren());
1745 - reader.moveUp();
1746 - Assert.assertFalse(reader.hasMoreChildren());
1747 - reader.close();
1748 - }
1749 -
1750 - private void addDriverTest(final HierarchicalStreamDriver driver) {
1751 - final String testName = getShortName(driver);
1752 - addTest(new TestCase(testName + "_Object") {
1753 - protected void runTest() throws Throwable {
1754 - testObject(driver);
1755 - }
1756 - });
1757 - addTest(new TestCase(testName + "_Stream") {
1758 - protected void runTest() throws Throwable {
1759 - testStream(driver);
1760 - }
1761 - });
1762 - }
1763 -
1764 - private String getShortName(final HierarchicalStreamDriver driver) {
1765 - String result = driver.getClass().getName();
1766 - result = result.substring(result.lastIndexOf('.') + 1);
1767 - return result;
1768 - }
1769 -}
1770 diff --git a/xstream/src/test/com/thoughtworks/xstream/io/binary/BinaryStreamTest.java b/xstream/src/test/com/thoughtworks/xstream/io/binary/BinaryStreamTest.java
1771 deleted file mode 100644
1772 index a01065a..0000000
1773 --- a/xstream/src/test/com/thoughtworks/xstream/io/binary/BinaryStreamTest.java
1774 +++ /dev/null
1775 @@ -1,92 +0,0 @@
1776 -/*
1777 - * Copyright (C) 2006 Joe Walnes.
1778 - * Copyright (C) 2006, 2007, 2011, 2015, 2016, 2021 XStream Committers.
1779 - * All rights reserved.
1780 - *
1781 - * The software in this package is published under the terms of the BSD
1782 - * style license a copy of which has been included with this distribution in
1783 - * the LICENSE.txt file.
1784 - *
1785 - * Created on 04. June 2006 by Joe Walnes
1786 - */
1787 -package com.thoughtworks.xstream.io.binary;
1788 -
1789 -import com.thoughtworks.xstream.XStreamException;
1790 -import com.thoughtworks.xstream.io.HierarchicalStreamReader;
1791 -import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
1792 -import com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier;
1793 -import com.thoughtworks.xstream.io.xml.AbstractXMLReaderTest;
1794 -import com.thoughtworks.xstream.io.xml.MXParserDriver;
1795 -
1796 -import java.io.ByteArrayOutputStream;
1797 -import java.io.StringReader;
1798 -import java.io.ByteArrayInputStream;
1799 -
1800 -public class BinaryStreamTest extends AbstractXMLReaderTest {
1801 -
1802 - private HierarchicalStreamCopier copier = new HierarchicalStreamCopier();
1803 -
1804 - protected void setUp() throws Exception {
1805 - super.setUp();
1806 - }
1807 -
1808 - // factory method
1809 - protected HierarchicalStreamReader createReader(String xml) throws Exception {
1810 - // Transmogrify XML input into binary format.
1811 - HierarchicalStreamReader xmlReader =
1812 - new MXParserDriver().createReader(new StringReader(xml));
1813 -
1814 - ByteArrayOutputStream buffer = new ByteArrayOutputStream();
1815 - HierarchicalStreamWriter binaryWriter = new BinaryStreamWriter(buffer);
1816 - copier.copy(xmlReader, binaryWriter);
1817 -
1818 - return new BinaryStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
1819 - }
1820 -
1821 - public void testHandlesMoreThan256Ids() {
1822 - int count = 500;
1823 -
1824 - ByteArrayOutputStream buffer = new ByteArrayOutputStream();
1825 - HierarchicalStreamWriter binaryWriter = new BinaryStreamWriter(buffer);
1826 - binaryWriter.startNode("root");
1827 - for (int i = 0; i < count; i++) {
1828 - binaryWriter.startNode("node" + i);
1829 - binaryWriter.endNode();
1830 - }
1831 - for (int i = 0; i < count; i++) {
1832 - binaryWriter.startNode("node" + i);
1833 - binaryWriter.endNode();
1834 - }
1835 - binaryWriter.endNode();
1836 -
1837 - HierarchicalStreamReader binaryReader
1838 - = new BinaryStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
1839 - assertEquals("root", binaryReader.getNodeName());
1840 - for (int i = 0; i < count; i++) {
1841 - assertTrue("Expected child " + i, binaryReader.hasMoreChildren());
1842 - binaryReader.moveDown();
1843 - assertEquals("node" + i, binaryReader.getNodeName());
1844 - binaryReader.moveUp();
1845 - }
1846 - for (int i = 0; i < count; i++) {
1847 - assertTrue("Expected child " + i, binaryReader.hasMoreChildren());
1848 - binaryReader.moveDown();
1849 - assertEquals("node" + i, binaryReader.getNodeName());
1850 - binaryReader.moveUp();
1851 - }
1852 -
1853 - }
1854 -
1855 - public void testIsXXEVulnerableWithExternalGeneralEntity() throws Exception {
1856 - try {
1857 - super.testIsXXEVulnerableWithExternalGeneralEntity();
1858 - fail("Thrown " + XStreamException.class.getName() + " expected");
1859 - } catch (final XStreamException e) {
1860 - final String message = e.getCause().getMessage();
1861 - if (message.indexOf("resolve entity") < 0) {
1862 - throw e;
1863 - }
1864 - }
1865 - }
1866 -
1867 -}
1868 diff --git a/xstream/src/test/com/thoughtworks/xstream/io/copy/HierarchicalStreamCopierTest.java b/xstream/src/test/com/thoughtworks/xstream/io/copy/HierarchicalStreamCopierTest.java
1869 deleted file mode 100644
1870 index 3b94d7c..0000000
1871 --- a/xstream/src/test/com/thoughtworks/xstream/io/copy/HierarchicalStreamCopierTest.java
1872 +++ /dev/null
1873 @@ -1,74 +0,0 @@
1874 -/*
1875 - * Copyright (C) 2006 Joe Walnes.
1876 - * Copyright (C) 2006, 2007, 2011, 2015, 2016, 2021 XStream Committers.
1877 - * All rights reserved.
1878 - *
1879 - * The software in this package is published under the terms of the BSD
1880 - * style license a copy of which has been included with this distribution in
1881 - * the LICENSE.txt file.
1882 - *
1883 - * Created on 04. June 2006 by Joe Walnes
1884 - */
1885 -package com.thoughtworks.xstream.io.copy;
1886 -
1887 -import com.thoughtworks.xstream.XStreamException;
1888 -import com.thoughtworks.xstream.io.HierarchicalStreamReader;
1889 -import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
1890 -import com.thoughtworks.xstream.io.xml.AbstractXMLReaderTest;
1891 -import com.thoughtworks.xstream.io.xml.CompactWriter;
1892 -import com.thoughtworks.xstream.io.xml.MXParserDriver;
1893 -import com.thoughtworks.xstream.io.xml.XppReader;
1894 -import com.thoughtworks.xstream.io.xml.xppdom.XppFactory;
1895 -
1896 -import org.xmlpull.v1.XmlPullParserException;
1897 -
1898 -import java.io.StringReader;
1899 -import java.io.StringWriter;
1900 -
1901 -public class HierarchicalStreamCopierTest extends AbstractXMLReaderTest {
1902 -
1903 - private HierarchicalStreamCopier copier = new HierarchicalStreamCopier();
1904 -
1905 - // This test leverages the existing (comprehensive) tests for the XML readers
1906 - // and adds an additional stage of copying in.
1907 -
1908 - // factory method - overriding base class.
1909 - protected HierarchicalStreamReader createReader(String xml) throws Exception {
1910 - HierarchicalStreamReader sourceReader =
1911 - new MXParserDriver().createReader(new StringReader(xml));
1912 -
1913 - StringWriter buffer = new StringWriter();
1914 - HierarchicalStreamWriter destinationWriter = new CompactWriter(buffer);
1915 -
1916 - copier.copy(sourceReader, destinationWriter);
1917 -
1918 - return new XppReader(new StringReader(buffer.toString()), XppFactory.createDefaultParser());
1919 - }
1920 -
1921 - public void testSkipsValueIfEmpty() throws XmlPullParserException {
1922 - String input = "<root><empty1/><empty2></empty2><not-empty>blah</not-empty></root>";
1923 - String expected = "<root><empty1/><empty2/><not-empty>blah</not-empty></root>";
1924 - HierarchicalStreamReader sourceReader = new XppReader(
1925 - new StringReader(input), XppFactory.createDefaultParser());
1926 -
1927 - StringWriter buffer = new StringWriter();
1928 - HierarchicalStreamWriter destinationWriter = new CompactWriter(buffer);
1929 -
1930 - copier.copy(sourceReader, destinationWriter);
1931 -
1932 - assertEquals(expected, buffer.toString());
1933 - }
1934 -
1935 - public void testIsXXEVulnerableWithExternalGeneralEntity() throws Exception {
1936 - try {
1937 - super.testIsXXEVulnerableWithExternalGeneralEntity();
1938 - fail("Thrown " + XStreamException.class.getName() + " expected");
1939 - } catch (final XStreamException e) {
1940 - final String message = e.getCause().getMessage();
1941 - if (message.indexOf("resolve entity") < 0) {
1942 - throw e;
1943 - }
1944 - }
1945 - }
1946 -
1947 -}
1948 diff --git a/xstream/src/test/com/thoughtworks/xstream/io/xml/MXParserReaderTest.java b/xstream/src/test/com/thoughtworks/xstream/io/xml/MXParserReaderTest.java
1949 deleted file mode 100644
1950 index 1f07106..0000000
1951 --- a/xstream/src/test/com/thoughtworks/xstream/io/xml/MXParserReaderTest.java
1952 +++ /dev/null
1953 @@ -1,41 +0,0 @@
1954 -/*
1955 - * Copyright (C) 2021 XStream Committers.
1956 - * All rights reserved.
1957 - *
1958 - * The software in this package is published under the terms of the BSD
1959 - * style license a copy of which has been included with this distribution in
1960 - * the LICENSE.txt file.
1961 - *
1962 - * Created on 2. January 2021 by Joerg Schaible
1963 - */
1964 -package com.thoughtworks.xstream.io.xml;
1965 -
1966 -import com.thoughtworks.xstream.XStreamException;
1967 -import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
1968 -import com.thoughtworks.xstream.io.HierarchicalStreamReader;
1969 -
1970 -import java.io.StringReader;
1971 -
1972 -public class MXParserReaderTest extends AbstractXMLReaderTest {
1973 -
1974 - private HierarchicalStreamDriver driver = new MXParserDriver();
1975 -
1976 - // factory method
1977 - protected HierarchicalStreamReader createReader(String xml) throws Exception {
1978 - return driver.createReader(new StringReader(xml));
1979 - }
1980 -
1981 - public void testIsXXEVulnerableWithExternalGeneralEntity() throws Exception {
1982 - try {
1983 - super.testIsXXEVulnerableWithExternalGeneralEntity();
1984 - fail("Thrown " + XStreamException.class.getName() + " expected");
1985 - } catch (final XStreamException e) {
1986 - final String message = e.getCause().getMessage();
1987 - if (message.indexOf("resolve entity") < 0) {
1988 - throw e;
1989 - }
1990 - }
1991 - }
1992 -
1993 - // inherits tests from superclass
1994 -}
00 01-java7-compatibility.patch
11 02-disable-beastax-driver.patch
2 no-mxparser.patch