Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void identStreamWithThread(T req, final OutputStream ostream) throws IOException, JAXBException {
- final PipedOutputStream pipedOutput = new PipedOutputStream();
- Runnable copyStream = new Runnable() {
- @Override
- public void run() {
- try {
- PipedInputStream pipedInput = new PipedInputStream(pipedOutput);
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- Transformer transformer = transformerFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- Source source = new StreamSource(pipedInput);
- Result result = new StreamResult(ostream);
- transformer.transform(source, result);
- } catch (IOException e) {
- e.printStackTrace();
- } catch (TransformerException e) {
- e.printStackTrace();
- }
- }
- };
- Thread t = new Thread(copyStream);
- t.setDaemon(true);
- t.start();
- Marshaller m = jaxbContext.createMarshaller();
- m.marshal(req, pipedOutput);
- pipedOutput.close();
- try {
- t.join();
- } catch (InterruptedException e) {
- throw new IOException(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement