package org.apache.flink.api.java.typeutils.runtime.generated; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; import org.apache.flink.api.common.ExecutionConfig; import org.apache.flink.api.common.typeinfo.TypeInformation; import org.apache.flink.api.common.typeutils.TypeSerializer; import org.apache.flink.api.java.typeutils.TypeExtractor; import org.apache.flink.core.memory.DataInputView; import org.apache.flink.core.memory.DataOutputView; import static org.apache.flink.util.Preconditions.checkNotNull; public class Word_GeneratedSerializer extends TypeSerializer { private static byte IS_NULL = 1; private static byte NO_SUBCLASS = 2; private static byte IS_SUBCLASS = 4; private static byte IS_TAGGED_SUBCLASS = 8; private static final long serialVersionUID = 1L; private int numFields; private transient Field[] fields; private ExecutionConfig executionConfig; private transient Map, TypeSerializer> subclassSerializerCache; private transient ClassLoader cl; Class clazz; final org.apache.flink.api.common.typeutils.base.IntSerializer f0; final org.apache.flink.api.common.typeutils.base.StringSerializer f1; public Word_GeneratedSerializer(Class clazz, TypeSerializer[] serializerFields, Field[] reflectiveFields, ExecutionConfig e) { this.clazz = clazz; executionConfig = e; cl = Thread.currentThread().getContextClassLoader(); this.numFields = reflectiveFields.length; this.fields = reflectiveFields; f0 = (org.apache.flink.api.common.typeutils.base.IntSerializer)serializerFields[0]; f1 = (org.apache.flink.api.common.typeutils.base.StringSerializer)serializerFields[1]; for (int i = 0; i < numFields; i++) { this.fields[i].setAccessible(true); } } public boolean isImmutableType() { return false; } private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(fields.length); for (Field field: fields) { out.writeObject(field.getDeclaringClass()); out.writeUTF(field.getName()); } } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { cl = Thread.currentThread().getContextClassLoader(); in.defaultReadObject(); int numFields = in.readInt(); fields = new Field[numFields]; for (int i = 0; i < numFields; i++) { Class clazz = (Class)in.readObject(); String fieldName = in.readUTF(); fields[i] = null; while(clazz != null) { try { fields[i] = clazz.getDeclaredField(fieldName); fields[i].setAccessible(true); break; } catch (NoSuchFieldException e) { clazz = clazz.getSuperclass(); } } } } public Word_GeneratedSerializer duplicate() { return this; } public org.apache.flink.examples.java.wordcount.WordCountPojo.Word createInstance() { if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { return null; } try { org.apache.flink.examples.java.wordcount.WordCountPojo.Word t = (org.apache.flink.examples.java.wordcount.WordCountPojo.Word)clazz.newInstance(); fields[0].set(t, f0.createInstance()); fields[1].set(t, f1.createInstance()); return t; } catch (Exception e) { throw new RuntimeException("Cannot instantiate class.", e); } } public org.apache.flink.examples.java.wordcount.WordCountPojo.Word copy(Object from) { if (from == null) return null; Class actualType = from.getClass(); org.apache.flink.examples.java.wordcount.WordCountPojo.Word target; try { target = (org.apache.flink.examples.java.wordcount.WordCountPojo.Word) from.getClass().newInstance(); } catch (Throwable t) { throw new RuntimeException("Cannot instantiate class.", t); } try { Object value; value = fields[0].get(from); if (value != null) { fields[0].set(target, f0.copy(value)); } else { fields[0].set(target, null); } value = fields[1].get(from); if (value != null) { fields[1].set(target, f1.copy(value)); } else { fields[1].set(target, null); } } catch (IllegalAccessException e) { throw new RuntimeException("Error during POJO copy."); } return target; } public org.apache.flink.examples.java.wordcount.WordCountPojo.Word copy(Object from, Object resuse) { if (from == null) return null; return copy(from); } public int getLength() { return -1; } public void serialize(Object value, DataOutputView target) throws IOException { int flags = 0; if (value == null) { flags |= IS_NULL; target.writeByte(flags); return; } Integer subclassTag = -1; Class actualClass = value.getClass(); TypeSerializer subclassSerializer = null; if (clazz != actualClass) { // TODO } else { flags |= NO_SUBCLASS; } target.writeByte(flags); if ((flags & IS_SUBCLASS) != 0) { target.writeUTF(actualClass.getName()); } else if ((flags & IS_TAGGED_SUBCLASS) != 0) { target.writeByte(subclassTag); } if ((flags & NO_SUBCLASS) != 0) { try { Object o; o = fields[0].get(value); if (o == null) { target.writeBoolean(true); } else { target.writeBoolean(false); f0.serialize(o, target); } o = fields[1].get(value); if (o == null) { target.writeBoolean(true); } else { target.writeBoolean(false); f1.serialize(o, target); } } catch (IllegalAccessException e) { throw new RuntimeException("Error during POJO copy, this should" + "not happen since we check the fields before."); } } else { // TOOD } } public org.apache.flink.examples.java.wordcount.WordCountPojo.Word deserialize(DataInputView source) throws IOException { int flags = source.readByte(); if((flags & IS_NULL) != 0) { return null; } org.apache.flink.examples.java.wordcount.WordCountPojo.Word target = null; if ((flags & IS_SUBCLASS) != 0) { // TODO } else if ((flags & IS_TAGGED_SUBCLASS) != 0) { // TODO } else { target = createInstance(); } if ((flags & NO_SUBCLASS) != 0) { try { boolean isNull; isNull = source.readBoolean(); if (isNull) { fields[0].set(target, null); } else { fields[0].set(target, f0.deserialize(source)); } isNull = source.readBoolean(); if (isNull) { fields[1].set(target, null); } else { fields[1].set(target, f1.deserialize(source)); } } catch (IllegalAccessException e) { throw new RuntimeException("Error during POJO copy, this should not happen" + "since we check the fieldsbefore."); } } else { //TODO } return target; } public org.apache.flink.examples.java.wordcount.WordCountPojo.Word deserialize(Object reuse, DataInputView source) throws IOException { return deserialize(source); } public void copy(DataInputView source, DataOutputView target) throws IOException { int flags = source.readByte(); target.writeByte(flags); if ((flags & IS_NULL) != 0) { return; } if ((flags & IS_SUBCLASS) != 0) { // TODO } else if ((flags & IS_TAGGED_SUBCLASS) != 0) { // TODO } if ((flags & NO_SUBCLASS) != 0) { boolean isNull; isNull = source.readBoolean(); target.writeBoolean(isNull); if (!isNull) { f0.copy(source, target); } isNull = source.readBoolean(); target.writeBoolean(isNull); if (!isNull) { f1.copy(source, target); } } else { // TODO } } public boolean equals(Object obj) { if (obj instanceof Word_GeneratedSerializer) { Word_GeneratedSerializer other = (Word_GeneratedSerializer)obj; return other.canEqual(this) && this.clazz == other.clazz && this.numFields == other.numFields && Objects.equals(this.f0, other.f0) && Objects.equals(this.f1, other.f1) ; } else { return false; } } public boolean canEqual(Object obj) { return obj instanceof Word_GeneratedSerializer; } public int hashCode() { return Objects.hash(clazz, numFields, f0, f1); } }