001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2009 Sun Microsystems, Inc.
015 * Portions copyright 2011-2016 ForgeRock AS.
016 */
017package org.forgerock.opendj.io;
018
019import java.io.IOException;
020
021import org.forgerock.opendj.ldap.ByteSequence;
022
023/**
024 * An abstract {@code ASN1Writer} which can be used as the basis for
025 * implementing new ASN1 writer implementations.
026 */
027public abstract class AbstractASN1Writer implements ASN1Writer {
028
029    /** Creates a new abstract ASN.1 writer. */
030    protected AbstractASN1Writer() {
031        // No implementation required.
032    }
033
034    @Override
035    public ASN1Writer writeBoolean(final boolean value) throws IOException {
036        return writeBoolean(ASN1.UNIVERSAL_BOOLEAN_TYPE, value);
037    }
038
039    @Override
040    public ASN1Writer writeEnumerated(final int value) throws IOException {
041        return writeEnumerated(ASN1.UNIVERSAL_ENUMERATED_TYPE, value);
042    }
043
044    @Override
045    public ASN1Writer writeInteger(final int value) throws IOException {
046        return writeInteger(ASN1.UNIVERSAL_INTEGER_TYPE, value);
047    }
048
049    @Override
050    public ASN1Writer writeInteger(final long value) throws IOException {
051        return writeInteger(ASN1.UNIVERSAL_INTEGER_TYPE, value);
052    }
053
054    @Override
055    public ASN1Writer writeNull() throws IOException {
056        return writeNull(ASN1.UNIVERSAL_NULL_TYPE);
057    }
058
059    @Override
060    public ASN1Writer writeOctetString(byte type, byte[] value) throws IOException {
061        return writeOctetString(type, value, 0, value.length);
062    }
063
064    @Override
065    public ASN1Writer writeOctetString(byte[] value) throws IOException {
066        return writeOctetString(value, 0, value.length);
067    }
068
069    @Override
070    public ASN1Writer writeOctetString(final byte[] value, final int offset, final int length)
071            throws IOException {
072        return writeOctetString(ASN1.UNIVERSAL_OCTET_STRING_TYPE, value, offset, length);
073    }
074
075    @Override
076    public ASN1Writer writeOctetString(final ByteSequence value) throws IOException {
077        return writeOctetString(ASN1.UNIVERSAL_OCTET_STRING_TYPE, value);
078    }
079
080    @Override
081    public ASN1Writer writeOctetString(final String value) throws IOException {
082        return writeOctetString(ASN1.UNIVERSAL_OCTET_STRING_TYPE, value);
083    }
084
085    @Override
086    public ASN1Writer writeStartSequence() throws IOException {
087        return writeStartSequence(ASN1.UNIVERSAL_SEQUENCE_TYPE);
088    }
089
090    @Override
091    public ASN1Writer writeStartSet() throws IOException {
092        return writeStartSet(ASN1.UNIVERSAL_SET_TYPE);
093    }
094
095}