Permalink
Browse files

[MOD] XQuery: convenience methods added for serializing query results

  • Loading branch information...
1 parent 5c12c3b commit 9eea50073cf8ff4cdb3423421e633d7e957c3e13 @ChristianGruen ChristianGruen committed Apr 29, 2012
@@ -229,13 +229,18 @@ public void serialize(final Serializer ser, final int n) throws IOException {
}
@Override
- public String toString() {
+ public ArrayOutput serialize() throws IOException {
final ArrayOutput ao = new ArrayOutput();
+ serialize(Serializer.get(ao));
+ return ao;
+ }
+
+ @Override
+ public String toString() {
try {
- serialize(Serializer.get(ao));
+ return serialize().toString();
} catch(final IOException ex) {
- Util.notexpected(ex);
+ throw Util.notexpected(ex);
}
- return ao.toString();
}
}
@@ -2,6 +2,7 @@
import java.io.*;
+import org.basex.io.out.*;
import org.basex.io.serial.*;
/**
@@ -25,6 +26,14 @@
boolean sameAs(Result r);
/**
+ * Serializes the result, using the standard XML serializer,
+ * and returns the cached result.
+ * @return serialized value
+ * @throws IOException I/O exception
+ */
+ ArrayOutput serialize() throws IOException;
+
+ /**
* Serializes the complete result.
* @param ser serializer
* @throws IOException I/O exception
@@ -134,14 +134,18 @@ public Value value() {
}
@Override
- public String toString() {
+ public ArrayOutput serialize() throws IOException {
final ArrayOutput ao = new ArrayOutput();
+ serialize(Serializer.get(ao));
+ return ao;
+ }
+
+ @Override
+ public String toString() {
try {
- serialize(Serializer.get(ao));
+ return serialize().toString();
} catch(final IOException ex) {
- // [LW] is that OK? Example: (1, 2, upper-case#1)
- Util.notexpected(ex);
+ throw Util.notexpected(ex);
}
- return ao.toString();
}
}

0 comments on commit 9eea500

Please sign in to comment.