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 024import org.forgerock.opendj.ldap.Entry; 025 026/** 027 * An interface for reading entries from a data source, typically an LDIF file. 028 * <p> 029 * Implementations must specify the following: 030 * <ul> 031 * <li>Whether it is possible for the implementation to encounter 032 * malformed change records and, if it is possible, how they are handled. 033 * <li>Any synchronization limitations. 034 * </ul> 035 */ 036public interface EntryReader extends Closeable { 037 038 /** 039 * Closes this entry reader if it is not already closed. Note that this 040 * method does not need to be called if a previous call of 041 * {@link #readEntry()} has returned {@code null}. 042 * 043 * @throws IOException 044 * If an unexpected IO error occurred while closing. 045 */ 046 @Override 047 void close() throws IOException; 048 049 /** 050 * Returns {@code true} if this reader contains another entry, blocking if 051 * necessary until either the next entry is available or the end of the 052 * stream is reached. 053 * 054 * @return {@code true} if this reader contains another entry. 055 * @throws IOException 056 * If an unexpected IO error occurred. 057 */ 058 boolean hasNext() throws IOException; 059 060 /** 061 * Reads the next entry, blocking if necessary until an entry is available. 062 * 063 * @return The next entry. 064 * @throws IOException 065 * If an unexpected IO error occurred while reading the entry. 066 * @throws NoSuchElementException 067 * If this reader does not contain any more entries. 068 */ 069 Entry readEntry() throws IOException; 070}