import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Optional;
-import javax.annotation.Nonnull;
import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
// Hidden to prevent subclassing from outside of this package
}
+ @Deprecated
public static ShardDataTreeSnapshot deserialize(final byte[] bytes) throws IOException {
/**
* Unfortunately versions prior to Boron did not include any way to evolve the snapshot format and contained
try {
try (final InputStream is = new ByteArrayInputStream(bytes)) {
- try (final DataInputStream dis = new DataInputStream(is)) {
- final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserialize(dis);
-
- // Make sure we consume all bytes, otherwise something went very wrong
- final int bytesLeft = dis.available();
- if (bytesLeft != 0) {
- throw new IOException("Deserialization left " + bytesLeft + " in the buffer");
- }
-
-
- return ret;
- }
+ return deserialize(is);
}
} catch (IOException e) {
LOG.debug("Failed to deserialize versioned stream, attempting pre-Lithium ProtoBuf", e);
}
}
+ public static ShardDataTreeSnapshot deserialize(final InputStream is) throws IOException {
+ try (final DataInputStream dis = new DataInputStream(is)) {
+ final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserialize(dis);
+
+ // Make sure we consume all bytes, otherwise something went very wrong
+ final int bytesLeft = dis.available();
+ if (bytesLeft != 0) {
+ throw new IOException("Deserialization left " + bytesLeft + " in the buffer");
+ }
+
+
+ return ret;
+ }
+ }
+
/**
* Get the root data node contained in this snapshot.
*
*/
public abstract Optional<NormalizedNode<?, ?>> getRootNode();
- /**
- * Serialize this snapshot into a byte array for persistence.
- *
- * @return Serialized snapshot
- * @throws IOException when a serialization problem occurs
- */
- public abstract @Nonnull byte[] serialize() throws IOException;
+ public abstract void serialize(final OutputStream os) throws IOException;
+ @Deprecated
private static boolean isLegacyStream(final byte[] bytes) {
if (bytes.length < 2) {
// Versioned streams have at least two bytes