< prev index next >

src/java.base/share/classes/java/net/HttpCookie.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 132      *          if the cookie name contains illegal characters
 133      * @throws  NullPointerException
 134      *          if {@code name} is {@code null}
 135      *
 136      * @see #setValue
 137      * @see #setVersion
 138      */
 139     public HttpCookie(String name, String value) {
 140         this(name, value, null /*header*/);
 141     }
 142 
 143     private HttpCookie(String name, String value, String header) {
 144         this(name, value, header, System.currentTimeMillis());
 145     }
 146 
 147     /**
 148      * Package private for testing purposes.
 149      */
 150     HttpCookie(String name, String value, String header, long creationTime) {
 151         name = name.trim();
 152         if (name.length() == 0 || !isToken(name) || name.charAt(0) == '$') {
 153             throw new IllegalArgumentException("Illegal cookie name");
 154         }
 155 
 156         this.name = name;
 157         this.value = value;
 158         toDiscard = false;
 159         secure = false;
 160 
 161         whenCreated = creationTime;
 162         portlist = null;
 163         this.header = header;
 164     }
 165 
 166     /**
 167      * Constructs cookies from set-cookie or set-cookie2 header string.
 168      * RFC 2965 section 3.2.2 set-cookie2 syntax indicates that one header line
 169      * may contain more than one cookie definitions, so this is a static
 170      * utility method instead of another constructor.
 171      *
 172      * @param  header




 132      *          if the cookie name contains illegal characters
 133      * @throws  NullPointerException
 134      *          if {@code name} is {@code null}
 135      *
 136      * @see #setValue
 137      * @see #setVersion
 138      */
 139     public HttpCookie(String name, String value) {
 140         this(name, value, null /*header*/);
 141     }
 142 
 143     private HttpCookie(String name, String value, String header) {
 144         this(name, value, header, System.currentTimeMillis());
 145     }
 146 
 147     /**
 148      * Package private for testing purposes.
 149      */
 150     HttpCookie(String name, String value, String header, long creationTime) {
 151         name = name.trim();
 152         if (name.isEmpty() || !isToken(name) || name.charAt(0) == '$') {
 153             throw new IllegalArgumentException("Illegal cookie name");
 154         }
 155 
 156         this.name = name;
 157         this.value = value;
 158         toDiscard = false;
 159         secure = false;
 160 
 161         whenCreated = creationTime;
 162         portlist = null;
 163         this.header = header;
 164     }
 165 
 166     /**
 167      * Constructs cookies from set-cookie or set-cookie2 header string.
 168      * RFC 2965 section 3.2.2 set-cookie2 syntax indicates that one header line
 169      * may contain more than one cookie definitions, so this is a static
 170      * utility method instead of another constructor.
 171      *
 172      * @param  header


< prev index next >