Class LDIF


  • public class LDIF
    extends java.lang.Object
    A class which enables loading and saving of records from/to LDIF files.
    Author:
    jp
    • Constructor Summary

      Constructors 
      Constructor Description
      LDIF​(java.lang.String in_fnam, java.lang.String out_fnam)
      Set up an LDIF stream for input and/or output with the given files.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the input/output files.
      static java.lang.String entryToString​(GenericEntry entry)
      Convert a GenericEntry to an LDIF-encoded string.
      java.lang.String errors()
      Return a string describing all the errors since the last call to this function, or null if there are none.
      protected void finalize()
      Releases any native structures associated with this object.
      GenericEntry get()
      Get the next entry from the LDIF input file.
      GenericEntry get​(long offset)
      Get the entry from the LDIF input file at the given file-offset, which should be a value returned by a call to tell().
      boolean getAllowUnknownAttrs()
      Get the current 'allow unknown attributes' flag status.
      ChangeEntry getChange()
      Get the next ChangeEntry from the LDIF input file.
      Entry getEntry()
      Get the next Entry from the LDIF input file.
      void put​(GenericEntry entry)
      Write an entry to the LDIF output file.
      void putComment​(java.lang.String str)
      Add a comment to the output LDIF file.
      void seek​(long offset)
      Re-seek the input file to the given file-offset, which should be a value previously returned by tell().
      void setAllowUnknownAttrs​(boolean flag)
      Set the status of the 'allow unknown attributes' flag.
      long tell()
      Return the current read file-offset in the input file, which can be used later on to seek() back to this point.
      java.lang.String toString()
      Returns a String representation of the LDIF stream
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • LDIF

        public LDIF​(java.lang.String in_fnam,
                    java.lang.String out_fnam)
             throws OperationFailedException,
                    java.lang.NullPointerException,
                    NativeLibraryException
        Set up an LDIF stream for input and/or output with the given files.
        Parameters:
        in_fnam - Input pathname, or null for no input
        out_fnam - Output pathname, or null for no output
        Throws:
        OperationFailedException - Can't open/create one of the files
        java.lang.NullPointerException - Both arguments were null
        NativeLibraryException - Internal unrecoverable error
    • Method Detail

      • close

        public void close()
                   throws NativeLibraryException
        Close the input/output files. This is done automatically when the object is finalized by Java, but the delay before this happens is unpredictable. For this reason it is better to close the file manually with this call. If any operation is attempted on the LDIF object after this call, an OperationFailedException will be thrown.
        Throws:
        NativeLibraryException - Internal unrecoverable error
      • setAllowUnknownAttrs

        public void setAllowUnknownAttrs​(boolean flag)
        Set the status of the 'allow unknown attributes' flag. With this flag set, unknown attributes found in the LDIF file won't be rejected with an error, but will be passed back with an 'octetstring' syntax. These unknown attributes can be written over LDAP or to LDIF files, but not sent over DAP.
        Parameters:
        flag - Allow unknown attributes?
      • getAllowUnknownAttrs

        public boolean getAllowUnknownAttrs()
        Get the current 'allow unknown attributes' flag status.
        Returns:
        Allow unknown attributes?
      • putComment

        public void putComment​(java.lang.String str)
                        throws OperationFailedException,
                               NativeLibraryException
        Add a comment to the output LDIF file. The string may contain newlines to make a multi-line comment. The string "# " is added before each line to make it into an LDIF comment.
        Parameters:
        str - Comment string to write to LDIF output file
        Throws:
        OperationFailedException - Stream has been closed
        java.lang.NullPointerException - Argument is null
        NativeLibraryException - Internal unrecoverable error
      • entryToString

        public static java.lang.String entryToString​(GenericEntry entry)
                                              throws java.lang.NullPointerException,
                                                     BadEntryException,
                                                     BadDNException,
                                                     NativeLibraryException
        Convert a GenericEntry to an LDIF-encoded string. The encoded string consists of lines, each of which is terminated with the platform line-separator (e.g. "\r\n" on Windows).
        Parameters:
        entry - GenericEntry to convert
        Returns:
        LDIF-encoding of the entry as a string
        Throws:
        java.lang.NullPointerException - Argument is null
        BadEntryException - The entry could not be converted to LDIF format
        BadDNException - The DN could not be converted to LDIF format
        NativeLibraryException - Internal unrecoverable error
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Releases any native structures associated with this object.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • toString

        public java.lang.String toString()
        Returns a String representation of the LDIF stream
        Overrides:
        toString in class java.lang.Object
        Returns:
        String representation of the LDIF stream