use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.
the class TypeSerializerUpgradeTestBase method readAndThenWriteData.
private static <T> DataInputView readAndThenWriteData(DataInputView originalDataInput, TypeSerializer<T> readSerializer, TypeSerializer<T> writeSerializer, Matcher<T> testDataMatcher) throws IOException {
T data = readSerializer.deserialize(originalDataInput);
assertThat(data, testDataMatcher);
DataOutputSerializer out = new DataOutputSerializer(INITIAL_OUTPUT_BUFFER_SIZE);
writeSerializer.serialize(data, out);
return new DataInputDeserializer(out.wrapAsByteBuffer());
}
use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.
the class TypeSerializerUpgradeTestBase method writeAndThenReadSerializerSnapshot.
private static <T> TypeSerializerSnapshot<T> writeAndThenReadSerializerSnapshot(TypeSerializer<T> serializer) throws IOException {
DataOutputSerializer out = new DataOutputSerializer(INITIAL_OUTPUT_BUFFER_SIZE);
writeSerializerSnapshotCurrentFormat(out, serializer);
DataInputDeserializer in = new DataInputDeserializer(out.wrapAsByteBuffer());
return readSerializerSnapshotCurrentFormat(in, Thread.currentThread().getContextClassLoader());
}
use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.
the class KvStateSerializer method deserializeKeyAndNamespace.
/**
* Deserializes the key and namespace into a {@link Tuple2}.
*
* @param serializedKeyAndNamespace Serialized key and namespace
* @param keySerializer Serializer for the key
* @param namespaceSerializer Serializer for the namespace
* @param <K> Key type
* @param <N> Namespace
* @return Tuple2 holding deserialized key and namespace
* @throws IOException if the deserialization fails for any reason
*/
public static <K, N> Tuple2<K, N> deserializeKeyAndNamespace(byte[] serializedKeyAndNamespace, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer) throws IOException {
DataInputDeserializer dis = new DataInputDeserializer(serializedKeyAndNamespace, 0, serializedKeyAndNamespace.length);
try {
K key = keySerializer.deserialize(dis);
byte magicNumber = dis.readByte();
if (magicNumber != MAGIC_NUMBER) {
throw new IOException("Unexpected magic number " + magicNumber + ".");
}
N namespace = namespaceSerializer.deserialize(dis);
if (dis.available() > 0) {
throw new IOException("Unconsumed bytes in the serialized key and namespace.");
}
return new Tuple2<>(key, namespace);
} catch (IOException e) {
throw new IOException("Unable to deserialize key " + "and namespace. This indicates a mismatch in the key/namespace " + "serializers used by the KvState instance and this access.", e);
}
}
use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.
the class KvStateSerializer method deserializeValue.
/**
* Deserializes the value with the given serializer.
*
* @param serializedValue Serialized value of type T
* @param serializer Serializer for T
* @param <T> Type of the value
* @return Deserialized value or <code>null</code> if the serialized value is <code>null</code>
* @throws IOException On failure during deserialization
*/
public static <T> T deserializeValue(byte[] serializedValue, TypeSerializer<T> serializer) throws IOException {
if (serializedValue == null) {
return null;
} else {
final DataInputDeserializer deser = new DataInputDeserializer(serializedValue, 0, serializedValue.length);
final T value = serializer.deserialize(deser);
if (deser.available() > 0) {
throw new IOException("Unconsumed bytes in the deserialized value. " + "This indicates a mismatch in the value serializers " + "used by the KvState instance and this access.");
}
return value;
}
}
use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.
the class JobConfWrapper method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
final byte[] data = new byte[in.readInt()];
in.readFully(data);
final DataInputDeserializer deser = new DataInputDeserializer(data);
this.jobConf = new JobConf();
try {
jobConf.readFields(deser);
} catch (IOException e) {
throw new IOException("Could not deserialize JobConf, the serialized and de-serialized don't match.", e);
}
Credentials currentUserCreds = HadoopInputFormatCommonBase.getCredentialsFromUGI(UserGroupInformation.getCurrentUser());
if (currentUserCreds != null) {
jobConf.getCredentials().addAll(currentUserCreds);
}
}
Aggregations