コード例 #1
0
ファイル: FSTree.java プロジェクト: Tim-NL/SpaceRTK
  @Override
  public void writeExternal(ObjectOutput oo) throws IOException {
    /*
     * Serialization format:
     * byte 1: serial version
     * byte 2: name length (l)
     * byte 3 to l+3: name
     * byte l+4 to l+67: size of node
     * byte l+68: children count
     * byte l+69 to n: children (recursive)
     */
    if (name != null && name.length() > Short.MAX_VALUE)
      throw new IOException("Name of node exceeds maximum allowed size of " + Short.MAX_VALUE);
    if (children.size() > Short.MAX_VALUE)
      throw new IOException(
          "Number of subfolders in "
              + name
              + " exceeds maximum allowed number: "
              + Short.MAX_VALUE);

    oo.writeByte(serialVersion);
    if (name != null) {
      oo.writeByte(name.length());
      oo.writeBytes(name);
    } else {
      oo.writeByte(1);
      oo.writeByte(0);
    }
    oo.writeLong(size);
    oo.writeByte(children.size());
    for (FSTree child : children.values()) {
      child.writeExternal(oo);
    }
  }