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 2009-2010 Sun Microsystems, Inc. 025 * Portions copyright 2012 ForgeRock AS. 026 */ 027 028package org.forgerock.opendj.ldif; 029 030import java.io.Closeable; 031import java.io.IOException; 032import java.util.NoSuchElementException; 033 034/** 035 * An interface for reading change records from a data source, typically an LDIF 036 * file. 037 * <p> 038 * Implementations must specify the following: 039 * <ul> 040 * <li>Whether or not it is possible for the implementation to encounter 041 * malformed change records and, if it is possible, how they are handled. 042 * <li>Any synchronization limitations. 043 * </ul> 044 */ 045public interface ChangeRecordReader extends Closeable { 046 047 /** 048 * Closes this change record reader if it not already closed. Note that this 049 * method does not need to be called if a previous call of 050 * {@link #readChangeRecord()} has returned {@code null}. 051 * 052 * @throws IOException 053 * If an unexpected IO error occurred while closing. 054 */ 055 @Override 056 void close() throws IOException; 057 058 /** 059 * Returns {@code true} if this reader contains another change record, 060 * blocking if necessary until either the next change record is available or 061 * the end of the stream is reached. 062 * 063 * @return {@code true} if this reader contains another change record. 064 * @throws IOException 065 * If an unexpected IO error occurred. 066 */ 067 boolean hasNext() throws IOException; 068 069 /** 070 * Reads the next change record, blocking if necessary until a change record 071 * is available. If the next change record does not contain a change type 072 * then it will be treated as an {@code Add} change record. 073 * 074 * @return The next change record. 075 * @throws IOException 076 * If an unexpected IO error occurred while reading the change 077 * record. 078 * @throws NoSuchElementException 079 * If this reader does not contain any more change records. 080 */ 081 ChangeRecord readChangeRecord() throws IOException; 082}