2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.misc.rosetta.marshal;
24 import javax.xml.datatype.XMLGregorianCalendar;
26 import org.onap.aaf.misc.env.util.Chrono;
29 * We make these objects instead of static functions so they can be passed into
36 public abstract class DataWriter<T> {
37 public abstract boolean write(T t, StringBuilder sb);
39 public final static DataWriter<String> STRING = new DataWriter<String>() {
41 public boolean write(String s, StringBuilder sb) {
47 public final static DataWriter<Integer> INTEGER = new DataWriter<Integer>() {
49 public boolean write(Integer i, StringBuilder sb) {
55 public final static DataWriter<Long> LONG = new DataWriter<Long>() {
57 public boolean write(Long t, StringBuilder sb) {
63 public final static DataWriter<Byte> BYTE = new DataWriter<Byte>() {
65 public boolean write(Byte t, StringBuilder sb) {
71 public final static DataWriter<Character> CHAR = new DataWriter<Character>() {
73 public boolean write(Character t, StringBuilder sb) {
79 public final static DataWriter<Boolean> BOOL = new DataWriter<Boolean>() {
81 public boolean write(Boolean t, StringBuilder sb) {
89 public final static DataWriter<byte[]> BYTE_ARRAY = new DataWriter<byte[]>() {
91 public boolean write(byte[] ba, StringBuilder sb) {
92 ByteArrayInputStream bais = new ByteArrayInputStream(ba);
93 StringBuilderOutputStream sbos = new StringBuilderOutputStream(sb);
96 // Symm.base64noSplit().encode(bais, sbos);
97 // } catch (IOException e) {
106 public final static DataWriter<XMLGregorianCalendar> DATE = new DataWriter<XMLGregorianCalendar>() {
108 public boolean write(XMLGregorianCalendar t, StringBuilder sb) {
109 sb.append(Chrono.dateOnlyStamp(t));
114 public final static DataWriter<XMLGregorianCalendar> DATE_TIME = new DataWriter<XMLGregorianCalendar>() {
116 public boolean write(XMLGregorianCalendar t, StringBuilder sb) {
117 sb.append(Chrono.dateTime(t));
122 private static final char[] chars="0123456789ABCDEF".toCharArray();
123 public final static DataWriter<byte[]> HEX_BINARY = new DataWriter<byte[]>() {
125 public boolean write(byte[] ba, StringBuilder sb) {
126 // FYI, doing this because don't want intermediate
127 // String in "HexString" or the processing in
130 for(int i=0;i<ba.length;++i) {
132 sb.append(chars[((b&0xF0)>>4)]);
133 sb.append(chars[b&0xF]);