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