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

The following examples show how to use org.apache.flink.core.memory.DataOutputView#writeByte() . 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: Record.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	int val = source.readUnsignedByte();
	target.writeByte(val);
	
	if (val >= MAX_BIT) {
		int shift = 7;
		int curr;
		val = val & 0x7f;
		while ((curr = source.readUnsignedByte()) >= MAX_BIT) {
			target.writeByte(curr);
			val |= (curr & 0x7f) << shift;
			shift += 7;
		}
		target.writeByte(curr);
		val |= curr << shift;
	}
	
	target.write(source, val);
}
 
Example 2
Source File: LocalDateSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(LocalDate record, DataOutputView target) throws IOException {
	if (record == null) {
		target.writeInt(Integer.MIN_VALUE);
		target.writeShort(Short.MIN_VALUE);
	} else {
		target.writeInt(record.getYear());
		target.writeByte(record.getMonthValue());
		target.writeByte(record.getDayOfMonth());
	}
}
 
Example 3
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static void writeVariableIntBytes(
	int value,
	DataOutputView keySerializationDateDataOutputView)
	throws IOException {
	do {
		keySerializationDateDataOutputView.writeByte(value);
		value >>>= 8;
	} while (value != 0);
}
 
Example 4
Source File: NFAStateSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
private void copyStartEvent(DataInputView source, DataOutputView target) throws IOException {
	byte isNull = source.readByte();
	target.writeByte(isNull);

	if (isNull == 1) {
		EventId startEventId = eventIdSerializer.deserialize(source);
		eventIdSerializer.serialize(startEventId, target);
	}
}
 
Example 5
Source File: CoGroupedStreams.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	byte tag = source.readByte();
	target.writeByte(tag);
	if (tag == 1) {
		oneSerializer.copy(source, target);
	} else {
		twoSerializer.copy(source, target);
	}
}
 
Example 6
Source File: StringValueSerializer.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 {
	int len = source.readUnsignedByte();
	target.writeByte(len);

	if (len >= HIGH_BIT) {
		int shift = 7;
		int curr;
		len = len & 0x7f;
		while ((curr = source.readUnsignedByte()) >= HIGH_BIT) {
			target.writeByte(curr);
			len |= (curr & 0x7f) << shift;
			shift += 7;
		}
		target.writeByte(curr);
		len |= curr << shift;
	}

	for (int i = 0; i < len; i++) {
		int c = source.readUnsignedByte();
		target.writeByte(c);
		while (c >= HIGH_BIT) {
			c = source.readUnsignedByte();
			target.writeByte(c);
		}
	}
}
 
Example 7
Source File: StringValue.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(DataInputView in, DataOutputView target) throws IOException {
	int len = in.readUnsignedByte();
	target.writeByte(len);

	if (len >= HIGH_BIT) {
		int shift = 7;
		int curr;
		len = len & 0x7f;
		while ((curr = in.readUnsignedByte()) >= HIGH_BIT) {
			len |= (curr & 0x7f) << shift;
			shift += 7;
			target.writeByte(curr);
		}
		len |= curr << shift;
		target.writeByte(curr);
	}

	for (int i = 0; i < len; i++) {
		int c = in.readUnsignedByte();
		target.writeByte(c);
		while (c >= HIGH_BIT) {
			c = in.readUnsignedByte();
			target.writeByte(c);
		}
	}
}
 
Example 8
Source File: StringValue.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(DataInputView in, DataOutputView target) throws IOException {
	int len = in.readUnsignedByte();
	target.writeByte(len);

	if (len >= HIGH_BIT) {
		int shift = 7;
		int curr;
		len = len & 0x7f;
		while ((curr = in.readUnsignedByte()) >= HIGH_BIT) {
			len |= (curr & 0x7f) << shift;
			shift += 7;
			target.writeByte(curr);
		}
		len |= curr << shift;
		target.writeByte(curr);
	}

	for (int i = 0; i < len; i++) {
		int c = in.readUnsignedByte();
		target.writeByte(c);
		while (c >= HIGH_BIT) {
			c = in.readUnsignedByte();
			target.writeByte(c);
		}
	}
}
 
Example 9
Source File: NFAStateSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
private void serializeStartEvent(EventId startEventID, DataOutputView target) throws IOException {
	if (startEventID != null) {
		target.writeByte(1);
		eventIdSerializer.serialize(startEventID, target);
	} else {
		target.writeByte(0);
	}
}
 
Example 10
Source File: StringValueSerializer.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.readUnsignedByte();
	target.writeByte(len);

	if (len >= HIGH_BIT) {
		int shift = 7;
		int curr;
		len = len & 0x7f;
		while ((curr = source.readUnsignedByte()) >= HIGH_BIT) {
			target.writeByte(curr);
			len |= (curr & 0x7f) << shift;
			shift += 7;
		}
		target.writeByte(curr);
		len |= curr << shift;
	}

	for (int i = 0; i < len; i++) {
		int c = source.readUnsignedByte();
		target.writeByte(c);
		while (c >= HIGH_BIT) {
			c = source.readUnsignedByte();
			target.writeByte(c);
		}
	}
}
 
Example 11
Source File: ByteValueSerializer.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.writeByte(source.readByte());
}
 
Example 12
Source File: ByteSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Byte record, DataOutputView target) throws IOException {
	target.writeByte(record);
}
 
Example 13
Source File: UnsignedByteType.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeByte(this.value);
}
 
Example 14
Source File: VoidCoderTypeSerializer.java    From flink-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(VoidValue record, DataOutputView target) throws IOException {
	target.writeByte(1);
}
 
Example 15
Source File: ByteValue.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeByte(this.value);
}
 
Example 16
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 17
Source File: ByteType.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeByte(this.value);
}
 
Example 18
Source File: Tuple0Serializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Tuple0 record, DataOutputView target) throws IOException {
	Preconditions.checkNotNull(record);
	target.writeByte(42);
}
 
Example 19
Source File: VoidCoderTypeSerializer.java    From flink-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	source.readByte();
	target.writeByte(1);
}
 
Example 20
Source File: ByteValueSerializer.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.writeByte(source.readByte());
}