/*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.cluster.datastore.node.utils.stream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.xml.transform.dom.DOMSource;
import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
private boolean readSignatureMarker = true;
- public NormalizedNodeInputStreamReader(InputStream stream) throws IOException {
+ public NormalizedNodeInputStreamReader(final InputStream stream) throws IOException {
Preconditions.checkNotNull(stream);
input = new DataInputStream(stream);
}
- public NormalizedNodeInputStreamReader(DataInput input) throws IOException {
+ public NormalizedNodeInputStreamReader(final DataInput input) {
this.input = Preconditions.checkNotNull(input);
}
return leafSetEntryBuilder;
}
- private NormalizedNode<?, ?> readNodeIdentifierDependentNode(byte nodeType, NodeIdentifier identifier)
+ private NormalizedNode<?, ?> readNodeIdentifierDependentNode(final byte nodeType, final NodeIdentifier identifier)
throws IOException {
switch(nodeType) {
case NodeTypes.ANY_XML_NODE :
LOG.debug("Read xml node");
- return Builders.anyXmlBuilder().withValue((Node<?>) readObject()).build();
+ return Builders.anyXmlBuilder().withValue((DOMSource) readObject()).build();
case NodeTypes.MAP_NODE :
LOG.debug("Read map node {}", identifier);
case ValueTypes.STRING_TYPE :
return input.readUTF();
+ case ValueTypes.STRING_BYTES_TYPE:
+ return readStringBytes();
+
case ValueTypes.BIG_DECIMAL_TYPE :
return new BigDecimal(input.readUTF());
}
}
+ private String readStringBytes() throws IOException {
+ byte[] bytes = new byte[input.readInt()];
+ input.readFully(bytes);
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
+
public YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
readSignatureMarkerAndVersionIfNeeded();
return readYangInstanceIdentifierInternal();
return children;
}
- private PathArgument readPathArgument() throws IOException {
+ public PathArgument readPathArgument() throws IOException {
// read Type
int type = input.readByte();
}
@SuppressWarnings("unchecked")
- private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(QName nodeType,
- ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException {
+ private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType,
+ final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException {
LOG.debug("Reading children of leaf set");
@SuppressWarnings({ "unchecked", "rawtypes" })
private NormalizedNodeContainerBuilder addDataContainerChildren(
- NormalizedNodeContainerBuilder builder) throws IOException {
+ final NormalizedNodeContainerBuilder builder) throws IOException {
LOG.debug("Reading data container (leaf nodes) nodes");
NormalizedNode<?, ?> child = readNormalizedNodeInternal();