LDAP Classes
Implements Java LDAP

com.novell.ldap.util
Class LDIFWriter

java.lang.Object
  extended bycom.novell.ldap.util.LDIFWriter
All Implemented Interfaces:
LDAPWriter

public class LDIFWriter
extends java.lang.Object
implements LDAPWriter

LDIFWriter is used to write LDIF content records or LDIF change records to the OutputStream object.

The object of the class is used to generate LDIF content record or LDIF change record lines and write the lines to OUtputStream


Constructor Summary
LDIFWriter(java.io.OutputStream out)
          Constructs an LDIFWriter object.
LDIFWriter(java.io.OutputStream out, java.lang.String version, boolean request)
          Constructs an LDIFWriter object.
 
Method Summary
 void finish()
          Write all remaining data to the output stream
 java.lang.String getVersion()
          Gets the version of the LDIF data associated with the input stream
 boolean isPrintable(byte[] bytes)
          Check if the input byte array object is safe to make a String.
 boolean isRequest()
          Returns true if request data ist associated with the input stream, or false if content data.
 void writeComments(java.lang.String line)
          Write a comment line into the LDIF OutputStream.
 void writeEntry(LDAPEntry entry)
          Write an LDAP record into LDIF file as LDAPContent data.
 void writeEntry(LDAPEntry entry, LDAPControl[] controls)
          Write an LDAP record into LDIF file as LDAPContent data.
 void writeError(java.lang.Exception e)
          Writes an exception as a comment in LDIF.
 void writeMessage(LDAPMessage request)
          Write an LDAP record into LDIF file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LDIFWriter

public LDIFWriter(java.io.OutputStream out)
           throws java.io.IOException
Constructs an LDIFWriter object. It allows the setting of the OutputStreamReader object, and assumes the LDIF version is "1". The type of file written is determined by the first message written to the file.

If the first message is one of LDAPAddRequest, LDAPDeleteRequest, LDAPModifyDNRequest, or LDAPModifyRequest the file will be writen as an LDAP request (change) file.

If the first message written to the file is an LDAPSearchResult object an LDIF content file will be written.

You are not allowed to mix request data and content data

Parameters:
out - The OutputStream where the LDIF data will be written.
Throws:
java.io.IOException - for errors writing to the stream.

LDIFWriter

public LDIFWriter(java.io.OutputStream out,
                  java.lang.String version,
                  boolean request)
           throws java.io.IOException
Constructs an LDIFWriter object. It allows the setting of the OutputStreamReader object, the LDIF version, and the type of LDIF file.

Parameters:
out - The OutputStream where the LDIF data will be written.
version - The version to set in the LDIF file, must be "1".
request - If true sets the out file type to request (change) data, else the file type will be content.
Throws:
java.io.IOException
Method Detail

writeEntry

public void writeEntry(LDAPEntry entry)
                throws java.io.IOException
Write an LDAP record into LDIF file as LDAPContent data.

You are not allowed to mix request data and content data

Specified by:
writeEntry in interface LDAPWriter
Parameters:
entry - LDAPEntry object
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
LDAPEntry

writeEntry

public void writeEntry(LDAPEntry entry,
                       LDAPControl[] controls)
                throws java.io.IOException
Write an LDAP record into LDIF file as LDAPContent data.

You are not allowed to mix request data and content data

Specified by:
writeEntry in interface LDAPWriter
Parameters:
entry - LDAPEntry object
controls - Controls that were returned with this entry
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
LDAPEntry

writeMessage

public void writeMessage(LDAPMessage request)
                  throws java.io.IOException
Write an LDAP record into LDIF file. A request or change operation may be objects of type LDAPAddRequest, LDAPDeleteRequest, LDAPModifyDNRequest, or LDAPModifyRequest. To write LDIF Content you must use an LDAPSearchResult object.

You are not allowed to mix request data and content data

Specified by:
writeMessage in interface LDAPWriter
Parameters:
request - LDAPMessage object
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
LDAPSearchResults, LDAPAddRequest, LDAPDeleteRequest, LDAPModifyDNRequest, LDAPModifyRequest

writeComments

public void writeComments(java.lang.String line)
                   throws java.io.IOException
Write a comment line into the LDIF OutputStream.

an '#' char is added to the front of each line to indicate that the line is a comment line. If a line contains more than 78 chars, it will be split into multiple lines each of which starts with '#'

Specified by:
writeComments in interface LDAPWriter
Parameters:
line - The comment lines to be written to the OutputStream
Throws:
java.io.IOException - if an I/O error occurs.

writeError

public void writeError(java.lang.Exception e)
                throws java.io.IOException
Writes an exception as a comment in LDIF.

Specified by:
writeError in interface LDAPWriter
Parameters:
e - Exception to be written.
Throws:
java.io.IOException

getVersion

public java.lang.String getVersion()
Gets the version of the LDIF data associated with the input stream

Specified by:
getVersion in interface LDAPWriter
Returns:
the version number

isRequest

public boolean isRequest()
Returns true if request data ist associated with the input stream, or false if content data.

Specified by:
isRequest in interface LDAPWriter
Returns:
true if input stream contains request data.

isPrintable

public boolean isPrintable(byte[] bytes)
Check if the input byte array object is safe to make a String.

Check if the input byte array contains any un-printable value

Parameters:
bytes - The byte array object to be checked.
Returns:
boolean object to incidate that the byte array object is safe or not

finish

public void finish()
            throws java.io.IOException
Write all remaining data to the output stream

Specified by:
finish in interface LDAPWriter
Throws:
java.io.IOException

LDAP Classes
Implements Java LDAP

Copyright © 2002 Novell, Inc. All Rights Reserved.
Novell, Inc.
1800 South Novell Place
Provo, Ut 84606
Phone: (801) 861-5000