slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 1 | /* 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/. */ |
| 4 | package org.onosproject.xran.codecs.ber.types; |
| 5 | |
| 6 | import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream; |
| 7 | import org.onosproject.xran.codecs.ber.BerTag; |
| 8 | |
| 9 | import java.io.IOException; |
| 10 | import java.io.InputStream; |
| 11 | import java.io.UnsupportedEncodingException; |
| 12 | |
| 13 | public class BerDateTime extends BerTime { |
| 14 | |
| 15 | public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.DATE_TIME_TAG); |
| 16 | private static final long serialVersionUID = 1L; |
| 17 | |
| 18 | public BerDateTime() { |
| 19 | } |
| 20 | |
| 21 | public BerDateTime(byte[] value) { |
| 22 | super(value); |
| 23 | } |
| 24 | |
| 25 | public BerDateTime(String valueAsString) throws UnsupportedEncodingException { |
| 26 | super(valueAsString); |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 31 | |
| 32 | int codeLength = super.encode(os, false); |
| 33 | |
| 34 | if (withTag) { |
| 35 | codeLength += tag.encode(os); |
| 36 | } |
| 37 | |
| 38 | return codeLength; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 43 | |
| 44 | int codeLength = 0; |
| 45 | |
| 46 | if (withTag) { |
| 47 | codeLength += tag.decodeAndCheck(is); |
| 48 | } |
| 49 | |
| 50 | codeLength += super.decode(is, false); |
| 51 | |
| 52 | return codeLength; |
| 53 | } |
| 54 | |
| 55 | } |