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