code: public final void dump(final LDAPInterface connection,
                             final String base,
                             final String filter,
                             final OutputStream outputStream,
                             final FormatLogger logger) {
          final FormatWriter ldapWriter = createWriter(outputStream, logger);
          if (ldapWriter == null) {
              logger.logError("Error creating writer for output stream");
          } else {
              try {
                  try {
                      final SearchRequest request = new SearchRequest(base, SearchScope.SUB, Filter.create(filter));
                      final SearchResult result = connection.search(request);
                      if (result.getResultCode() == ResultCode.SUCCESS) {
                          final List<SearchResultEntry> entries = result.getSearchEntries();
                          if (entries != null) {
                              for (final SearchResultEntry entry : entries) {
                                  ldapWriter.printEntry(entry);
                              }
                          } else {
                              logger.logInfo("Search did not return any directory entries");
                          }
                      } else {
                          logger.logError("Search operation failed");
                      }
                  } catch (final LDAPException e) {
                      logger.logError("Error searching the LDAP directory", e);
                  } finally {
                      ldapWriter.close();
                  }
              } catch (final IOException e) {
                  logger.logError("Error writing directory entry to the output stream", e);
              }
          }
      }
docs: Dump the results of a search against the LDAP directory server to an output stream.
  
  @param connection   The connection to the LDAP directory server.
  @param base         The base DN from which to start the search.
  @param filter       Query used to filter the directory entries.
  @param outputStream The output stream to which the directory entries are to be written.
  @param logger       Used to log information or error messages.