001 /*
002 * Copyright 2009-2016 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2009-2016 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.asn1;
022
023
024
025 import java.io.Serializable;
026
027 import com.unboundid.util.Mutable;
028 import com.unboundid.util.ThreadSafety;
029 import com.unboundid.util.ThreadSafetyLevel;
030
031
032
033 /**
034 * This class provides a data structure which is used in the course of writing
035 * an ASN.1 set to an ASN.1 buffer. It keeps track of the position at which the
036 * set value begins so that the appropriate length may be inserted
037 * after all embedded elements have been added. The {@link #end} method must be
038 * called after all elements have been added to ensure that the length is
039 * properly computed and inserted into the associated buffer.
040 */
041 @Mutable()
042 @ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE)
043 public final class ASN1BufferSet
044 implements Serializable
045 {
046 /**
047 * The serial version UID for this serializable class.
048 */
049 private static final long serialVersionUID = 6686782295672518084L;
050
051
052
053 // The ASN.1 buffer with which the set is associated.
054 private final ASN1Buffer buffer;
055
056 // The position in the ASN.1 buffer at which the first set value begins.
057 private final int valueStartPos;
058
059
060
061 /**
062 * Creates a new instance of this class for the provided ASN.1 buffer.
063 *
064 * @param buffer The ASN.1 buffer with which this object will be associated.
065 */
066 ASN1BufferSet(final ASN1Buffer buffer)
067 {
068 this.buffer = buffer;
069
070 valueStartPos = buffer.length();
071 }
072
073
074
075 /**
076 * Updates the associated ASN.1 buffer to indicate that all sequence elements
077 * have been added and that the appropriate length should be inserted.
078 */
079 public void end()
080 {
081 buffer.endSequenceOrSet(valueStartPos);
082 }
083 }