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 Sun Microsystems, Inc. 025 * Portions copyright 2012 ForgeRock AS. 026 */ 027 028package org.forgerock.opendj.ldif; 029 030import java.io.Closeable; 031import java.io.Flushable; 032import java.io.IOException; 033 034import org.forgerock.opendj.ldap.Entry; 035 036/** 037 * An interface for writing entries to a data source, typically an LDIF file. 038 */ 039public interface EntryWriter extends Closeable, Flushable { 040 /** 041 * Closes this entry writer, flushing it first. Closing a previously closed 042 * entry writer has no effect. 043 * 044 * @throws IOException 045 * If an unexpected IO error occurred while closing. 046 */ 047 void close() throws IOException; 048 049 /** 050 * Flushes this entry writer so that any buffered data is written 051 * immediately to underlying stream, flushing the stream if it is also 052 * {@code Flushable}. 053 * <p> 054 * If the intended destination of this stream is an abstraction provided by 055 * the underlying operating system, for example a file, then flushing the 056 * stream guarantees only that bytes previously written to the stream are 057 * passed to the operating system for writing; it does not guarantee that 058 * they are actually written to a physical device such as a disk drive. 059 * 060 * @throws IOException 061 * If an unexpected IO error occurred while flushing. 062 */ 063 void flush() throws IOException; 064 065 /** 066 * Writes a comment. 067 * 068 * @param comment 069 * The {@code CharSequence} to be written as a comment. 070 * @return A reference to this entry writer. 071 * @throws IOException 072 * If an unexpected IO error occurred while writing the comment. 073 * @throws NullPointerException 074 * If {@code comment} was {@code null}. 075 */ 076 EntryWriter writeComment(CharSequence comment) throws IOException; 077 078 /** 079 * Writes an entry. 080 * 081 * @param entry 082 * The {@code Entry} to be written. 083 * @return A reference to this entry writer. 084 * @throws IOException 085 * If an unexpected IO error occurred while writing the entry. 086 * @throws NullPointerException 087 * If {@code entry} was {@code null}. 088 */ 089 EntryWriter writeEntry(Entry entry) throws IOException; 090 091}