Improved support for default yang statements in configuration subsystem
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / fromxml / SimpleBinaryAttributeReadingStrategy.java
1 /*
2  * Copyright (c) 2013 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.netconf.confignetconfconnector.mapping.attributes.fromxml;
10
11 import com.google.common.collect.Lists;
12 import com.google.common.io.BaseEncoding;
13
14 import java.util.List;
15
16 public class SimpleBinaryAttributeReadingStrategy extends SimpleAttributeReadingStrategy {
17
18     public SimpleBinaryAttributeReadingStrategy(String nullableDefault) {
19         super(nullableDefault);
20     }
21
22     protected Object postprocessParsedValue(String textContent) {
23         BaseEncoding en = BaseEncoding.base64();
24         byte[] decode = en.decode(textContent);
25         List<String> parsed = Lists.newArrayListWithCapacity(decode.length);
26         for (byte b : decode) {
27             parsed.add(Byte.toString(b));
28         }
29         return parsed;
30     }
31
32     @Override
33     protected Object postprocessNullableDefault(String nullableDefault) {
34         return nullableDefault == null ? null : postprocessParsedValue(nullableDefault);
35     }
36 }