X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fpersisted%2FShardDataTreeSnapshot.java;h=85d1143a891f743fdc652f1847f4b047c412e8aa;hp=7b8382e9c2536bf44b6dea553e8b81f5c855aeeb;hb=95c296a7c1e8e186a88a0a0dc82e080b2185db33;hpb=2faf656bf68dd3843fd59520b27a7ec2abbdcc68 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java index 7b8382e9c2..85d1143a89 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java @@ -12,7 +12,8 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Optional; import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -33,7 +34,7 @@ public abstract class ShardDataTreeSnapshot { } @Deprecated - public static ShardDataTreeSnapshot deserialize(final byte[] bytes) throws IOException { + public static ShardDataTreeSnapshot deserializePreCarbon(final byte[] bytes) throws IOException { /** * Unfortunately versions prior to Boron did not include any way to evolve the snapshot format and contained * only the raw data stored in the datastore. Furthermore utilities involved do not check if the array is @@ -50,8 +51,19 @@ public abstract class ShardDataTreeSnapshot { } try { - try (final InputStream is = new ByteArrayInputStream(bytes)) { - return deserialize(is); + try (InputStream is = new ByteArrayInputStream(bytes)) { + try (DataInputStream dis = new DataInputStream(is)) { + final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserializePreCarbon(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; + } } } catch (IOException e) { LOG.debug("Failed to deserialize versioned stream, attempting pre-Lithium ProtoBuf", e); @@ -59,19 +71,17 @@ public abstract class ShardDataTreeSnapshot { } } - public static ShardDataTreeSnapshot deserialize(final InputStream is) throws IOException { - try (final DataInputStream dis = new DataInputStream(is)) { - final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserialize(dis); + public static ShardDataTreeSnapshot deserialize(final ObjectInput in) throws IOException { + final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.versionedDeserialize(in); - // 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"); - } + // Make sure we consume all bytes, otherwise something went very wrong + final int bytesLeft = in.available(); + if (bytesLeft != 0) { + throw new IOException("Deserialization left " + bytesLeft + " in the buffer"); + } - return ret; - } + return ret; } /** @@ -81,7 +91,7 @@ public abstract class ShardDataTreeSnapshot { */ public abstract Optional> getRootNode(); - public abstract void serialize(final OutputStream os) throws IOException; + public abstract void serialize(ObjectOutput out) throws IOException; @Deprecated private static boolean isLegacyStream(final byte[] bytes) {