Java Resource File parseASX(String inputResource)

Here you can find the source of parseASX(String inputResource)

Description

parse ASX

License

Open Source License

Declaration

private static String parseASX(String inputResource) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    private static String parseASX(String inputResource) {
        String inputFile = "";
        try {/*w  w w . j  a  va  2  s.  c om*/
            String contents = readTextFromUrl(new URL(inputResource));
            for (String line : contents.split("\n")) {
                if (line.toLowerCase().contains("href")) {
                    String pattern = "(?i).*href=\"(.*)\".*";
                    inputFile = line.replaceAll(pattern, "$1");
                    break;
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return inputFile;
    }

    /**
     * Return the text of the file with the given URL. E.g. if
     * http://test.be/text.txt is given the contents of text.txt is returned.
     * 
     * @param url
     *            The URL.
     * @return The contents of the file.
     */
    public static String readTextFromUrl(URL url) {
        StringBuffer fubber = new StringBuffer();
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                fubber.append(inputLine).append("\n");
            }
            in.close();
        } catch (IOException exception) {
            exception.printStackTrace();
        }
        return fubber.toString();
    }
}

Related

  1. isFullIRI(String resource)
  2. loadAutoConfigFiles(ClassLoader classLoader, String resourceName)
  3. loadConfigFile(String resource, Class clazz)
  4. loadUTF8(String resource)
  5. openInputStream(String resourceString, ClassLoader classLoader)
  6. printUsage(ResourceBundle bundle)
  7. put(String resource, Map headers, String data)
  8. resourceExists(String s)
  9. runtimeResourceLocation(String src)