Java Code Examples for org.apache.flink.core.memory.DataOutputSerializer#length()

The following examples show how to use org.apache.flink.core.memory.DataOutputSerializer#length() . 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: StreamElementSerializerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T, X extends StreamElement> X serializeAndDeserialize(
		X record,
		StreamElementSerializer<T> serializer) throws IOException {

	DataOutputSerializer output = new DataOutputSerializer(32);
	serializer.serialize(record, output);

	// additional binary copy step
	DataInputDeserializer copyInput = new DataInputDeserializer(output.getByteArray(), 0, output.length());
	DataOutputSerializer copyOutput = new DataOutputSerializer(32);
	serializer.copy(copyInput, copyOutput);

	DataInputDeserializer input = new DataInputDeserializer(copyOutput.getByteArray(), 0, copyOutput.length());
	return (X) serializer.deserialize(input);
}
 
Example 2
Source File: StreamElementSerializerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T, X extends StreamElement> X serializeAndDeserialize(
		X record,
		StreamElementSerializer<T> serializer) throws IOException {

	DataOutputSerializer output = new DataOutputSerializer(32);
	serializer.serialize(record, output);

	// additional binary copy step
	DataInputDeserializer copyInput = new DataInputDeserializer(output.getByteArray(), 0, output.length());
	DataOutputSerializer copyOutput = new DataOutputSerializer(32);
	serializer.copy(copyInput, copyOutput);

	DataInputDeserializer input = new DataInputDeserializer(copyOutput.getByteArray(), 0, copyOutput.length());
	return (X) serializer.deserialize(input);
}
 
Example 3
Source File: StreamElementSerializerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T, X extends StreamElement> X serializeAndDeserialize(
		X record,
		StreamElementSerializer<T> serializer) throws IOException {

	DataOutputSerializer output = new DataOutputSerializer(32);
	serializer.serialize(record, output);

	// additional binary copy step
	DataInputDeserializer copyInput = new DataInputDeserializer(output.getByteArray(), 0, output.length());
	DataOutputSerializer copyOutput = new DataOutputSerializer(32);
	serializer.copy(copyInput, copyOutput);

	DataInputDeserializer input = new DataInputDeserializer(copyOutput.getByteArray(), 0, copyOutput.length());
	return (X) serializer.deserialize(input);
}
 
Example 4
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 5
Source File: RocksDBKeySerializationUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static <N> void writeNameSpace(
	N namespace,
	TypeSerializer<N> namespaceSerializer,
	DataOutputSerializer keySerializationDataOutputView,
	boolean ambiguousKeyPossible) throws IOException {

	int beforeWrite = keySerializationDataOutputView.length();
	namespaceSerializer.serialize(namespace, keySerializationDataOutputView);

	if (ambiguousKeyPossible) {
		//write length of namespace
		writeLengthFrom(beforeWrite, keySerializationDataOutputView);
	}
}
 
Example 6
Source File: RocksDBKeySerializationUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static <K> void writeKey(
	K key,
	TypeSerializer<K> keySerializer,
	DataOutputSerializer keySerializationDataOutputView,
	boolean ambiguousKeyPossible) throws IOException {
	//write key
	int beforeWrite = keySerializationDataOutputView.length();
	keySerializer.serialize(key, keySerializationDataOutputView);

	if (ambiguousKeyPossible) {
		//write size of key
		writeLengthFrom(beforeWrite, keySerializationDataOutputView);
	}
}
 
Example 7
Source File: LinkedOptionalMapSerializer.java    From flink 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: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <N> void writeNameSpace(
	N namespace,
	TypeSerializer<N> namespaceSerializer,
	DataOutputSerializer keySerializationDataOutputView,
	boolean ambiguousKeyPossible) throws IOException {

	int beforeWrite = keySerializationDataOutputView.length();
	namespaceSerializer.serialize(namespace, keySerializationDataOutputView);

	if (ambiguousKeyPossible) {
		//write length of namespace
		writeLengthFrom(beforeWrite, keySerializationDataOutputView);
	}
}
 
Example 9
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <K> void writeKey(
	K key,
	TypeSerializer<K> keySerializer,
	DataOutputSerializer keySerializationDataOutputView,
	boolean ambiguousKeyPossible) throws IOException {
	//write key
	int beforeWrite = keySerializationDataOutputView.length();
	keySerializer.serialize(key, keySerializationDataOutputView);

	if (ambiguousKeyPossible) {
		//write size of key
		writeLengthFrom(beforeWrite, keySerializationDataOutputView);
	}
}
 
Example 10
Source File: LinkedOptionalMapSerializer.java    From flink 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 11
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <N> void writeNameSpace(
	N namespace,
	TypeSerializer<N> namespaceSerializer,
	DataOutputSerializer keySerializationDataOutputView,
	boolean ambiguousKeyPossible) throws IOException {

	int beforeWrite = keySerializationDataOutputView.length();
	namespaceSerializer.serialize(namespace, keySerializationDataOutputView);

	if (ambiguousKeyPossible) {
		//write length of namespace
		writeLengthFrom(beforeWrite, keySerializationDataOutputView);
	}
}
 
Example 12
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <K> void writeKey(
	K key,
	TypeSerializer<K> keySerializer,
	DataOutputSerializer keySerializationDataOutputView,
	boolean ambiguousKeyPossible) throws IOException {
	//write key
	int beforeWrite = keySerializationDataOutputView.length();
	keySerializer.serialize(key, keySerializationDataOutputView);

	if (ambiguousKeyPossible) {
		//write size of key
		writeLengthFrom(beforeWrite, keySerializationDataOutputView);
	}
}
 
Example 13
Source File: RocksDBKeySerializationUtils.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static void writeLengthFrom(
	int fromPosition,
	DataOutputSerializer keySerializationDateDataOutputView) throws IOException {
	int length = keySerializationDateDataOutputView.length() - fromPosition;
	writeVariableIntBytes(length, keySerializationDateDataOutputView);
}
 
Example 14
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void writeLengthFrom(
	int fromPosition,
	DataOutputSerializer keySerializationDateDataOutputView) throws IOException {
	int length = keySerializationDateDataOutputView.length() - fromPosition;
	writeVariableIntBytes(length, keySerializationDateDataOutputView);
}
 
Example 15
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void writeLengthFrom(
	int fromPosition,
	DataOutputSerializer keySerializationDateDataOutputView) throws IOException {
	int length = keySerializationDateDataOutputView.length() - fromPosition;
	writeVariableIntBytes(length, keySerializationDateDataOutputView);
}