コード例 #1
0
ファイル: DataTree.java プロジェクト: gildafnai82/craq
 /**
  * this method uses a stringbuilder to create a new path for children. This is faster than string
  * appends ( str1 + str2).
  *
  * @param oa OutputArchive to write to.
  * @param path a string builder.
  * @throws IOException
  * @throws InterruptedException
  */
 void serializeNode(OutputArchive oa, StringBuilder path) throws IOException {
   String pathString = path.toString();
   DataNode node = getNode(pathString);
   if (node == null) {
     return;
   }
   String children[] = null;
   synchronized (node) {
     scount++;
     oa.writeString(pathString, "path");
     oa.writeRecord(node, "node");
     children = node.children.toArray(new String[node.children.size()]);
   }
   path.append('/');
   int off = path.length();
   if (children != null) {
     for (String child : children) {
       // since this is single buffer being resused
       // we need
       // to truncate the previous bytes of string.
       path.delete(off, Integer.MAX_VALUE);
       path.append(child);
       serializeNode(oa, path);
     }
   }
 }
コード例 #2
0
ファイル: DataTree.java プロジェクト: gildafnai82/craq
 public void serialize(OutputArchive oa, String tag) throws IOException {
   scount = 0;
   serializeList(longKeyMap, oa);
   serializeNode(oa, new StringBuilder(""));
   // / marks end of stream
   // we need to check if clear had been called in between the snapshot.
   if (root != null) {
     oa.writeString("/", "path");
   }
 }