| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006 Sun Microsystems, Inc. |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.RDN; |
| | | |
| | | import static org.opends.server.loggers.Debug.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugCought; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.opends.server.util.Validator.*; |
| | | |
| | |
| | | */ |
| | | public final class LDIFWriter |
| | | { |
| | | /** |
| | | * The fully-qualified name of this class for debugging purposes. |
| | | */ |
| | | private static final String CLASS_NAME = "org.opends.server.util.LDIFWriter"; |
| | | |
| | | |
| | | // FIXME -- Add support for generating a hash when writing the data. |
| | |
| | | public LDIFWriter(LDIFExportConfig exportConfig) |
| | | throws IOException |
| | | { |
| | | assert debugConstructor(CLASS_NAME, String.valueOf(exportConfig)); |
| | | |
| | | ensureNotNull(exportConfig); |
| | | this.exportConfig = exportConfig; |
| | |
| | | public void writeComment(String comment, int wrapColumn) |
| | | throws IOException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "writeComment", String.valueOf(comment), |
| | | String.valueOf(wrapColumn)); |
| | | |
| | | ensureNotNull(comment); |
| | | |
| | |
| | | */ |
| | | public boolean writeEntries(Collection <Entry> entries) |
| | | throws IOException, LDIFException { |
| | | assert debugEnter(CLASS_NAME, "writeEntry", String.valueOf(entries)); |
| | | |
| | | boolean ret=true; |
| | | Iterator<Entry> i = entries.iterator(); |
| | |
| | | public boolean writeEntry(Entry entry) |
| | | throws IOException, LDIFException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "writeEntry", String.valueOf(entry)); |
| | | |
| | | ensureNotNull(entry); |
| | | return entry.toLDIF(exportConfig); |
| | |
| | | public void writeAddChangeRecord(Entry entry) |
| | | throws IOException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "writeAddChangeRecord", |
| | | String.valueOf(entry)); |
| | | |
| | | ensureNotNull(entry); |
| | | |
| | |
| | | public void writeDeleteChangeRecord(Entry entry, boolean commentEntry) |
| | | throws IOException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "writeDeleteChangeRecord", |
| | | String.valueOf(entry), String.valueOf(commentEntry)); |
| | | |
| | | ensureNotNull(entry); |
| | | |
| | |
| | | public void writeModifyChangeRecord(DN dn, List<Modification> modifications) |
| | | throws IOException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "writeModifyChangeRecord", String.valueOf(dn), |
| | | String.valueOf(modifications)); |
| | | |
| | | ensureNotNull(dn, modifications); |
| | | |
| | |
| | | DN newSuperior) |
| | | throws IOException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "writeModifyDNChangeRecord", |
| | | String.valueOf(dn), String.valueOf(newRDN), |
| | | String.valueOf(deleteOldRDN), |
| | | String.valueOf(newSuperior)); |
| | | |
| | | ensureNotNull(dn, newRDN); |
| | | |
| | |
| | | public void flush() |
| | | throws IOException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "flush"); |
| | | |
| | | writer.flush(); |
| | | } |
| | |
| | | public void close() |
| | | throws IOException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "close"); |
| | | |
| | | writer.flush(); |
| | | writer.close(); |
| | |
| | | public static void appendLDIFSeparatorAndValue(StringBuilder buffer, |
| | | byte[] valueBytes) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "appendLDIFSeparatorAndValue", |
| | | "java.lang.StringBuilder", |
| | | String.valueOf(valueBytes)); |
| | | |
| | | ensureNotNull(buffer, valueBytes); |
| | | |
| | |
| | | catch (Exception e) |
| | | { |
| | | // This should never happen. |
| | | assert debugException(CLASS_NAME, "appendLDIFSeparatorAndValue", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | buffer.append(new String(valueBytes)); |
| | | } |
| | | } |
| | |
| | | boolean wrapLines, int wrapColumn) |
| | | throws IOException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "writeLDIFLine", String.valueOf(line), |
| | | String.valueOf(writer), String.valueOf(wrapLines), |
| | | String.valueOf(wrapColumn)); |
| | | |
| | | ensureNotNull(line, writer); |
| | | |