Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

public class Main {
    /**
     * Make a list of all URL's that can be found in a string.
     * @param aSource  A string, possibly containing URL's.
     * @return A List of URL's that could be scraped from the string.
     */
    public static java.util.List<String> extractUrl(String aSource) {
        final String lPrefix = "http://";
        final java.util.List<String> lResult = new ArrayList<String>();
        String lTodo = aSource;
        int lUrlPos = lTodo.indexOf(lPrefix);
        while (lUrlPos >= 0) {
            lUrlPos += lPrefix.length();
            StringBuilder lUrlBuf = new StringBuilder();
            while ((lUrlPos < lTodo.length()) && lTodo.charAt(lUrlPos) != '\n'
                    && !Character.isSpaceChar(lTodo.charAt(lUrlPos)))
                lUrlBuf.append(lTodo.charAt(lUrlPos++));
            lResult.add(lUrlBuf.toString());

            if (lUrlPos < lTodo.length())
                lTodo = lTodo.substring(lUrlPos);
            else
                lTodo = "";
            lUrlPos = lTodo.indexOf(lPrefix);
        }
        return lResult;
    }
}