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