Methods Summary |
---|
protected void | doFormatValue(org.apache.http.util.CharArrayBuffer buffer, java.lang.String value, boolean quote)Actually formats the value of a name-value pair.
This does not include a leading = character.
Called from {@link #formatNameValuePair formatNameValuePair}.
if (!quote) {
for (int i = 0; (i < value.length()) && !quote; i++) {
quote = isSeparator(value.charAt(i));
}
}
if (quote) {
buffer.append('"");
}
for (int i = 0; i < value.length(); i++) {
char ch = value.charAt(i);
if (isUnsafe(ch)) {
buffer.append('\\");
}
buffer.append(ch);
}
if (quote) {
buffer.append('"");
}
|
protected int | estimateElementsLen(org.apache.http.HeaderElement[] elems)Estimates the length of formatted header elements.
if ((elems == null) || (elems.length < 1))
return 0;
int result = (elems.length-1) * 2; // elements separated by ", "
for (int i=0; i<elems.length; i++) {
result += estimateHeaderElementLen(elems[i]);
}
return result;
|
protected int | estimateHeaderElementLen(org.apache.http.HeaderElement elem)Estimates the length of a formatted header element.
if (elem == null)
return 0;
int result = elem.getName().length(); // name
final String value = elem.getValue();
if (value != null) {
// assume quotes, but no escaped characters
result += 3 + value.length(); // ="value"
}
final int parcnt = elem.getParameterCount();
if (parcnt > 0) {
for (int i=0; i<parcnt; i++) {
result += 2 + // ; <param>
estimateNameValuePairLen(elem.getParameter(i));
}
}
return result;
|
protected int | estimateNameValuePairLen(org.apache.http.NameValuePair nvp)Estimates the length of a formatted name-value pair.
if (nvp == null)
return 0;
int result = nvp.getName().length(); // name
final String value = nvp.getValue();
if (value != null) {
// assume quotes, but no escaped characters
result += 3 + value.length(); // ="value"
}
return result;
|
protected int | estimateParametersLen(org.apache.http.NameValuePair[] nvps)Estimates the length of formatted parameters.
if ((nvps == null) || (nvps.length < 1))
return 0;
int result = (nvps.length-1) * 2; // "; " between the parameters
for (int i=0; i<nvps.length; i++) {
result += estimateNameValuePairLen(nvps[i]);
}
return result;
|
public static final java.lang.String | formatElements(org.apache.http.HeaderElement[] elems, boolean quote, org.apache.http.message.HeaderValueFormatter formatter)Formats an array of header elements.
// public default constructor
if (formatter == null)
formatter = BasicHeaderValueFormatter.DEFAULT;
return formatter.formatElements(null, elems, quote).toString();
|
public org.apache.http.util.CharArrayBuffer | formatElements(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.HeaderElement[] elems, boolean quote)
if (elems == null) {
throw new IllegalArgumentException
("Header element array must not be null.");
}
int len = estimateElementsLen(elems);
if (buffer == null) {
buffer = new CharArrayBuffer(len);
} else {
buffer.ensureCapacity(len);
}
for (int i=0; i<elems.length; i++) {
if (i > 0) {
buffer.append(", ");
}
formatHeaderElement(buffer, elems[i], quote);
}
return buffer;
|
public static final java.lang.String | formatHeaderElement(org.apache.http.HeaderElement elem, boolean quote, org.apache.http.message.HeaderValueFormatter formatter)Formats a header element.
if (formatter == null)
formatter = BasicHeaderValueFormatter.DEFAULT;
return formatter.formatHeaderElement(null, elem, quote).toString();
|
public org.apache.http.util.CharArrayBuffer | formatHeaderElement(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.HeaderElement elem, boolean quote)
if (elem == null) {
throw new IllegalArgumentException
("Header element must not be null.");
}
int len = estimateHeaderElementLen(elem);
if (buffer == null) {
buffer = new CharArrayBuffer(len);
} else {
buffer.ensureCapacity(len);
}
buffer.append(elem.getName());
final String value = elem.getValue();
if (value != null) {
buffer.append('=");
doFormatValue(buffer, value, quote);
}
final int parcnt = elem.getParameterCount();
if (parcnt > 0) {
for (int i=0; i<parcnt; i++) {
buffer.append("; ");
formatNameValuePair(buffer, elem.getParameter(i), quote);
}
}
return buffer;
|
public static final java.lang.String | formatNameValuePair(org.apache.http.NameValuePair nvp, boolean quote, org.apache.http.message.HeaderValueFormatter formatter)Formats a name-value pair.
if (formatter == null)
formatter = BasicHeaderValueFormatter.DEFAULT;
return formatter.formatNameValuePair(null, nvp, quote).toString();
|
public org.apache.http.util.CharArrayBuffer | formatNameValuePair(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.NameValuePair nvp, boolean quote)
if (nvp == null) {
throw new IllegalArgumentException
("NameValuePair must not be null.");
}
int len = estimateNameValuePairLen(nvp);
if (buffer == null) {
buffer = new CharArrayBuffer(len);
} else {
buffer.ensureCapacity(len);
}
buffer.append(nvp.getName());
final String value = nvp.getValue();
if (value != null) {
buffer.append('=");
doFormatValue(buffer, value, quote);
}
return buffer;
|
public static final java.lang.String | formatParameters(org.apache.http.NameValuePair[] nvps, boolean quote, org.apache.http.message.HeaderValueFormatter formatter)Formats a set of parameters.
if (formatter == null)
formatter = BasicHeaderValueFormatter.DEFAULT;
return formatter.formatParameters(null, nvps, quote).toString();
|
public org.apache.http.util.CharArrayBuffer | formatParameters(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.NameValuePair[] nvps, boolean quote)
if (nvps == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
int len = estimateParametersLen(nvps);
if (buffer == null) {
buffer = new CharArrayBuffer(len);
} else {
buffer.ensureCapacity(len);
}
for (int i = 0; i < nvps.length; i++) {
if (i > 0) {
buffer.append("; ");
}
formatNameValuePair(buffer, nvps[i], quote);
}
return buffer;
|
protected boolean | isSeparator(char ch)Checks whether a character is a {@link #SEPARATORS separator}.
return SEPARATORS.indexOf(ch) >= 0;
|
protected boolean | isUnsafe(char ch)Checks whether a character is {@link #UNSAFE_CHARS unsafe}.
return UNSAFE_CHARS.indexOf(ch) >= 0;
|