Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main {
    private final static String ENCODE = "UTF-8";

    /**
     * unreserved characters (ALPHA / DIGIT / "-" / "." / "_" / "~") MUST not be encoded, 
     * others MUST be encoded.
     * @param str
     * @return percent encoding defined in RFC 5849 3.6. Percent Encoding
     */
    private static String oauthEncode(String str) {
        try {
            return URLEncoder.encode(str, ENCODE).replace("*", "%2A").replace("%7E", "~").replace("+", "%20");
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }
}