From 498bb8e0bfadf239abc59586ff9adf2be0869436 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 13 Sep 2013 15:12:14 +0000
Subject: [PATCH] Backport fix for OPENDJ-1137: ConnectionEntryReader does not provide a means for accessing controls in the search result

---
 opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java b/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java
index fdfcf4d..a4e6261 100644
--- a/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java
+++ b/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java
@@ -87,6 +87,9 @@
  *       // Handle continuation reference...
  *     }
  *   }
+ *
+ *   Result result = reader.readResult();
+ *   // Handle controls included with the search result...
  * }
  * catch (IOException e)
  * {
@@ -359,6 +362,40 @@
         }
     }
 
+    /**
+     * Waits for the next search response to become available and returns it if
+     * it is a search result indicating that the search completed successfully.
+     * If the search result indicates that the search failed then an
+     * {@link ErrorResultIOException} is thrown. Otherwise, if the search
+     * response represents an entry or reference then an
+     * {@code IllegalStateException} is thrown.
+     * <p>
+     * This method should only be called if {@link #hasNext()} has, or will,
+     * return {@code false}.
+     * <p>
+     * It is not necessary to call this method once all search result entries
+     * have been processed, but it may be useful to do so in order to inspect
+     * any controls which were included with the result. For example, this
+     * method may be called in order to obtain the next paged results cookie
+     * once the current page of results has been processed.
+     *
+     * @return The search result indicating success.
+     * @throws ErrorResultIOException
+     *             If the search result indicates that the search operation
+     *             failed for some reason.
+     * @throws IllegalStateException
+     *             If there are remaining search result entries or references to
+     *             be processed. In other words, if {@link #hasNext()} would
+     *             return {@code true}.
+     */
+    public Result readResult() throws ErrorResultIOException {
+        if (hasNext()) {
+            throw new IllegalStateException();
+        } else {
+            return (Result) nextResponse;
+        }
+    }
+
     private Response getNextResponse() throws ErrorResultIOException {
         while (nextResponse == null) {
             try {

--
Gitblit v1.10.0