Exemplo n.º 1
0
 public void readFields(DataInput in) throws IOException {
   // instance-specific
   this.sampleStrs = new ArrayList<String>();
   int numSamples = in.readInt();
   for (int i = 0; i < numSamples; i++) {
     sampleStrs.add(UTF8.readString(in).toString());
   }
   this.tokenClassIdentifier = in.readInt();
   if (in.readBoolean()) {
     this.tokenParameter = UTF8.readString(in);
   } else {
     this.tokenParameter = null;
   }
   this.schema = computeAvroSchema();
 }
Exemplo n.º 2
0
 public void readFields(DataInput in) throws IOException {
   int numUnionElts = in.readInt();
   this.unionTypes = new ArrayList<InferredType>();
   for (int i = 0; i < numUnionElts; i++) {
     unionTypes.add(InferredType.readType(in));
   }
   this.schema = computeAvroSchema();
 }
Exemplo n.º 3
0
 /** Deserialize an unknown InferredType from the given input stream */
 public static InferredType readType(DataInput in) throws IOException {
   InferredType it = null;
   byte b = in.readByte();
   String name = in.readUTF();
   if (b == BASE_TYPE) {
     it = new BaseType(name);
   } else if (b == STRUCT_TYPE) {
     it = new StructType(name);
   } else if (b == ARRAY_TYPE) {
     it = new ArrayType(name);
   } else if (b == UNION_TYPE) {
     it = new UnionType(name);
   } else {
     throw new IOException("No type found: " + b);
   }
   it.readFields(in);
   return it;
 }
  /**
   * Reads a primitive value of the specified class type from the stream.
   *
   * @param in A stream to read from.
   * @param cls A class type of the primitive.
   * @return A primitive.
   * @throws IOException If an I/O error occurs.
   */
  static Object readPrimitive(DataInput in, Class cls) throws IOException {
    if (cls == byte.class) return in.readByte();

    if (cls == short.class) return in.readShort();

    if (cls == int.class) return in.readInt();

    if (cls == long.class) return in.readLong();

    if (cls == float.class) return in.readFloat();

    if (cls == double.class) return in.readDouble();

    if (cls == boolean.class) return in.readBoolean();

    if (cls == char.class) return in.readChar();

    throw new IllegalArgumentException();
  }