Exemplo n.º 1
0
  @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);
    }
  }
Exemplo n.º 2
0
 public void writeString(final String s) throws IOException {
   final ObjectOutput out = this.out;
   if (s != null) {
     final int cn = s.length();
     ASCII:
     if (cn <= BA_LENGTH) {
       for (int ci = 0; ci < cn; ) {
         if ((s.charAt(ci++) & 0xffffff00) != 0) {
           break ASCII;
         }
       }
       if (cn <= 8) {
         out.writeInt(-cn);
         out.writeBytes(s);
         return;
       } else {
         out.writeInt(-cn);
         s.getBytes(0, cn, this.ba, 0);
         out.write(this.ba, 0, cn);
         return;
       }
     }
     out.writeInt(cn);
     out.writeChars(s);
     return;
   } else {
     out.writeInt(Integer.MIN_VALUE);
     return;
   }
 }
Exemplo n.º 3
0
 public void writeBytes(String s) throws IOException {
   oo.writeBytes(s);
 }