Makefile.am: Added URLDecoder and URLEncoder.
* Makefile.am: Added URLDecoder and URLEncoder. * Makefile.in: Rebuilt. * java/net/ServerSocket.java (setSocketFactory): Renamed from setSocketImplFactory to match spec. * java/net/Socket.java (getSoLinger): Changed return type to match spec. * java/net/URLDecoder.java: New file. * java/net/URLEncoder.java: New file. From-SVN: r26605
This commit is contained in:
parent
d2692ef86e
commit
12571b1f96
8 changed files with 146 additions and 5 deletions
48
libjava/java/net/URLDecoder.java
Normal file
48
libjava/java/net/URLDecoder.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
// URLDecoder.java - Provides a method for decoding strings according to
|
||||
// application/x-www-form-urlencoded MIME type.
|
||||
|
||||
/* Copyright (C) 1999 Cygnus Solutions
|
||||
|
||||
This file is part of libgcj.
|
||||
|
||||
This software is copyrighted work licensed under the terms of the
|
||||
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
||||
details. */
|
||||
|
||||
package java.net;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* @author Warren Levy <warrenl@cygnus.com>
|
||||
* @date April 22, 1999.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Written using on-line Java Platform 1.2 API Specification.
|
||||
* Status: Believed complete and correct.
|
||||
*/
|
||||
|
||||
// JDK1.2
|
||||
public class URLDecoder
|
||||
{
|
||||
// This method, per the JCL, is conservative in that it encodes
|
||||
// some "allowable" characters as % triplets.
|
||||
public static String decode(String s) throws Exception
|
||||
{
|
||||
String str = s.replace('+', ' ');
|
||||
String result = "";
|
||||
int i;
|
||||
int start = 0;
|
||||
while ((i = str.indexOf('%', start)) >= 0)
|
||||
{
|
||||
result = result + str.substring(start, i) +
|
||||
(char) Integer.parseInt(str.substring(i + 1, i + 3), 16);
|
||||
start = i + 3;
|
||||
}
|
||||
|
||||
if (start < str.length())
|
||||
result = result + str.substring(start);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue