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

The following examples show how to use org.apache.flink.core.memory.DataOutputView#writeInt() . 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: TwoPhaseCommitSinkFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void copy(
		DataInputView source, DataOutputView target) throws IOException {
	TXN pendingTxnHandle = transactionSerializer.deserialize(source);
	transactionSerializer.serialize(pendingTxnHandle, target);
	final long pendingTxnStartTime = source.readLong();
	target.writeLong(pendingTxnStartTime);

	int numPendingCommitTxns = source.readInt();
	target.writeInt(numPendingCommitTxns);
	for (int i = 0; i < numPendingCommitTxns; i++) {
		TXN pendingCommitTxnHandle = transactionSerializer.deserialize(source);
		transactionSerializer.serialize(pendingCommitTxnHandle, target);
		final long pendingCommitTxnStartTime = source.readLong();
		target.writeLong(pendingCommitTxnStartTime);
	}

	boolean hasContext = source.readBoolean();
	target.writeBoolean(hasContext);
	if (hasContext) {
		CONTEXT context = contextSerializer.deserialize(source);
		contextSerializer.serialize(context, target);
	}
}
 
Example 2
Source File: NullAwareMapSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Map<K, V> map, DataOutputView target) throws IOException {
	final int size = map.size();
	target.writeInt(size);

	for (Map.Entry<K, V> entry : map.entrySet()) {
		if (entry.getKey() == null) {
			target.writeBoolean(true);
		} else {
			target.writeBoolean(false);
			keySerializer.serialize(entry.getKey(), target);
		}

		if (entry.getValue() == null) {
			target.writeBoolean(true);
		} else {
			target.writeBoolean(false);
			valueSerializer.serialize(entry.getValue(), target);
		}
	}
}
 
Example 3
Source File: NestedMapsStateTable.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation note: we currently chose the same format between {@link NestedMapsStateTable} and
 * {@link CopyOnWriteStateTable}.
 *
 * <p>{@link NestedMapsStateTable} could naturally support a kind of
 * prefix-compressed format (grouping by namespace, writing the namespace only once per group instead for each
 * mapping). We might implement support for different formats later (tailored towards different state table
 * implementations).
 */
@Override
public void writeStateInKeyGroup(@Nonnull DataOutputView dov, int keyGroupId) throws IOException {
	final Map<N, Map<K, S>> keyGroupMap = owningStateTable.getMapForKeyGroup(keyGroupId);
	if (null != keyGroupMap) {
		Map<N, Map<K, S>> filteredMappings = filterMappingsInKeyGroupIfNeeded(keyGroupMap);
		dov.writeInt(countMappingsInKeyGroup(filteredMappings));
		for (Map.Entry<N, Map<K, S>> namespaceEntry : filteredMappings.entrySet()) {
			final N namespace = namespaceEntry.getKey();
			final Map<K, S> namespaceMap = namespaceEntry.getValue();
			for (Map.Entry<K, S> keyEntry : namespaceMap.entrySet()) {
				writeElement(namespace, keyEntry, dov);
			}
		}
	} else {
		dov.writeInt(0);
	}
}
 
Example 4
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 5
Source File: FloatValueArray.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeInt(position);

	for (int i = 0; i < position; i++) {
		out.writeFloat(data[i]);
	}
}
 
Example 6
Source File: ArrayListSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ArrayList<T> list, DataOutputView target) throws IOException {
	final int size = list.size();
	target.writeInt(size);
	for (int i = 0; i < size; i++) {
		elementSerializer.serialize(list.get(i), target);
	}
}
 
Example 7
Source File: LinkedOptionalMapSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static <T> void writeFramed(DataOutputView out, BiConsumerWithException<DataOutputView, T, IOException> writer, T item) throws IOException {
	DataOutputSerializer frame = new DataOutputSerializer(64);
	writer.accept(frame, item);

	final byte[] buffer = frame.getSharedBuffer();
	final int bufferSize = frame.length();
	out.writeInt(bufferSize);
	out.write(buffer, 0, bufferSize);
}
 
Example 8
Source File: BigIntSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static boolean copyBigInteger(DataInputView source, DataOutputView target) throws IOException {
	final int len = source.readInt();
	target.writeInt(len);
	if (len > 4) {
		target.write(source, len - 4);
	}
	return len == 0; // returns true if the copied record was null
}
 
Example 9
Source File: IntPrimitiveArraySerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(int[] record, DataOutputView target) throws IOException {
	if (record == null) {
		throw new IllegalArgumentException("The record must not be null.");
	}
	
	final int len = record.length;
	target.writeInt(len);
	for (int i = 0; i < len; i++) {
		target.writeInt(record[i]);
	}
}
 
Example 10
Source File: EncodedValueSerializer.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(byte[] record, DataOutputView target) throws IOException {
  if (record == null) {
    throw new IllegalArgumentException("The record must not be null.");
  }

  final int len = record.length;
  target.writeInt(len);
  target.write(record);
}
 
Example 11
Source File: ProtobufSerializer.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
public void serialize(M record, DataOutputView target) throws IOException {
  final int size = record.getSerializedSize();
  target.writeInt(size);

  output.set(target);
  try {
    record.writeTo(output);
  } finally {
    output.done();
  }
}
 
Example 12
Source File: StringArraySerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	final int len = source.readInt();
	target.writeInt(len);
	
	for (int i = 0; i < len; i++) {
		StringValue.copyString(source, target);
	}
}
 
Example 13
Source File: BytePrimitiveArraySerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	final int len = source.readInt();
	target.writeInt(len);
	target.write(source, len);
}
 
Example 14
Source File: StringDataSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	int length = source.readInt();
	target.writeInt(length);
	target.write(source, length);
}
 
Example 15
Source File: EnumSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(T record, DataOutputView target) throws IOException {
	// use our own maintained ordinals instead of the actual enum ordinal
	target.writeInt(valueToOrdinal.get(record));
}
 
Example 16
Source File: IntType.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeInt(this.value);
}
 
Example 17
Source File: EventId.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(EventId record, DataOutputView target) throws IOException {
	target.writeInt(record.id);
	target.writeLong(record.timestamp);
}
 
Example 18
Source File: IntegerTaskEvent.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void write(final DataOutputView out) throws IOException {
	out.writeInt(this.value);
}
 
Example 19
Source File: CustomIntSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Integer record, DataOutputView target) throws IOException {
	target.writeInt(MAGIC_VALUE);
	target.writeInt(record);
}
 
Example 20
Source File: IntType.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	out.writeInt(this.value);
}