102 try {
103 XMLStreamWriter writer = staxOut.createXMLStreamWriter(new PrintStream(out) {
104 @Override
105 public void close() {
106 // noop
107 }
108 });
109 writer = createIndenter(writer);
110 packet.getMessage().copy().writeTo(writer);
111 writer.close();
112 } catch (XMLStreamException e) {
113 e.printStackTrace(out);
114 }
115 out.println("============");
116 }
117
118 /**
119 * Wraps {@link XMLStreamWriter} by an indentation engine if possible.
120 *
121 * <p>
122 * We can do this only when we have <tt>stax-utils.jar</tt> in the classpath.
123 */
124 private XMLStreamWriter createIndenter(XMLStreamWriter writer) {
125 try {
126 Class clazz = getClass().getClassLoader().loadClass("javanet.staxutils.IndentingXMLStreamWriter");
127 Constructor c = clazz.getConstructor(XMLStreamWriter.class);
128 writer = (XMLStreamWriter)c.newInstance(writer);
129 } catch (Exception e) {
130 // if stax-utils.jar is not in the classpath, this will fail
131 // so, we'll just have to do without indentation
132 if(!warnStaxUtils) {
133 warnStaxUtils = true;
134 out.println("WARNING: put stax-utils.jar to the classpath to indent the dump output");
135 }
136 }
137 return writer;
138 }
139
140
141 public AbstractTubeImpl copy(TubeCloner cloner) {
142 return new DumpTube(this,cloner);
|
102 try {
103 XMLStreamWriter writer = staxOut.createXMLStreamWriter(new PrintStream(out) {
104 @Override
105 public void close() {
106 // noop
107 }
108 });
109 writer = createIndenter(writer);
110 packet.getMessage().copy().writeTo(writer);
111 writer.close();
112 } catch (XMLStreamException e) {
113 e.printStackTrace(out);
114 }
115 out.println("============");
116 }
117
118 /**
119 * Wraps {@link XMLStreamWriter} by an indentation engine if possible.
120 *
121 * <p>
122 * We can do this only when we have {@code stax-utils.jar} in the classpath.
123 */
124 private XMLStreamWriter createIndenter(XMLStreamWriter writer) {
125 try {
126 Class clazz = getClass().getClassLoader().loadClass("javanet.staxutils.IndentingXMLStreamWriter");
127 Constructor c = clazz.getConstructor(XMLStreamWriter.class);
128 writer = (XMLStreamWriter)c.newInstance(writer);
129 } catch (Exception e) {
130 // if stax-utils.jar is not in the classpath, this will fail
131 // so, we'll just have to do without indentation
132 if(!warnStaxUtils) {
133 warnStaxUtils = true;
134 out.println("WARNING: put stax-utils.jar to the classpath to indent the dump output");
135 }
136 }
137 return writer;
138 }
139
140
141 public AbstractTubeImpl copy(TubeCloner cloner) {
142 return new DumpTube(this,cloner);
|