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() . These examples are extracted from open source projects. 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 Project: flink   File: Record.java    License: 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 Project: flink   File: StringValueSerializer.java    License: 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 3
Source Project: flink   File: NFAStateSerializer.java    License: 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 4
Source Project: flink   File: StringValue.java    License: 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 5
Source Project: flink   File: StringValue.java    License: 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 6
@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 Project: flink   File: CoGroupedStreams.java    License: 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 8
Source Project: flink   File: NFAStateSerializer.java    License: 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 9
public static void writeVariableIntBytes(
	int value,
	DataOutputView keySerializationDateDataOutputView)
	throws IOException {
	do {
		keySerializationDateDataOutputView.writeByte(value);
		value >>>= 8;
	} while (value != 0);
}
 
Example 10
Source Project: flink   File: LocalDateSerializer.java    License: 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 11
Source Project: flink   File: ByteValueSerializer.java    License: 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 Project: Flink-CEPplus   File: Tuple0Serializer.java    License: 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 13
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	target.writeByte(source.readByte());
}
 
Example 14
Source Project: Flink-CEPplus   File: ByteSerializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Byte record, DataOutputView target) throws IOException {
	target.writeByte(record);
}
 
Example 15
Source Project: flink   File: UnsignedByteType.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeByte(this.value);
}
 
Example 16
@Override
public void serialize(VoidValue record, DataOutputView target) throws IOException {
	target.writeByte(1);
}
 
Example 17
Source Project: flink   File: ByteValue.java    License: 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 Project: flink   File: PojoSerializer.java    License: 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 19
Source Project: flink   File: ByteType.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeByte(this.value);
}
 
Example 20
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	source.readByte();
	target.writeByte(1);
}