2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml;
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;
17 public class SimpleBinaryAttributeWritingStrategy extends SimpleAttributeWritingStrategy {
23 public SimpleBinaryAttributeWritingStrategy(final Document document, final String key) {
28 protected Object preprocess(final Object value) {
29 Util.checkType(value, List.class);
30 BaseEncoding en = BaseEncoding.base64();
32 List<?> list = (List<?>) value;
33 byte[] decoded = new byte[list.size()];
35 for (Object bAsStr : list) {
36 Preconditions.checkArgument(bAsStr instanceof String, "Unexpected inner value for %s, expected string", value);
37 byte b = Byte.parseByte((String) bAsStr);
41 return en.encode(decoded);