blob: 1c89db517c488c15addb30bbdfd657f3b9c57cf0 [file] [log] [blame]
slowr60d4d102017-08-16 18:33:58 -07001/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4package org.onosproject.xran.codecs.ber.types.string;
5
6import com.fasterxml.jackson.annotation.JsonValue;
7import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
8import org.onosproject.xran.codecs.ber.BerTag;
9import org.onosproject.xran.codecs.ber.types.BerOctetString;
10
11import java.io.IOException;
12import java.io.InputStream;
13
14public class BerGeneralString extends BerOctetString {
15
16 public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.GENERAL_STRING_TAG);
17 private static final long serialVersionUID = 1L;
18
19 public BerGeneralString() {
20 }
21
22 public BerGeneralString(byte[] value) {
23 this.value = value;
24 }
25
26 @JsonValue
27 @Override
28 public String toString() {
29 return new String(value);
30 }
31
32 @Override
33 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
34
35 int codeLength = super.encode(os, false);
36
37 if (withTag) {
38 codeLength += tag.encode(os);
39 }
40
41 return codeLength;
42 }
43
44 @Override
45 public int decode(InputStream is, boolean withTag) throws IOException {
46
47 int codeLength = 0;
48
49 if (withTag) {
50 codeLength += tag.decodeAndCheck(is);
51 }
52
53 codeLength += super.decode(is, false);
54
55 return codeLength;
56 }
57
58}