Android Open Source - Simple-Dilbert Find Urls

From Project

Back to project page Simple-Dilbert.


The source code is released under:

Apache License

If you think the Android project Simple-Dilbert listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mareksebera.simpledilbert.utilities;
//from  www. ja  v  a  2s  .c om
import android.util.Log;

import com.mareksebera.simpledilbert.preferences.DilbertPreferences;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.joda.time.LocalDate;

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

final public class FindUrls {
    private static final String LOG_TAG = "FindUrls";

    private FindUrls() {

    private static final Pattern url_match_pattern = Pattern

    private static final Pattern date_match_pattern = Pattern

    public static String extractUrls(HttpResponse response) {
        String found = null;
        try {
            Scanner scan;
            Header contentEncoding = response
            if (contentEncoding != null
                    && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                scan = new Scanner(new GZIPInputStream(response.getEntity()
            } else {
                scan = new Scanner(response.getEntity().getContent());

            found = scan.findWithinHorizon(url_match_pattern, 0);
            if (null != found) {
                Matcher m = url_match_pattern.matcher(found);
                if (m.matches())
                    found =;
        } catch (Throwable t) {
            Log.e(LOG_TAG, "Error Occurred", t);
        return found;

    public static LocalDate extractCurrentDateFromIntentUrl(Uri path) {
        try {
            Matcher m = date_match_pattern.matcher(path.toString());
            if (m.matches()) {
                return LocalDate.parse(, DilbertPreferences.DATE_FORMATTER);
        } catch (Throwable t) {
            Log.e(LOG_TAG, "extractCurrentDateFromIntentUrl failed", t);
        return null;

Java Source Code List