homework/hw_2/hw_2_code/ex4/src/main/java/avro/AvroFile.java
/**
 * Autogenerated by Avro
 *
 * DO NOT EDIT DIRECTLY
 */
package avro;

import org.apache.avro.generic.GenericArray;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.util.Utf8;
import org.apache.avro.message.BinaryMessageEncoder;
import org.apache.avro.message.BinaryMessageDecoder;
import org.apache.avro.message.SchemaStore;

@org.apache.avro.specific.AvroGenerated
public class AvroFile extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
  private static final long serialVersionUID = 8379785950420437046L;


  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"AvroFile\",\"namespace\":\"avro\",\"fields\":[{\"name\":\"filename\",\"type\":\"string\"},{\"name\":\"filecontent\",\"type\":\"bytes\"},{\"name\":\"checksum\",\"type\":\"string\"}]}");
  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }

  private static final SpecificData MODEL$ = new SpecificData();

  private static final BinaryMessageEncoder<AvroFile> ENCODER =
      new BinaryMessageEncoder<AvroFile>(MODEL$, SCHEMA$);

  private static final BinaryMessageDecoder<AvroFile> DECODER =
      new BinaryMessageDecoder<AvroFile>(MODEL$, SCHEMA$);

  /**
   * Return the BinaryMessageEncoder instance used by this class.
   * @return the message encoder used by this class
   */
  public static BinaryMessageEncoder<AvroFile> getEncoder() {
    return ENCODER;
  }

  /**
   * Return the BinaryMessageDecoder instance used by this class.
   * @return the message decoder used by this class
   */
  public static BinaryMessageDecoder<AvroFile> getDecoder() {
    return DECODER;
  }

  /**
   * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
   * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
   * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore
   */
  public static BinaryMessageDecoder<AvroFile> createDecoder(SchemaStore resolver) {
    return new BinaryMessageDecoder<AvroFile>(MODEL$, SCHEMA$, resolver);
  }

  /**
   * Serializes this AvroFile to a ByteBuffer.
   * @return a buffer holding the serialized data for this instance
   * @throws java.io.IOException if this instance could not be serialized
   */
  public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
    return ENCODER.encode(this);
  }

  /**
   * Deserializes a AvroFile from a ByteBuffer.
   * @param b a byte buffer holding serialized data for an instance of this class
   * @return a AvroFile instance decoded from the given buffer
   * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class
   */
  public static AvroFile fromByteBuffer(
      java.nio.ByteBuffer b) throws java.io.IOException {
    return DECODER.decode(b);
  }

  private java.lang.CharSequence filename;
  private java.nio.ByteBuffer filecontent;
  private java.lang.CharSequence checksum;

  /**
   * Default constructor.  Note that this does not initialize fields
   * to their default values from the schema.  If that is desired then
   * one should use <code>newBuilder()</code>.
   */
  public AvroFile() {}

  /**
   * All-args constructor.
   * @param filename The new value for filename
   * @param filecontent The new value for filecontent
   * @param checksum The new value for checksum
   */
  public AvroFile(java.lang.CharSequence filename, java.nio.ByteBuffer filecontent, java.lang.CharSequence checksum) {
    this.filename = filename;
    this.filecontent = filecontent;
    this.checksum = checksum;
  }

  public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; }
  public org.apache.avro.Schema getSchema() { return SCHEMA$; }
  // Used by DatumWriter.  Applications should not call.
  public java.lang.Object get(int field$) {
    switch (field$) {
    case 0: return filename;
    case 1: return filecontent;
    case 2: return checksum;
    default: throw new IndexOutOfBoundsException("Invalid index: " + field$);
    }
  }

  // Used by DatumReader.  Applications should not call.
  @SuppressWarnings(value="unchecked")
  public void put(int field$, java.lang.Object value$) {
    switch (field$) {
    case 0: filename = (java.lang.CharSequence)value$; break;
    case 1: filecontent = (java.nio.ByteBuffer)value$; break;
    case 2: checksum = (java.lang.CharSequence)value$; break;
    default: throw new IndexOutOfBoundsException("Invalid index: " + field$);
    }
  }

  /**
   * Gets the value of the 'filename' field.
   * @return The value of the 'filename' field.
   */
  public java.lang.CharSequence getFilename() {
    return filename;
  }


  /**
   * Sets the value of the 'filename' field.
   * @param value the value to set.
   */
  public void setFilename(java.lang.CharSequence value) {
    this.filename = value;
  }

  /**
   * Gets the value of the 'filecontent' field.
   * @return The value of the 'filecontent' field.
   */
  public java.nio.ByteBuffer getFilecontent() {
    return filecontent;
  }


  /**
   * Sets the value of the 'filecontent' field.
   * @param value the value to set.
   */
  public void setFilecontent(java.nio.ByteBuffer value) {
    this.filecontent = value;
  }

  /**
   * Gets the value of the 'checksum' field.
   * @return The value of the 'checksum' field.
   */
  public java.lang.CharSequence getChecksum() {
    return checksum;
  }


  /**
   * Sets the value of the 'checksum' field.
   * @param value the value to set.
   */
  public void setChecksum(java.lang.CharSequence value) {
    this.checksum = value;
  }

  /**
   * Creates a new AvroFile RecordBuilder.
   * @return A new AvroFile RecordBuilder
   */
  public static avro.AvroFile.Builder newBuilder() {
    return new avro.AvroFile.Builder();
  }

  /**
   * Creates a new AvroFile RecordBuilder by copying an existing Builder.
   * @param other The existing builder to copy.
   * @return A new AvroFile RecordBuilder
   */
  public static avro.AvroFile.Builder newBuilder(avro.AvroFile.Builder other) {
    if (other == null) {
      return new avro.AvroFile.Builder();
    } else {
      return new avro.AvroFile.Builder(other);
    }
  }

  /**
   * Creates a new AvroFile RecordBuilder by copying an existing AvroFile instance.
   * @param other The existing instance to copy.
   * @return A new AvroFile RecordBuilder
   */
  public static avro.AvroFile.Builder newBuilder(avro.AvroFile other) {
    if (other == null) {
      return new avro.AvroFile.Builder();
    } else {
      return new avro.AvroFile.Builder(other);
    }
  }

  /**
   * RecordBuilder for AvroFile instances.
   */
  @org.apache.avro.specific.AvroGenerated
  public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<AvroFile>
    implements org.apache.avro.data.RecordBuilder<AvroFile> {

    private java.lang.CharSequence filename;
    private java.nio.ByteBuffer filecontent;
    private java.lang.CharSequence checksum;

    /** Creates a new Builder */
    private Builder() {
      super(SCHEMA$, MODEL$);
    }

    /**
     * Creates a Builder by copying an existing Builder.
     * @param other The existing Builder to copy.
     */
    private Builder(avro.AvroFile.Builder other) {
      super(other);
      if (isValidValue(fields()[0], other.filename)) {
        this.filename = data().deepCopy(fields()[0].schema(), other.filename);
        fieldSetFlags()[0] = other.fieldSetFlags()[0];
      }
      if (isValidValue(fields()[1], other.filecontent)) {
        this.filecontent = data().deepCopy(fields()[1].schema(), other.filecontent);
        fieldSetFlags()[1] = other.fieldSetFlags()[1];
      }
      if (isValidValue(fields()[2], other.checksum)) {
        this.checksum = data().deepCopy(fields()[2].schema(), other.checksum);
        fieldSetFlags()[2] = other.fieldSetFlags()[2];
      }
    }

    /**
     * Creates a Builder by copying an existing AvroFile instance
     * @param other The existing instance to copy.
     */
    private Builder(avro.AvroFile other) {
      super(SCHEMA$, MODEL$);
      if (isValidValue(fields()[0], other.filename)) {
        this.filename = data().deepCopy(fields()[0].schema(), other.filename);
        fieldSetFlags()[0] = true;
      }
      if (isValidValue(fields()[1], other.filecontent)) {
        this.filecontent = data().deepCopy(fields()[1].schema(), other.filecontent);
        fieldSetFlags()[1] = true;
      }
      if (isValidValue(fields()[2], other.checksum)) {
        this.checksum = data().deepCopy(fields()[2].schema(), other.checksum);
        fieldSetFlags()[2] = true;
      }
    }

    /**
      * Gets the value of the 'filename' field.
      * @return The value.
      */
    public java.lang.CharSequence getFilename() {
      return filename;
    }


    /**
      * Sets the value of the 'filename' field.
      * @param value The value of 'filename'.
      * @return This builder.
      */
    public avro.AvroFile.Builder setFilename(java.lang.CharSequence value) {
      validate(fields()[0], value);
      this.filename = value;
      fieldSetFlags()[0] = true;
      return this;
    }

    /**
      * Checks whether the 'filename' field has been set.
      * @return True if the 'filename' field has been set, false otherwise.
      */
    public boolean hasFilename() {
      return fieldSetFlags()[0];
    }


    /**
      * Clears the value of the 'filename' field.
      * @return This builder.
      */
    public avro.AvroFile.Builder clearFilename() {
      filename = null;
      fieldSetFlags()[0] = false;
      return this;
    }

    /**
      * Gets the value of the 'filecontent' field.
      * @return The value.
      */
    public java.nio.ByteBuffer getFilecontent() {
      return filecontent;
    }


    /**
      * Sets the value of the 'filecontent' field.
      * @param value The value of 'filecontent'.
      * @return This builder.
      */
    public avro.AvroFile.Builder setFilecontent(java.nio.ByteBuffer value) {
      validate(fields()[1], value);
      this.filecontent = value;
      fieldSetFlags()[1] = true;
      return this;
    }

    /**
      * Checks whether the 'filecontent' field has been set.
      * @return True if the 'filecontent' field has been set, false otherwise.
      */
    public boolean hasFilecontent() {
      return fieldSetFlags()[1];
    }


    /**
      * Clears the value of the 'filecontent' field.
      * @return This builder.
      */
    public avro.AvroFile.Builder clearFilecontent() {
      filecontent = null;
      fieldSetFlags()[1] = false;
      return this;
    }

    /**
      * Gets the value of the 'checksum' field.
      * @return The value.
      */
    public java.lang.CharSequence getChecksum() {
      return checksum;
    }


    /**
      * Sets the value of the 'checksum' field.
      * @param value The value of 'checksum'.
      * @return This builder.
      */
    public avro.AvroFile.Builder setChecksum(java.lang.CharSequence value) {
      validate(fields()[2], value);
      this.checksum = value;
      fieldSetFlags()[2] = true;
      return this;
    }

    /**
      * Checks whether the 'checksum' field has been set.
      * @return True if the 'checksum' field has been set, false otherwise.
      */
    public boolean hasChecksum() {
      return fieldSetFlags()[2];
    }


    /**
      * Clears the value of the 'checksum' field.
      * @return This builder.
      */
    public avro.AvroFile.Builder clearChecksum() {
      checksum = null;
      fieldSetFlags()[2] = false;
      return this;
    }

    @Override
    @SuppressWarnings("unchecked")
    public AvroFile build() {
      try {
        AvroFile record = new AvroFile();
        record.filename = fieldSetFlags()[0] ? this.filename : (java.lang.CharSequence) defaultValue(fields()[0]);
        record.filecontent = fieldSetFlags()[1] ? this.filecontent : (java.nio.ByteBuffer) defaultValue(fields()[1]);
        record.checksum = fieldSetFlags()[2] ? this.checksum : (java.lang.CharSequence) defaultValue(fields()[2]);
        return record;
      } catch (org.apache.avro.AvroMissingFieldException e) {
        throw e;
      } catch (java.lang.Exception e) {
        throw new org.apache.avro.AvroRuntimeException(e);
      }
    }
  }

  @SuppressWarnings("unchecked")
  private static final org.apache.avro.io.DatumWriter<AvroFile>
    WRITER$ = (org.apache.avro.io.DatumWriter<AvroFile>)MODEL$.createDatumWriter(SCHEMA$);

  @Override public void writeExternal(java.io.ObjectOutput out)
    throws java.io.IOException {
    WRITER$.write(this, SpecificData.getEncoder(out));
  }

  @SuppressWarnings("unchecked")
  private static final org.apache.avro.io.DatumReader<AvroFile>
    READER$ = (org.apache.avro.io.DatumReader<AvroFile>)MODEL$.createDatumReader(SCHEMA$);

  @Override public void readExternal(java.io.ObjectInput in)
    throws java.io.IOException {
    READER$.read(this, SpecificData.getDecoder(in));
  }

  @Override protected boolean hasCustomCoders() { return true; }

  @Override public void customEncode(org.apache.avro.io.Encoder out)
    throws java.io.IOException
  {
    out.writeString(this.filename);

    out.writeBytes(this.filecontent);

    out.writeString(this.checksum);

  }

  @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
    throws java.io.IOException
  {
    org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
    if (fieldOrder == null) {
      this.filename = in.readString(this.filename instanceof Utf8 ? (Utf8)this.filename : null);

      this.filecontent = in.readBytes(this.filecontent);

      this.checksum = in.readString(this.checksum instanceof Utf8 ? (Utf8)this.checksum : null);

    } else {
      for (int i = 0; i < 3; i++) {
        switch (fieldOrder[i].pos()) {
        case 0:
          this.filename = in.readString(this.filename instanceof Utf8 ? (Utf8)this.filename : null);
          break;

        case 1:
          this.filecontent = in.readBytes(this.filecontent);
          break;

        case 2:
          this.checksum = in.readString(this.checksum instanceof Utf8 ? (Utf8)this.checksum : null);
          break;

        default:
          throw new java.io.IOException("Corrupt ResolvingDecoder.");
        }
      }
    }
  }
}










