Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Mozilla Public License 

import android.net.Uri;

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    /**
     * Test whether a {@link URL} is a Tor Hidden Service host name, also known
     * as an ".onion address".
     *
     * @return whether the host name is a Tor .onion address
     */
    public static boolean isOnionAddress(URL url) {
        return url.getHost().endsWith(".onion");
    }

    /**
     * Test whether a URL {@link String} is a Tor Hidden Service host name, also known
     * as an ".onion address".
     *
     * @return whether the host name is a Tor .onion address
     */
    public static boolean isOnionAddress(String urlString) {
        try {
            return isOnionAddress(new URL(urlString));
        } catch (MalformedURLException e) {
            return false;
        }
    }

    /**
     * Test whether a {@link Uri} is a Tor Hidden Service host name, also known
     * as an ".onion address".
     *
     * @return whether the host name is a Tor .onion address
     */
    public static boolean isOnionAddress(Uri uri) {
        return uri.getHost().endsWith(".onion");
    }
}