Remove yang-test
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / toxml / SimpleBinaryAttributeWritingStrategy.java
1 /*
2  * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.io.BaseEncoding;
13 import java.util.List;
14 import org.opendaylight.controller.config.facade.xml.util.Util;
15 import org.w3c.dom.Document;
16
17 public class SimpleBinaryAttributeWritingStrategy extends SimpleAttributeWritingStrategy {
18
19     public SimpleBinaryAttributeWritingStrategy(final Document document, final String key) {
20         super(document, key);
21     }
22
23     @Override
24     protected Object preprocess(final Object value) {
25         Util.checkType(value, List.class);
26         BaseEncoding en = BaseEncoding.base64();
27
28         List<?> list = (List<?>) value;
29         byte[] decoded = new byte[list.size()];
30         int index = 0;
31         for (Object basStr : list) {
32             Preconditions.checkArgument(basStr instanceof String, "Unexpected inner value for %s, expected string",
33                     value);
34             decoded[index++] = Byte.parseByte((String) basStr);
35         }
36         return en.encode(decoded);
37     }
38 }