Index: /apps/workspaces/main/xstream/src/java/com/thoughtworks/xstream/core/util/QuickWriter.java =================================================================== --- /apps/workspaces/main/xstream/src/java/com/thoughtworks/xstream/core/util/QuickWriter.java (revision 719) +++ /apps/workspaces/main/xstream/src/java/com/thoughtworks/xstream/core/util/QuickWriter.java (working copy) @@ -21,7 +21,7 @@ buffer = new char[bufferSize]; } - public void write(String str) { + public void write(String str) throws IOException { int len = str.length(); if (pointer + len >= buffer.length) { flush(); @@ -34,7 +34,7 @@ pointer += len; } - public void write(char c) { + public void write(char c) throws IOException { if (pointer + 1 >= buffer.length) { flush(); } @@ -41,7 +41,7 @@ buffer[pointer++] = c; } - public void write(char[] c) { + public void write(char[] c) throws IOException { int len = c.length; if (pointer + len >= buffer.length) { flush(); @@ -54,24 +54,17 @@ pointer += len; } - public void flush() { - try { - writer.write(buffer, 0, pointer); - pointer = 0; - writer.flush(); - } catch (IOException e) { - throw new StreamException(e); - } + public void flush() throws IOException { + writer.write(buffer, 0, pointer); + pointer = 0; + writer.flush(); } - public void close() { - try { - writer.write(buffer, 0, pointer); - pointer = 0; - writer.close(); - } catch (IOException e) { - throw new StreamException(e); - } + public void close() throws IOException { + if(pointer != 0) { + flush(); + } + writer.close(); } private void raw(char[] c) { Index: /apps/workspaces/main/xstream/src/java/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java =================================================================== --- /apps/workspaces/main/xstream/src/java/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java (revision 719) +++ /apps/workspaces/main/xstream/src/java/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java (working copy) @@ -1,10 +1,12 @@ package com.thoughtworks.xstream.io.xml; +import java.io.IOException; +import java.io.Writer; + import com.thoughtworks.xstream.core.util.FastStack; import com.thoughtworks.xstream.core.util.QuickWriter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; - -import java.io.Writer; +import com.thoughtworks.xstream.io.StreamException; /** * A simple writer that outputs XML in a pretty-printed indented stream. @@ -51,94 +53,121 @@ } public void startNode(String name) { - tagIsEmpty = false; - finishTag(); - writer.write('<'); - writer.write(name); - elementStack.push(name); - tagInProgress = true; - depth++; - readyForNewLine = true; - tagIsEmpty = true; + try { + tagIsEmpty = false; + finishTag(); + try { + writer.write('<'); + writer.write(name); + } catch (IOException e) { + throw new StreamException(e); + } + elementStack.push(name); + tagInProgress = true; + depth++; + readyForNewLine = true; + tagIsEmpty = true; + } catch (IOException e) { + throw new StreamException(e); + } } public void setValue(String text) { - readyForNewLine = false; - tagIsEmpty = false; - finishTag(); - - writeText(writer, text); + try { + readyForNewLine = false; + tagIsEmpty = false; + finishTag(); + writeText(writer, text); + } catch (IOException e) { + throw new StreamException(e); + } } public void addAttribute(String key, String value) { - writer.write(' '); - writer.write(key); - writer.write('='); - writer.write('\"'); - writeAttributeValue(writer, value); - writer.write('\"'); + try { + writer.write(' '); + writer.write(key); + writer.write('='); + writer.write('\"'); + writeAttributeValue(writer, value); + writer.write('\"'); + } catch (IOException e) { + throw new StreamException(e); + } } protected void writeAttributeValue(QuickWriter writer, String text) { - writeText(text); + try { + writeText(text); + } catch (IOException e) { + throw new StreamException(e); + } } protected void writeText(QuickWriter writer, String text) { - writeText(text); + try { + writeText(text); + } catch (IOException e) { + throw new StreamException(e); + } } - private void writeText(String text) { - int length = text.length(); - for (int i = 0; i < length; i++) { - char c = text.charAt(i); - switch (c) { - case '\0': - this.writer.write(NULL); - break; - case '&': - this.writer.write(AMP); - break; - case '<': - this.writer.write(LT); - break; - case '>': - this.writer.write(GT); - break; - case '"': - this.writer.write(QUOT); - break; - case '\'': - this.writer.write(APOS); - break; - case '\r': - this.writer.write(SLASH_R); - break; - default: - this.writer.write(c); - } - } + private void writeText(String text) throws IOException { + int length = text.length(); + for (int i = 0; i < length; i++) { + char c = text.charAt(i); + switch (c) { + case '\0': + this.writer.write(NULL); + break; + case '&': + this.writer.write(AMP); + break; + case '<': + this.writer.write(LT); + break; + case '>': + this.writer.write(GT); + break; + case '"': + this.writer.write(QUOT); + break; + case '\'': + this.writer.write(APOS); + break; + case '\r': + this.writer.write(SLASH_R); + break; + default: + this.writer.write(c); + } + } } public void endNode() { - depth--; - if (tagIsEmpty) { - writer.write('/'); - readyForNewLine = false; - finishTag(); - elementStack.popSilently(); - } else { - finishTag(); - writer.write(CLOSE); - writer.write((String)elementStack.pop()); - writer.write('>'); - } - readyForNewLine = true; - if (depth == 0 ) { - writer.flush(); - } + try { + depth--; + if (tagIsEmpty) { + writer.write('/'); + readyForNewLine = false; + finishTag(); + elementStack.popSilently(); + } else { + finishTag(); + writer.write(CLOSE); + writer.write((String) elementStack.pop()); + writer.write('>'); + } + readyForNewLine = true; + if (depth == 0) { + writer.flush(); + } + } catch (IOException e) { + throw new StreamException(e); + } } - private void finishTag() { + private void finishTag() throws IOException { if (tagInProgress) { writer.write('>'); } @@ -151,18 +180,30 @@ } protected void endOfLine() { - writer.write(NL); - for (int i = 0; i < depth; i++) { - writer.write(lineIndenter); - } + try { + writer.write(NL); + for (int i = 0; i < depth; i++) { + writer.write(lineIndenter); + } + } catch (IOException e) { + throw new StreamException(e); + } } public void flush() { - writer.flush(); + try { + writer.flush(); + } catch (IOException e) { + throw new StreamException(e); + } } public void close() { - writer.close(); + try { + writer.close(); + } catch (IOException e) { + throw new StreamException(e); + } } public HierarchicalStreamWriter underlyingWriter() { Index: /apps/workspaces/main/xstream/src/test/com/thoughtworks/xstream/io/xml/CompactWriterTest.java =================================================================== --- /apps/workspaces/main/xstream/src/test/com/thoughtworks/xstream/io/xml/CompactWriterTest.java (revision 719) +++ /apps/workspaces/main/xstream/src/test/com/thoughtworks/xstream/io/xml/CompactWriterTest.java (working copy) @@ -1,7 +1,9 @@ package com.thoughtworks.xstream.io.xml; import com.thoughtworks.xstream.core.util.QuickWriter; +import com.thoughtworks.xstream.io.StreamException; +import java.io.IOException; import java.io.StringWriter; import java.io.Writer; @@ -50,9 +52,13 @@ public void testWriteTextAsCDATA() { writer = new CompactWriter(buffer) { protected void writeText(QuickWriter writer, String text) { - writer.write("<[CDATA["); - writer.write(text); - writer.write("]]>"); + try { + writer.write("<[CDATA["); + writer.write(text); + writer.write("]]>"); + } catch (IOException e) { + throw new StreamException(e); + } } }; Index: /apps/workspaces/main/xstream/src/test/com/thoughtworks/xstream/io/xml/PrettyPrintWriterTest.java =================================================================== --- /apps/workspaces/main/xstream/src/test/com/thoughtworks/xstream/io/xml/PrettyPrintWriterTest.java (revision 719) +++ /apps/workspaces/main/xstream/src/test/com/thoughtworks/xstream/io/xml/PrettyPrintWriterTest.java (working copy) @@ -1,7 +1,9 @@ package com.thoughtworks.xstream.io.xml; import com.thoughtworks.xstream.core.util.QuickWriter; +import com.thoughtworks.xstream.io.StreamException; +import java.io.IOException; import java.io.StringWriter; public class PrettyPrintWriterTest extends AbstractXMLWriterTest { @@ -54,11 +56,19 @@ public void testAllowsUserToOverrideTextAndAttributeEscapingRules() { writer = new PrettyPrintWriter(buffer, " ") { protected void writeAttributeValue(QuickWriter writer, String text) { - writer.write(replace(text, '&', "_&_")); + try { + writer.write(replace(text, '&', "_&_")); + } catch (IOException e) { + throw new StreamException(e); + } } protected void writeText(QuickWriter writer, String text) { - writer.write(replace(text, '&', "AND")); + try { + writer.write(replace(text, '&', "AND")); + } catch (IOException e) { + throw new StreamException(e); + } } };