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.URLDecoder;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    /**
     * ####
     * Methods to convert params to URL encoded form
     */
    private static final String UTF_8 = "UTF-8";

    public static String extract(String response, Pattern p) {
        Matcher matcher = p.matcher(response);
        if (matcher.find() && matcher.groupCount() >= 1) {
            try {
                return URLDecoder.decode(matcher.group(1), UTF_8);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        throw new RuntimeException(
                "Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null);

    }
}