Permalink
Browse files

Removed some dead code, don't output the divider if there's only one …

…document
  • Loading branch information...
ndw committed Apr 17, 2015
1 parent 28b8e18 commit 13d88aa186df2a6db3cb9a6042ca5d8200ccb793
Showing with 16 additions and 96 deletions.
  1. +16 −96 src/main/java/com/xmlcalabash/io/WritableDocument.java
@@ -162,19 +162,19 @@ public void write(final XdmNode doc) {
S9apiUtils.serialize(runtime, doc, serializer);
} else {
try {
- DataStore store = runtime.getDataStore();
- store.writeEntry(uri, uri, media, new DataWriter() {
- public void store(OutputStream ostream)
- throws IOException {
- logger.trace("Attempt to write file: " + uri);
- serializer.setOutputStream(ostream);
- try {
- S9apiUtils.serialize(runtime, doc, serializer);
- } catch (SaxonApiException e) {
- throw new IOException(e);
- }
- }
- });
+ DataStore store = runtime.getDataStore();
+ store.writeEntry(uri, uri, media, new DataWriter() {
+ public void store(OutputStream ostream)
+ throws IOException {
+ logger.trace("Attempt to write file: " + uri);
+ serializer.setOutputStream(ostream);
+ try {
+ S9apiUtils.serialize(runtime, doc, serializer);
+ } catch (SaxonApiException e) {
+ throw new IOException(e);
+ }
+ }
+ });
} catch (IOException ex) {
if (ex.getCause() instanceof SaxonApiException) {
throw (SaxonApiException) ex.getCause();
@@ -183,8 +183,9 @@ public void store(OutputStream ostream)
}
}
-
- if ((((ostream == null) && (uri == null)) || (System.out.equals(ostream))) && runtime.getDebug()) {
+ writeCount++;
+ if ((((ostream == null) && (uri == null) && (writeCount > 1))
+ || (System.out.equals(ostream))) && runtime.getDebug()) {
System.out.println("\n--<document boundary>--------------------------------------------------------------------------");
}
} catch (SaxonApiException sae) {
@@ -205,85 +206,4 @@ public int documentsWritten() {
public int documentsRead() {
return 1;
}
-
- /**
- * Decode UTF-8/URL encoded strings.
- *
- * @param s the string to be decoded
- * @return the decoded string
- */
- private String decodeUTF8(String s) {
- if (s == null) {
- return null;
- }
-
- if(s.indexOf('%') == -1) {
- //Optimization, nothing to uncorrect here
- return s;
- }
-
- StringBuilder sbuf = new StringBuilder();
- int l = s.length();
- int ch = -1;
- int b = 0, sumb = 0;
- boolean applyUTF8dec = false;
-
- for (int i = 0, more = -1; i < l; i++) {
- /* Get next byte b from URL segment s */
- char current = s.charAt(i);
- ch = current;
- switch (ch) {
- case '%' :
- if (i + 2 < s.length()) {
- ch = s.charAt(++i);
- int hb =
- (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a')
- & 0xF;
- ch = s.charAt(++i);
- int lb =
- (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a')
- & 0xF;
- b = (hb << 4) | lb;
- applyUTF8dec = true;
- }
- break;
- default :
- b = ch;
- applyUTF8dec = false;
- }
-
- /* Decode byte b as UTF-8, sumb collects incomplete chars */
- if (applyUTF8dec) {
- if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
- sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
- if (--more == 0) {
- sbuf.append((char) sumb); // Add char to sbuf
- }
- } else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
- sbuf.append((char) b); // Store in sbuf
- } else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
- sumb = b & 0x1f;
- more = 1; // Expect 1 more byte
- } else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
- sumb = b & 0x0f;
- more = 2; // Expect 2 more bytes
- } else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
- sumb = b & 0x07;
- more = 3; // Expect 3 more bytes
- } else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
- sumb = b & 0x03;
- more = 4; // Expect 4 more bytes
- } else /*if ((b & 0xfe) == 0xfc)*/ { // 1111110x (yields 1 bit)
- sumb = b & 0x01;
- more = 5; // Expect 5 more bytes
- }
- } else {
- sbuf.append(current);
- // Do not expect other continuation.
- more = -1;
- }
- /* We don't test if the UTF-8 encoding is well-formed */
- }
- return sbuf.toString();
- }
}

0 comments on commit 13d88aa

Please sign in to comment.