Example usage for java.net URL openStream

List of usage examples for java.net URL openStream

Introduction

In this page you can find the example usage for java.net URL openStream.

Prototype

public final InputStream openStream() throws java.io.IOException 

Source Link

Document

Opens a connection to this URL and returns an InputStream for reading from that connection.

Usage

From source file:com.gs.obevo.api.platform.ToolVersion.java

public static synchronized String getToolVersion() {
    if (TOOL_VERSION == null) {

        Properties props = new Properties();
        try {/*www .ja  v a2 s  .c o  m*/
            URL resource = Validate.notNull(ToolVersion.class.getClassLoader().getResource(PROPERTY_PATH),
                    "Could not read the required propertyPath: " + PROPERTY_PATH);
            props.load(resource.openStream());
        } catch (IOException e) {
            throw new RuntimeException("Could not open the required propertyPath: " + PROPERTY_PATH, e);
        }
        TOOL_VERSION = props.getProperty("tool.version");
    }

    return TOOL_VERSION;
}

From source file:com.uksf.mf.core.utility.ClassNames.java

/**
 * Gets class names from file on uksf server
 * @return map of class names: old, new//from  w w w.ja  va 2 s.c o m
 */
public static LinkedHashMap<String, String> getClassNames() {
    LinkedHashMap<String, String> classNames = new LinkedHashMap<>();
    try {
        URL url = new URL("http://www.uk-sf.com/mf/CLASSES.txt");
        if (checkConnection(url)) {
            throw new IOException();
        }
        InputStream stream = url.openStream();
        List<String> lines = IOUtils.readLines(stream, "UTF-8");
        for (String line : lines) {
            String parts[] = line.split(",", -1);
            if (parts[1] == null)
                parts[1] = "";
            classNames.put(parts[0], parts[1]);
        }
    } catch (IOException e) {
        LogHandler.logSeverity(WARNING, "Cannot reach 'www.uk-sf.com', class name swap will not run");
        return null;
    }
    return classNames;
}

From source file:Main.java

/**
 * This is a convenience method to load a resource as a stream. <p/> The
 * algorithm used to find the resource is given in getResource()
 * /* www  .  j a  v a2s . c o  m*/
 * @param resourceName The name of the resource to load
 * @param callingClass The Class object of the calling object
 */
public static InputStream getResourceAsStream(String resourceName, Class callingClass) {
    URL url = getResource(resourceName, callingClass);

    try {
        return (url != null) ? url.openStream() : null;
    } catch (IOException e) {
        return null;
    }
}

From source file:com.ms.commons.test.classloader.util.CLFileUtil.java

public static String readUrlToString(URL url, String encoding) throws IOException {
    if (url == null) {
        return null;
    }//from  w  w w. j  a v a 2  s.  c om
    InputStream in = null;
    try {
        in = url.openStream();
        return IOUtils.toString(in, encoding);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.apache.cxf.transport.https.httpclient.PublicSuffixMatcherLoader.java

public static PublicSuffixMatcher load(final URL url) throws IOException {
    if (url == null) {
        throw new IllegalArgumentException("URL is null");
    }//  w w w. j  a v a 2 s  .  c  om
    try (InputStream in = url.openStream()) {
        return load(in);
    }
}

From source file:cloudclient.Client.java

public static String getIP() throws MalformedURLException {
    //Get external ip of the client                 
    String ip = null;/* w w w . j a  v a  2 s.  c  om*/

    URL whatismyip = new URL("http://checkip.amazonaws.com");
    try {
        BufferedReader in_ip = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
        ip = in_ip.readLine();

    } catch (IOException e1) {
        e1.printStackTrace();
    }

    return ip;

}

From source file:com.reprezen.kaizen.oasparser.jsonoverlay.JsonLoader.java

public static JsonNode load(URL url) throws IOException {
    String urlString = url.toString();
    if (cache.containsKey(urlString)) {
        return cache.get(urlString);
    }//  w w  w  .  jav  a  2s .  c  o  m
    String json = IOUtils.toString(url.openStream(), Charsets.UTF_8);
    return loadString(url, json);
}

From source file:eu.delving.test.TestCodeGeneration.java

private static RecDefModel recDefModel() {
    return new RecDefModel() {
        @Override//from  w ww.j a  v a2  s .  c  om
        public RecDefTree createRecDefTree(SchemaVersion schemaVersion) {
            if (!"test".equals(schemaVersion.getPrefix()))
                throw new RuntimeException();
            try {
                URL url = TestCodeGeneration.class.getResource("/codegen/TestCodeGeneration-recdef.xml");
                InputStream inputStream = url.openStream();
                return RecDefTree.create(RecDef.read(inputStream));
            } catch (Exception e) {
                throw new RuntimeException("Unable to load recdef", e);
            }
        }
    };
}

From source file:MainClass.java

private static void parse(URL url, String encoding) throws IOException {
    ParserGetter kit = new ParserGetter();
    HTMLEditorKit.Parser parser = kit.getParser();
    InputStream in = url.openStream();
    InputStreamReader r = new InputStreamReader(in, encoding);
    HTMLEditorKit.ParserCallback callback = new Outliner(new OutputStreamWriter(System.out));
    parser.parse(r, callback, true);//w ww.ja  v  a2  s. c o m
}

From source file:edu.vt.middleware.ldap.LdapUtil.java

/**
 * Reads the data at the supplied URL and returns it as a byte array.
 *
 * @param  url  to read//from ww  w.  jav a 2 s  . co m
 *
 * @return  bytes read from the URL
 *
 * @throws  IOException  if an error occurs reading data
 */
public static byte[] readURL(final URL url) throws IOException {
    return readInputStream(url.openStream());
}