code: public static Cookie[] getCookies(final URI url, final CookieStore cookieStore, final int cookieMaxByteSize) {
  		int overallLength = 0, i = 0;
  		final List<Cookie> cookies = cookieStore.getCookies();
  		for (final Cookie cookie : cookies) {
  			/* Just an approximation, and doesn't take attributes into account, but
  			 * there is no way to enumerate the attributes of a cookie. */
  			overallLength += length(cookie.getName());
  			overallLength += length(cookie.getValue());
  			overallLength += length(cookie.getDomain());
  			overallLength += length(cookie.getPath());
  			if (overallLength > cookieMaxByteSize) {
  				LOGGER.warn("URL " + url + " returned too large cookies (" + overallLength + " characters)");
  				return cookies.subList(0, i).toArray(new Cookie[i]);
  			}
  			i++;
  		}
  		return cookies.toArray(new Cookie[cookies.size()]);
  	}
docs: Returns the list of cookies in a given store in the form of an array, limiting their overall size
  (only the maximal prefix of cookies satisfying the size limit is returned). Note that the size limit is expressed
  in bytes, but the actual memory footprint is larger because of object overheads and because strings
  are made of 16-bits characters. Moreover, cookie attributes are not measured when evaluating size.
  
  @param url the URL which generated the cookies (for logging purposes).
  @param cookieStore a cookie store, usually generated by a response.
  @param cookieMaxByteSize the maximum overall size of cookies in bytes.
  @return the list of cookies in a given store in the form of an array, with limited overall size.