Class MakeLDIFInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable, EntryWriter

    public class MakeLDIFInputStream
    extends InputStream
    implements EntryWriter
    This class creates an input stream that can be used to read entries generated by MakeLDIF as if they were being read from another source like a file. It has a fixed-size queue that dictates how many entries may be held in memory at any given time.
    • Method Detail

      • newStartedInputStream

        public static MakeLDIFInputStream newStartedInputStream​(TemplateFile templateFile)
        Creates a new MakeLDIF input stream based on the provided template file and starts generating entries in the background.

        The generator thread is started here rather than by the constructor so that this is not published to it before construction has completed.

        Parameters:
        templateFile - The template file to use to generate the entries.
        Returns:
        A new input stream which has started generating entries.
      • read

        public int read()
                 throws IOException
        Reads a single byte of data from this input stream.
        Specified by:
        read in class InputStream
        Returns:
        The byte read from the input stream, or -1 if the end of the stream has been reached.
        Throws:
        IOException - If a problem has occurred while generating data for use by this input stream.
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws IOException
        Reads data from this input stream.
        Overrides:
        read in class InputStream
        Parameters:
        b - The array into which the data should be read.
        off - The position in the array at which point the data read may be placed.
        len - The maximum number of bytes that may be read into the provided array.
        Returns:
        The number of bytes read from the input stream into the provided array, or -1 if the end of the stream has been reached.
        Throws:
        IOException - If a problem has occurred while generating data for use by this input stream.
      • writeEntry

        public boolean writeEntry​(TemplateEntry entry)
                           throws IOException,
                                  MakeLDIFException
        Description copied from interface: EntryWriter
        Writes the provided entry to the appropriate target.
        Specified by:
        writeEntry in interface EntryWriter
        Parameters:
        entry - The entry to be written.
        Returns:
        true if the entry writer will accept additional entries, or false if no more entries should be written.
        Throws:
        IOException - If a problem occurs while writing the entry to its intended destination.
        MakeLDIFException - If some other problem occurs.
      • closeEntryWriter

        public void closeEntryWriter()
        Description copied from interface: EntryWriter
        Notifies the entry writer that no more entries will be provided and that any associated cleanup may be performed.
        Specified by:
        closeEntryWriter in interface EntryWriter