Beispiel #1
0
  public final void readFields(DataInput in) throws IOException {
    metadata.clear();
    int sizeOrVersion = in.readInt();
    if (sizeOrVersion < 0) { // version
      version = sizeOrVersion;
      switch (version) {
        case VERSION:
          url = Text.readString(in);
          base = Text.readString(in);

          content = new byte[in.readInt()];
          in.readFully(content);

          contentType = Text.readString(in);
          metadata.readFields(in);
          break;
        default:
          throw new VersionMismatchException((byte) VERSION, (byte) version);
      }
    } else { // size
      byte[] compressed = new byte[sizeOrVersion];
      in.readFully(compressed, 0, compressed.length);
      ByteArrayInputStream deflated = new ByteArrayInputStream(compressed);
      DataInput inflater = new DataInputStream(new InflaterInputStream(deflated));
      readFieldsCompressed(inflater);
    }
  }
Beispiel #2
0
  private final void readFieldsCompressed(DataInput in) throws IOException {
    byte oldVersion = in.readByte();
    switch (oldVersion) {
      case 0:
      case 1:
        url = UTF8.readString(in); // read url
        base = UTF8.readString(in); // read base

        content = new byte[in.readInt()]; // read content
        in.readFully(content);

        contentType = UTF8.readString(in); // read contentType
        // reconstruct metadata
        int keySize = in.readInt();
        String key;
        for (int i = 0; i < keySize; i++) {
          key = UTF8.readString(in);
          int valueSize = in.readInt();
          for (int j = 0; j < valueSize; j++) {
            metadata.add(key, UTF8.readString(in));
          }
        }
        break;
      case 2:
        url = Text.readString(in); // read url
        base = Text.readString(in); // read base

        content = new byte[in.readInt()]; // read content
        in.readFully(content);

        contentType = Text.readString(in); // read contentType
        metadata.readFields(in); // read meta data
        break;
      default:
        throw new VersionMismatchException((byte) 2, oldVersion);
    }
  }