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

The following examples show how to use org.apache.flink.core.memory.DataOutputView#writeBoolean() . 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: MapDataSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(MapData map, DataOutputView target) throws IOException {
	BinaryMapData binaryMap = toBinaryMap(map);
	final int size = binaryMap.size();
	target.writeInt(size);
	BinaryArrayData keyArray = binaryMap.keyArray();
	BinaryArrayData valueArray = binaryMap.valueArray();
	for (int i = 0; i < size; i++) {
		if (keyArray.isNullAt(i)) {
			throw new IllegalArgumentException("The key of BinaryMapData must not be null.");
		}
		Object key = ArrayData.get(keyArray, i, keyType);
		keyTypeSerializer.serialize(key, target);
		if (valueArray.isNullAt(i)) {
			target.writeBoolean(true);
		} else {
			target.writeBoolean(false);
			Object value = ArrayData.get(valueArray, i, valueType);
			valueTypeSerializer.serialize(value, target);
		}
	}
}
 
Example 2
Source File: NullAwareMapSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	final int size = source.readInt();
	target.writeInt(size);

	for (int i = 0; i < size; ++i) {
		boolean keyIsNull = source.readBoolean();
		target.writeBoolean(keyIsNull);
		if (!keyIsNull) {
			keySerializer.copy(source, target);
		}

		boolean valueIsNull = source.readBoolean();
		target.writeBoolean(valueIsNull);

		if (!valueIsNull) {
			valueSerializer.copy(source, target);
		}
	}
}
 
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: NullableSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(T record, DataOutputView target) throws IOException {
	if (record == null) {
		target.writeBoolean(true);
		target.write(padding);
	}
	else {
		target.writeBoolean(false);
		originalSerializer.serialize(record, target);
	}
}
 
Example 5
Source File: FlinkKafkaProducer.java    From flink 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 6
Source File: NullableSerializer.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 isNull = source.readBoolean();
	target.writeBoolean(isNull);
	if (isNull) {
		target.write(padding);
	}
	else {
		originalSerializer.copy(source, target);
	}
}
 
Example 7
Source File: GenericArraySerializer.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 len = source.readInt();
	target.writeInt(len);
	
	for (int i = 0; i < len; i++) {
		boolean isNonNull = source.readBoolean();
		target.writeBoolean(isNonNull);
		
		if (isNonNull) {
			componentSerializer.copy(source, target);
		}
	}
}
 
Example 8
Source File: KeyedBackendSerializationProxy.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	super.write(out);

	// write the compression format used to write each key-group
	out.writeBoolean(usingKeyGroupCompression);

	TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot(out, keySerializerSnapshot, keySerializer);

	// write individual registered keyed state metainfos
	out.writeShort(stateMetaInfoSnapshots.size());
	for (StateMetaInfoSnapshot metaInfoSnapshot : stateMetaInfoSnapshots) {
		StateMetaInfoSnapshotReadersWriters.getWriter().writeStateMetaInfoSnapshot(metaInfoSnapshot, out);
	}
}
 
Example 9
Source File: NullValue.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	source.readBoolean();
	target.writeBoolean(false);
}
 
Example 10
Source File: BooleanSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	target.writeBoolean(source.readBoolean());
}
 
Example 11
Source File: NullValue.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeBoolean(false);
}
 
Example 12
Source File: BooleanValue.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeBoolean(this.value);
}
 
Example 13
Source File: BooleanType.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeBoolean(this.value);
}
 
Example 14
Source File: BooleanSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	target.writeBoolean(source.readBoolean());
}
 
Example 15
Source File: CompositeSerializerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected void writeOuterSnapshot(DataOutputView out) throws IOException {
	out.writeBoolean(isImmutableTargetType);
}
 
Example 16
Source File: IntervalJoinOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(BufferEntry<T> record, DataOutputView target) throws IOException {
	target.writeBoolean(record.hasBeenJoined);
	elementSerializer.serialize(record.element, target);
}
 
Example 17
Source File: PojoSerializer.java    From Flink-CEPplus 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 18
Source File: BooleanValue.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeBoolean(this.value);
}
 
Example 19
Source File: BooleanValueSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	target.writeBoolean(source.readBoolean());
}
 
Example 20
Source File: StringUtils.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Writes a String to the given output. The string may be null.
 * The written string can be read with {@link #readNullableString(DataInputView)}-
 *
 * @param str The string to write, or null.
 * @param out The output to write to.
 *
 * @throws IOException Thrown, if the writing or the serialization fails.
 */
public static void writeNullableString(@Nullable String str, DataOutputView out) throws IOException {
	if (str != null) {
		out.writeBoolean(true);
		writeString(str, out);
	} else {
		out.writeBoolean(false);
	}
}