Java Code Examples for org.apache.flink.core.memory.DataInputDeserializer#readByte()
The following examples show how to use
org.apache.flink.core.memory.DataInputDeserializer#readByte() .
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: RocksDBListState.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static <V> V deserializeNextElement(DataInputDeserializer in, TypeSerializer<V> elementSerializer) { try { if (in.available() > 0) { V element = elementSerializer.deserialize(in); if (in.available() > 0) { in.readByte(); } return element; } } catch (IOException e) { throw new FlinkRuntimeException("Unexpected list element deserialization failure"); } return null; }
Example 2
Source File: KvStateSerializer.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 3
Source File: KvStateSerializer.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Deserializes all values with the given serializer. * * @param serializedValue Serialized value of type List<T> * @param serializer Serializer for T * @param <T> Type of the value * @return Deserialized list or <code>null</code> if the serialized value * is <code>null</code> * @throws IOException On failure during deserialization */ public static <T> List<T> deserializeList(byte[] serializedValue, TypeSerializer<T> serializer) throws IOException { if (serializedValue != null) { final DataInputDeserializer in = new DataInputDeserializer( serializedValue, 0, serializedValue.length); try { final List<T> result = new ArrayList<>(); while (in.available() > 0) { result.add(serializer.deserialize(in)); // The expected binary format has a single byte separator. We // want a consistent binary format in order to not need any // special casing during deserialization. A "cleaner" format // would skip this extra byte, but would require a memory copy // for RocksDB, which stores the data serialized in this way // for lists. if (in.available() > 0) { in.readByte(); } } return result; } catch (IOException e) { throw new IOException( "Unable to deserialize value. " + "This indicates a mismatch in the value serializers " + "used by the KvState instance and this access.", e); } } else { return null; } }
Example 4
Source File: RocksDBListState.java From flink with Apache License 2.0 | 5 votes |
private static <V> V deserializeNextElement(DataInputDeserializer in, TypeSerializer<V> elementSerializer) { try { if (in.available() > 0) { V element = elementSerializer.deserialize(in); if (in.available() > 0) { in.readByte(); } return element; } } catch (IOException e) { throw new FlinkRuntimeException("Unexpected list element deserialization failure", e); } return null; }
Example 5
Source File: KvStateSerializer.java From flink with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 6
Source File: KvStateSerializer.java From flink with Apache License 2.0 | 5 votes |
/** * Deserializes all values with the given serializer. * * @param serializedValue Serialized value of type List<T> * @param serializer Serializer for T * @param <T> Type of the value * @return Deserialized list or <code>null</code> if the serialized value * is <code>null</code> * @throws IOException On failure during deserialization */ public static <T> List<T> deserializeList(byte[] serializedValue, TypeSerializer<T> serializer) throws IOException { if (serializedValue != null) { final DataInputDeserializer in = new DataInputDeserializer( serializedValue, 0, serializedValue.length); try { final List<T> result = new ArrayList<>(); while (in.available() > 0) { result.add(serializer.deserialize(in)); // The expected binary format has a single byte separator. We // want a consistent binary format in order to not need any // special casing during deserialization. A "cleaner" format // would skip this extra byte, but would require a memory copy // for RocksDB, which stores the data serialized in this way // for lists. if (in.available() > 0) { in.readByte(); } } return result; } catch (IOException e) { throw new IOException( "Unable to deserialize value. " + "This indicates a mismatch in the value serializers " + "used by the KvState instance and this access.", e); } } else { return null; } }
Example 7
Source File: RocksDBListState.java From flink with Apache License 2.0 | 5 votes |
private static <V> V deserializeNextElement(DataInputDeserializer in, TypeSerializer<V> elementSerializer) { try { if (in.available() > 0) { V element = elementSerializer.deserialize(in); if (in.available() > 0) { in.readByte(); } return element; } } catch (IOException e) { throw new FlinkRuntimeException("Unexpected list element deserialization failure", e); } return null; }
Example 8
Source File: KvStateSerializer.java From flink with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 9
Source File: KvStateSerializer.java From flink with Apache License 2.0 | 5 votes |
/** * Deserializes all values with the given serializer. * * @param serializedValue Serialized value of type List<T> * @param serializer Serializer for T * @param <T> Type of the value * @return Deserialized list or <code>null</code> if the serialized value * is <code>null</code> * @throws IOException On failure during deserialization */ public static <T> List<T> deserializeList(byte[] serializedValue, TypeSerializer<T> serializer) throws IOException { if (serializedValue != null) { final DataInputDeserializer in = new DataInputDeserializer( serializedValue, 0, serializedValue.length); try { final List<T> result = new ArrayList<>(); while (in.available() > 0) { result.add(serializer.deserialize(in)); // The expected binary format has a single byte separator. We // want a consistent binary format in order to not need any // special casing during deserialization. A "cleaner" format // would skip this extra byte, but would require a memory copy // for RocksDB, which stores the data serialized in this way // for lists. if (in.available() > 0) { in.readByte(); } } return result; } catch (IOException e) { throw new IOException( "Unable to deserialize value. " + "This indicates a mismatch in the value serializers " + "used by the KvState instance and this access.", e); } } else { return null; } }