Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
org.apache.commons.codec.net.URLCodec Example
What is org.apache.commons.codec.net.URLCodec class? How to use org.apache.commons.codec.net.URLCodec class?
✍: FYIcenter.com
org.apache.commons.codec.net.URLCodec class is a Java class
offered in commons-codec.jar that
implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding.
This class is meant to be a replacement for standard Java classes URLEncoder and URLDecoder on older Java platforms, as these classes in Java versions below 1.4 rely on the platform's default charset encoding.
Two commonly used instance methods in org.apache.commons.codec.net.URLCodec class are:
1. The encoding method:
public String encode(String str) throws EncoderException
Encodes a string into its URL safe form using the default string charset.
Unsafe characters are escaped.
Specified by:
encode in interface StringEncoder
Parameters:
str - string to convert to a URL safe form
Returns:
URL safe string
Throws:
EncoderException - Thrown if URL encoding is unsuccessful
2. The decoding method:
public String decode(String str) throws DecoderException
Decodes a URL safe string into its original form using the default
string charset. Escaped characters are converted back to their original
representation.
Specified by:
decode in interface StringDecoder
Parameters:
str - URL safe string to convert into its original form
Returns:
original string
Throws:
DecoderException - Thrown if URL decoding is unsuccessful
Here is a simple example of org.apache.commons.codec.net.URLCodec class:
// Copyright (c) 2016 FYIcenter.com
import org.apache.commons.codec.net.URLCodec;
// Example of using the URLCodec class
public class URLCodecExample {
public static void main(String[] args) throws Exception {
URLCodec codec = new URLCodec();
System.out.println("encode() Example:");
String inputString = "2_What Is activation.jar?.html";
String outputString = codec.encode(inputString);
String expectedString = "2_What+Is+activation.jar%3F.html";
System.out.println(" Input string: "+inputString);
System.out.println(" Encoded string: "+outputString);
System.out.println(" Expected string: "+expectedString);
System.out.println("decode() Example:");
inputString = "2_What+Is+activation.jar%3F.html";
outputString = codec.decode(inputString);
expectedString = "2_What Is activation.jar?.html";
System.out.println(" Input string: "+inputString);
System.out.println(" Encoded string: "+outputString);
System.out.println(" Expected string: "+expectedString);
}
}
You can compile and run the above example in a command window as shown below:
C:\fyicenter>\local\jdk-1.8.0\bin\javac -cp C:\local\commons-codec-1.10\commons-codec-1.10.jar URLCodecExample.java C:\fyicenter>\local\jdk-1.8.0\bin\java -cp .;C:\local\commons-codec-1.10\commons-codec-1.10.jar URLCodecExample encode() Example: Input string: 2_What Is activation.jar?.html Encoded string: 2_What+Is+activation.jar%3F.html Expected string: 2_What+Is+activation.jar%3F.html decode() Example: Input string: 2_What+Is+activation.jar%3F.html Encoded string: 2_What Is activation.jar?.html Expected string: 2_What Is activation.jar?.html
⇒ FAQ for Apache Commons Codec JAR Library
⇐ org.apache.commons.codec.digest.DigestUtils Example
2017-04-22, ∼2960🔥, 0💬
Popular Posts:
What Is mail.jar of JavaMail 1.3? I got the JAR file from javamail-1_3.zip. mail.jar in javamail-1_3...
Java Servlet API 4.0.1 Source Code Files are important if you want to compile them with different JD...
Apache Avalon began in 1999 as the Java Apache Server Framework and in late 2002 separated from the ...
The Web Services Description Language for Java Toolkit (WSDL4J), Release 1.6.2, allows the creation,...
JDK 11 jdk.scripting.nashorn.jm odis the JMOD file for JDK 11 Scripting Nashorn module. JDK 11 Scrip...