forked from ScottOaks/JavaPerformanceTuning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJAXBSerializingTest.java
More file actions
44 lines (39 loc) · 1.37 KB
/
Copy pathJAXBSerializingTest.java
File metadata and controls
44 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Copyright (c) 2013,2014 Scott Oaks. All rights reserved.
*/
package net.sdo;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import net.sdo.jaxb.FindPopularItemsResponse;
public class JAXBSerializingTest extends AbstractParsingTest {
private JAXBContext jc;
private FindPopularItemsResponse responseItems;
private ByteArrayOutputStream os;
@Override
protected void engineInit(RunParams rp) throws IOException {
try {
jc = JAXBContext.newInstance("net.sdo.jaxb");
Unmarshaller u = jc.createUnmarshaller();
responseItems = (FindPopularItemsResponse) u.unmarshal(new ByteArrayInputStream(rp.getInput()));
os = new ByteArrayOutputStream();
} catch (JAXBException ex) {
throw new IOException("Can't create JAXB context", ex);
}
}
@Override
protected void engineRun(InputStream is) throws IOException {
try {
os.reset();
Marshaller m = jc.createMarshaller();
m.marshal(responseItems,os);
} catch (JAXBException ex) {
throw new IOException("Can't create JAXB object", ex);
}
}
}