URLEncodedUtils.java (httpcomponents-client-4.5.6-src) | : | URLEncodedUtils.java (httpcomponents-client-4.5.7-src) | ||
---|---|---|---|---|
skipping to change at line 75 | skipping to change at line 75 | |||
*/ | */ | |||
public static final String CONTENT_TYPE = "application/x-www-form-urlencoded "; | public static final String CONTENT_TYPE = "application/x-www-form-urlencoded "; | |||
private static final char QP_SEP_A = '&'; | private static final char QP_SEP_A = '&'; | |||
private static final char QP_SEP_S = ';'; | private static final char QP_SEP_S = ';'; | |||
private static final String NAME_VALUE_SEPARATOR = "="; | private static final String NAME_VALUE_SEPARATOR = "="; | |||
/** | /** | |||
* @deprecated 4.5 Use {@link #parse(URI, Charset)} | * @deprecated 4.5 Use {@link #parse(URI, Charset)} | |||
*/ | */ | |||
@Deprecated | ||||
public static List <NameValuePair> parse(final URI uri, final String charset Name) { | public static List <NameValuePair> parse(final URI uri, final String charset Name) { | |||
return parse(uri, charsetName != null ? Charset.forName(charsetName) : n ull); | return parse(uri, charsetName != null ? Charset.forName(charsetName) : n ull); | |||
} | } | |||
/** | /** | |||
* Returns a list of {@link NameValuePair NameValuePairs} as built from the URI's query portion. For example, a URI | * Returns a list of {@link NameValuePair NameValuePairs} as built from the URI's query portion. For example, a URI | |||
* of {@code http://example.org/path/to/file?a=1&b=2&c=3} would return a lis t of three NameValuePairs, one for a=1, | * of {@code http://example.org/path/to/file?a=1&b=2&c=3} would return a lis t of three NameValuePairs, one for a=1, | |||
* one for b=2, and one for c=3. By convention, {@code '&'} and {@code ';'} are accepted as parameter separators. | * one for b=2, and one for c=3. By convention, {@code '&'} and {@code ';'} are accepted as parameter separators. | |||
* <p> | * <p> | |||
* This is typically useful while parsing an HTTP PUT. | * This is typically useful while parsing an HTTP PUT. | |||
skipping to change at line 127 | skipping to change at line 128 | |||
public static List <NameValuePair> parse( | public static List <NameValuePair> parse( | |||
final HttpEntity entity) throws IOException { | final HttpEntity entity) throws IOException { | |||
Args.notNull(entity, "HTTP entity"); | Args.notNull(entity, "HTTP entity"); | |||
final ContentType contentType = ContentType.get(entity); | final ContentType contentType = ContentType.get(entity); | |||
if (contentType == null || !contentType.getMimeType().equalsIgnoreCase(C ONTENT_TYPE)) { | if (contentType == null || !contentType.getMimeType().equalsIgnoreCase(C ONTENT_TYPE)) { | |||
return createEmptyList(); | return createEmptyList(); | |||
} | } | |||
final long len = entity.getContentLength(); | final long len = entity.getContentLength(); | |||
Args.check(len <= Integer.MAX_VALUE, "HTTP entity is too large"); | Args.check(len <= Integer.MAX_VALUE, "HTTP entity is too large"); | |||
final Charset charset = contentType.getCharset() != null ? contentType.g etCharset() : HTTP.DEF_CONTENT_CHARSET; | final Charset charset = contentType.getCharset() != null ? contentType.g etCharset() : HTTP.DEF_CONTENT_CHARSET; | |||
final InputStream instream = entity.getContent(); | final InputStream inStream = entity.getContent(); | |||
if (instream == null) { | if (inStream == null) { | |||
return createEmptyList(); | return createEmptyList(); | |||
} | } | |||
final CharArrayBuffer buf; | final CharArrayBuffer buf; | |||
try { | try { | |||
buf = new CharArrayBuffer(len > 0 ? (int) len : 1024); | buf = new CharArrayBuffer(len > 0 ? (int) len : 1024); | |||
final Reader reader = new InputStreamReader(instream, charset); | final Reader reader = new InputStreamReader(inStream, charset); | |||
final char[] tmp = new char[1024]; | final char[] tmp = new char[1024]; | |||
int l; | int l; | |||
while((l = reader.read(tmp)) != -1) { | while((l = reader.read(tmp)) != -1) { | |||
buf.append(tmp, 0, l); | buf.append(tmp, 0, l); | |||
} | } | |||
} finally { | } finally { | |||
instream.close(); | inStream.close(); | |||
} | } | |||
if (buf.length() == 0) { | if (buf.isEmpty()) { | |||
return createEmptyList(); | return createEmptyList(); | |||
} | } | |||
return parse(buf, charset, QP_SEP_A); | return parse(buf, charset, QP_SEP_A); | |||
} | } | |||
/** | /** | |||
* Returns true if the entity's Content-Type header is | * Returns true if the entity's Content-Type header is | |||
* {@code application/x-www-form-urlencoded}. | * {@code application/x-www-form-urlencoded}. | |||
*/ | */ | |||
public static boolean isEncoded(final HttpEntity entity) { | public static boolean isEncoded(final HttpEntity entity) { | |||
skipping to change at line 308 | skipping to change at line 309 | |||
final List<NameValuePair> list = new ArrayList<NameValuePair>(); | final List<NameValuePair> list = new ArrayList<NameValuePair>(); | |||
while (!cursor.atEnd()) { | while (!cursor.atEnd()) { | |||
delimSet.set('='); | delimSet.set('='); | |||
final String name = tokenParser.parseToken(buf, cursor, delimSet); | final String name = tokenParser.parseToken(buf, cursor, delimSet); | |||
String value = null; | String value = null; | |||
if (!cursor.atEnd()) { | if (!cursor.atEnd()) { | |||
final int delim = buf.charAt(cursor.getPos()); | final int delim = buf.charAt(cursor.getPos()); | |||
cursor.updatePos(cursor.getPos() + 1); | cursor.updatePos(cursor.getPos() + 1); | |||
if (delim == '=') { | if (delim == '=') { | |||
delimSet.clear('='); | delimSet.clear('='); | |||
value = tokenParser.parseValue(buf, cursor, delimSet); | value = tokenParser.parseToken(buf, cursor, delimSet); | |||
if (!cursor.atEnd()) { | if (!cursor.atEnd()) { | |||
cursor.updatePos(cursor.getPos() + 1); | cursor.updatePos(cursor.getPos() + 1); | |||
} | } | |||
} | } | |||
} | } | |||
if (!name.isEmpty()) { | if (!name.isEmpty()) { | |||
list.add(new BasicNameValuePair( | list.add(new BasicNameValuePair( | |||
decodeFormFields(name, charset), | decodeFormFields(name, charset), | |||
decodeFormFields(value, charset))); | decodeFormFields(value, charset))); | |||
} | } | |||
End of changes. 6 change blocks. | ||||
6 lines changed or deleted | 7 lines changed or added |