Path: blob/master/src/java.naming/share/classes/javax/naming/ldap/PagedResultsResponseControl.java
41159 views
/*1* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming.ldap;2627import java.io.IOException;28import com.sun.jndi.ldap.Ber;29import com.sun.jndi.ldap.BerDecoder;3031/**32* Indicates the end of a batch of search results.33* Contains an estimate of the total number of entries in the result set34* and an opaque cookie. The cookie must be supplied to the next search35* operation in order to get the next batch of results.36* <p>37* The code sample in {@link PagedResultsControl} shows how this class may38* be used.39* <p>40* This class implements the LDAPv3 Response Control for41* paged-results as defined in42* <a href="http://www.ietf.org/rfc/rfc2696">RFC 2696</a>.43*44* The control's value has the following ASN.1 definition:45* <pre>46*47* realSearchControlValue ::= SEQUENCE {48* size INTEGER (0..maxInt),49* -- requested page size from client50* -- result set size estimate from server51* cookie OCTET STRING52* }53*54* </pre>55*56* @since 1.557* @see PagedResultsControl58* @author Vincent Ryan59*/60public final class PagedResultsResponseControl extends BasicControl {6162/**63* The paged-results response control's assigned object identifier64* is 1.2.840.113556.1.4.319.65*/66public static final String OID = "1.2.840.113556.1.4.319";6768private static final long serialVersionUID = -8819778744844514666L;6970/**71* An estimate of the number of entries in the search result.72*73* @serial74*/75private int resultSize;7677/**78* A server-generated cookie.79*80* @serial81*/82private byte[] cookie;8384/**85* Constructs a paged-results response control.86*87* @param id The control's object identifier string.88* @param criticality The control's criticality.89* @param value The control's ASN.1 BER encoded value.90* It is not cloned - any changes to value91* will affect the contents of the control.92* @throws IOException If an error was encountered while decoding93* the control's value.94*/95public PagedResultsResponseControl(String id, boolean criticality,96byte[] value) throws IOException {9798super(id, criticality, value);99100// decode value101BerDecoder ber = new BerDecoder(value, 0, value.length);102103ber.parseSeq(null);104resultSize = ber.parseInt();105cookie = ber.parseOctetString(Ber.ASN_OCTET_STR, null);106}107108/**109* Retrieves (an estimate of) the number of entries in the search result.110*111* @return The number of entries in the search result, or zero if unknown.112*/113public int getResultSize() {114return resultSize;115}116117/**118* Retrieves the server-generated cookie. Null is returned when there are119* no more entries for the server to return.120*121* @return A possibly null server-generated cookie. It is not cloned - any122* changes to the cookie will update the control's state and thus123* are not recommended.124*/125public byte[] getCookie() {126if (cookie.length == 0) {127return null;128} else {129return cookie;130}131}132}133134135