Java Code Examples for org.apache.flink.core.memory.DataOutputView#writeUTF()

The following examples show how to use org.apache.flink.core.memory.DataOutputView#writeUTF() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalTimerServiceSerializationProxy.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void write(DataOutputView out) throws IOException {
	super.write(out);
	final Map<String, InternalTimerServiceImpl<K, ?>> registeredTimerServices =
		timerServicesManager.getRegisteredTimerServices();

	out.writeInt(registeredTimerServices.size());
	for (Map.Entry<String, InternalTimerServiceImpl<K, ?>> entry : registeredTimerServices.entrySet()) {
		String serviceName = entry.getKey();
		InternalTimerServiceImpl<K, ?> timerService = entry.getValue();

		out.writeUTF(serviceName);
		InternalTimersSnapshotReaderWriters
			.getWriterForVersion(
				VERSION,
				timerService.snapshotTimersForKeyGroup(keyGroupIdx),
				timerService.getKeySerializer(),
				(TypeSerializer) timerService.getNamespaceSerializer())
			.writeTimersSnapshot(out);
	}
}
 
Example 2
Source File: KryoRegistrationSerializerConfigSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeUTF(kryoRegistration.getRegisteredClass().getName());

	final KryoRegistration.SerializerDefinitionType serializerDefinitionType = kryoRegistration.getSerializerDefinitionType();

	out.writeInt(serializerDefinitionType.ordinal());
	switch (serializerDefinitionType) {
		case UNSPECIFIED:
			// nothing else to write
			break;
		case CLASS:
			out.writeUTF(kryoRegistration.getSerializerClass().getName());
			break;
		case INSTANCE:
			try (final DataOutputViewStream outViewWrapper = new DataOutputViewStream(out)) {
				InstantiationUtil.serializeObject(outViewWrapper, kryoRegistration.getSerializableSerializerInstance());
			}
			break;
		default:
			// this should not happen; adding as a guard for the future
			throw new IllegalStateException(
					"Unrecognized Kryo registration serializer definition type: " + serializerDefinitionType);
	}
}
 
Example 3
Source File: TestType.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(TestType record, DataOutputView target) throws IOException {
	target.writeUTF(record.getKey());
	target.writeUTF(RANDOM_PAYLOAD);
	target.writeInt(record.getValue());
	target.writeBoolean(true);
}
 
Example 4
Source File: EnumSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void writeSnapshot(DataOutputView out) throws IOException {
	checkState(enumClass != null, "Enum class can not be null.");
	out.writeUTF(enumClass.getName());
	out.writeInt(previousEnums.length);
	for (T enumConstant : previousEnums) {
		out.writeUTF(enumConstant.name());
	}
}
 
Example 5
Source File: FlinkKafkaProducer011.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(
		DataInputView source,
		DataOutputView target) throws IOException {
	int numIds = source.readInt();
	target.writeInt(numIds);
	for (int i = 0; i < numIds; i++) {
		target.writeUTF(source.readUTF());
	}
}
 
Example 6
Source File: FlinkKafkaProducer011.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		KafkaTransactionContext record,
		DataOutputView target) throws IOException {
	int numIds = record.transactionalIds.size();
	target.writeInt(numIds);
	for (String id : record.transactionalIds) {
		target.writeUTF(id);
	}
}
 
Example 7
Source File: FlinkKafkaProducer011.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(
		DataInputView source, DataOutputView target) throws IOException {
	boolean hasTransactionalId = source.readBoolean();
	target.writeBoolean(hasTransactionalId);
	if (hasTransactionalId) {
		target.writeUTF(source.readUTF());
	}
	target.writeLong(source.readLong());
	target.writeShort(source.readShort());
}
 
Example 8
Source File: FlinkKafkaProducer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
	FlinkKafkaProducer.KafkaTransactionState record,
	DataOutputView target) throws IOException {
	if (record.transactionalId == null) {
		target.writeBoolean(false);
	} else {
		target.writeBoolean(true);
		target.writeUTF(record.transactionalId);
	}
	target.writeLong(record.producerId);
	target.writeShort(record.epoch);
}
 
Example 9
Source File: FlinkKafkaProducer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(
	DataInputView source, DataOutputView target) throws IOException {
	boolean hasTransactionalId = source.readBoolean();
	target.writeBoolean(hasTransactionalId);
	if (hasTransactionalId) {
		target.writeUTF(source.readUTF());
	}
	target.writeLong(source.readLong());
	target.writeShort(source.readShort());
}
 
Example 10
Source File: MessageTypeSerializer.java    From flink-statefun with Apache License 2.0 4 votes vote down vote up
@Override
public void writeSnapshot(DataOutputView dataOutputView) throws IOException {
  dataOutputView.writeUTF(messageFactoryType.name());
}
 
Example 11
Source File: PojoSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public void serialize(T value, DataOutputView target) throws IOException {
	int flags = 0;
	// handle null values
	if (value == null) {
		flags |= IS_NULL;
		target.writeByte(flags);
		return;
	}

	Integer subclassTag = -1;
	Class<?> actualClass = value.getClass();
	TypeSerializer subclassSerializer = null;
	if (clazz != actualClass) {
		subclassTag = registeredClasses.get(actualClass);
		if (subclassTag != null) {
			flags |= IS_TAGGED_SUBCLASS;
			subclassSerializer = registeredSerializers[subclassTag];
		} else {
			flags |= IS_SUBCLASS;
			subclassSerializer = getSubclassSerializer(actualClass);
		}
	} else {
		flags |= NO_SUBCLASS;
	}

	target.writeByte(flags);

	// if its a registered subclass, write the class tag id, otherwise write the full classname
	if ((flags & IS_SUBCLASS) != 0) {
		target.writeUTF(actualClass.getName());
	} else if ((flags & IS_TAGGED_SUBCLASS) != 0) {
		target.writeByte(subclassTag);
	}

	// if its a subclass, use the corresponding subclass serializer,
	// otherwise serialize each field with our field serializers
	if ((flags & NO_SUBCLASS) != 0) {
		try {
			for (int i = 0; i < numFields; i++) {
				Object o = (fields[i] != null) ? fields[i].get(value) : null;
				if (o == null) {
					target.writeBoolean(true); // null field handling
				} else {
					target.writeBoolean(false);
					fieldSerializers[i].serialize(o, target);
				}
			}
		} catch (IllegalAccessException e) {
			throw new RuntimeException("Error during POJO copy, this should not happen since we check the fields before.", e);
		}
	} else {
		// subclass
		if (subclassSerializer != null) {
			subclassSerializer.serialize(value, target);
		}
	}
}
 
Example 12
Source File: Tuple2CaseClassSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected void writeOuterSnapshot(DataOutputView out) throws IOException {
	checkState(type != null, "tuple class can not be NULL");
	out.writeUTF(type.getName());
}
 
Example 13
Source File: PojoSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	// copy the flags
	int flags = source.readByte();
	target.writeByte(flags);

	if ((flags & IS_NULL) != 0) {
		// is a null value, nothing further to copy
		return;
	}

	TypeSerializer<?> subclassSerializer = null;
	if ((flags & IS_SUBCLASS) != 0) {
		String className = source.readUTF();
		target.writeUTF(className);
		try {
			Class<?> subclass = Class.forName(className, true, Thread.currentThread()
					.getContextClassLoader());
			subclassSerializer = getSubclassSerializer(subclass);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException("Cannot instantiate class.", e);
		}
	} else if ((flags & IS_TAGGED_SUBCLASS) != 0) {
		int subclassTag = source.readByte();
		target.writeByte(subclassTag);
		subclassSerializer = registeredSerializers[subclassTag];
	}

	if ((flags & NO_SUBCLASS) != 0) {
		for (int i = 0; i < numFields; i++) {
			boolean isNull = source.readBoolean();
			target.writeBoolean(isNull);
			if (!isNull) {
				fieldSerializers[i].copy(source, target);
			}
		}
	} else {
		if (subclassSerializer != null) {
			subclassSerializer.copy(source, target);
		}
	}
}
 
Example 14
Source File: GenericArraySerializerConfigSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void writeSnapshot(DataOutputView out) throws IOException {
	checkState(componentClass != null && nestedSnapshot != null);
	out.writeUTF(componentClass.getName());
	nestedSnapshot.writeNestedSerializerSnapshots(out);
}
 
Example 15
Source File: ParameterlessTypeSerializerConfig.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	super.write(out);
	out.writeUTF(serializationFormatIdentifier);
}
 
Example 16
Source File: ValueSerializerMigrationTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeUTF(name);
}
 
Example 17
Source File: TupleSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected void writeOuterSnapshot(DataOutputView out) throws IOException {
	checkState(tupleClass != null, "tuple class can not be NULL");
	out.writeUTF(tupleClass.getName());
}
 
Example 18
Source File: PostVersionedIOReadableWritableTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	super.write(out);
	out.writeUTF(data);
}
 
Example 19
Source File: DelegatingConfiguration.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeUTF(this.prefix);
	this.backingConfig.write(out);
}
 
Example 20
Source File: PojoSerializerSnapshotData.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
void writeSnapshotData(DataOutputView out) throws IOException {
	out.writeUTF(pojoClass.getName());
	writeOptionalMap(out, fieldSerializerSnapshots, PojoFieldUtils::writeField, TypeSerializerSnapshot::writeVersionedSnapshot);
	writeOptionalMap(out, registeredSubclassSerializerSnapshots, NoOpWriter.noopWriter(), TypeSerializerSnapshot::writeVersionedSnapshot);
	writeOptionalMap(out, nonRegisteredSubclassSerializerSnapshots, NoOpWriter.noopWriter(), TypeSerializerSnapshot::writeVersionedSnapshot);
}