1 7 8 package javax.naming.ldap; 9 10 import java.io.IOException ; 11 import com.sun.jndi.ldap.Ber; 12 import com.sun.jndi.ldap.BerEncoder; 13 14 95 final public class PagedResultsControl extends BasicControl { 96 97 101 public static final String OID = "1.2.840.113556.1.4.319"; 102 103 private static final byte[] EMPTY_COOKIE = new byte[0]; 104 105 private static final long serialVersionUID = 6684806685736844298L; 106 107 120 public PagedResultsControl(int pageSize, boolean criticality) 121 throws IOException { 122 123 super(OID, criticality, null); 124 value = setEncodedValue(pageSize, EMPTY_COOKIE); 125 } 126 127 146 public PagedResultsControl(int pageSize, byte[] cookie, 147 boolean criticality) throws IOException { 148 149 super(OID, criticality, null); 150 if (cookie == null) { 151 cookie = EMPTY_COOKIE; 152 } 153 value = setEncodedValue(pageSize, cookie); 154 } 155 156 167 private byte[] setEncodedValue(int pageSize, byte[] cookie) 168 throws IOException { 169 170 BerEncoder ber = new BerEncoder(10 + cookie.length); 172 173 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR); 174 ber.encodeInt(pageSize); 175 ber.encodeOctetString(cookie, Ber.ASN_OCTET_STR); 176 ber.endSeq(); 177 178 return ber.getTrimmedBuf(); 179 } 180 } 181 | Popular Tags |