Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
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 (309)
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, 2071🔥, 0💬
Popular Posts:
JDK 11 java.management.jmod is the JMOD file for JDK 11 Management module. JDK 11 Management module ...
commons-collections4-4.2 -sources.jaris the source JAR file for Apache Commons Collections 4.2, whic...
JDK 17 java.xml.jmod is the JMOD file for JDK 17 XML (eXtensible Markup Language) module. JDK 17 XML...
Commons VFS provides a single API for accessing various different file systems. It presents a unifor...
Apache BCEL Source Code Files are inside the Apache BCEL source package file like bcel-6.6.1-src.zip...