001 /* 002 * Copyright 2009-2015 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005 /* 006 * Copyright (C) 2009-2015 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 028 029 030 /** 031 * This class provides a data structure which is used in the course of writing 032 * an ASN.1 sequence to an ASN.1 buffer. It keeps track of the position at 033 * which the sequence value begins so that the appropriate length may be 034 * inserted after all embedded elements have been added. The {@code end} 035 * method must be called after all elements have been added to ensure that the 036 * length is properly computed and inserted into the associated buffer. 037 */ 038 public final class ASN1BufferSequence 039 implements Serializable 040 { 041 /** 042 * The serial version UID for this serializable class. 043 */ 044 private static final long serialVersionUID = 7219098399193345629L; 045 046 047 048 // The ASN.1 buffer with which the sequence is associated. 049 private final ASN1Buffer buffer; 050 051 // The position in the ASN.1 buffer at which the first sequence value begins. 052 private final int valueStartPos; 053 054 055 056 /** 057 * Creates a new instance of this class for the provided ASN.1 buffer. 058 * 059 * @param buffer The ASN.1 buffer with which this object will be associated. 060 */ 061 ASN1BufferSequence(final ASN1Buffer buffer) 062 { 063 this.buffer = buffer; 064 065 valueStartPos = buffer.length(); 066 } 067 068 069 070 /** 071 * Updates the associated ASN.1 buffer to indicate that all sequence elements 072 * have been added and that the appropriate length should be inserted. 073 */ 074 public void end() 075 { 076 buffer.endSequenceOrSet(valueStartPos); 077 } 078 }