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.playonlinux.qt.common.ResourceHelper.java

/**
 * Load a pixmap from the given URL.//from ww  w  .  j  a  v  a  2  s .  c o  m
 * @param source URL to load the pixmap from
 * @return loaded Pixmap
 */
public static QPixmap getPixmap(URL source) {
    try {
        QBuffer sourceDev = getDeviceFromStream(source.openStream());
        QPixmap pixmap = new QPixmap();
        pixmap.loadFromData(sourceDev.data());
        return pixmap;
    } catch (IOException e) {
        LOGGER.error(e);
        return new QPixmap();
    }
}

From source file:com.servoy.j2db.server.ngclient.startup.resourceprovider.ComponentResourcesExporter.java

/**
 * @param path//from   ww  w . jav a2  s  . c  o m
 * @param tmpWarDir
 * @throws IOException 
 */
private static void copy(Enumeration<String> paths, File destDir) throws IOException {
    if (paths != null) {
        while (paths.hasMoreElements()) {
            String path = paths.nextElement();
            if (path.endsWith("/")) {
                File targetDir = new File(destDir,
                        FilenameUtils.getName(path.substring(0, path.lastIndexOf("/"))));
                copy(Activator.getContext().getBundle().getEntryPaths(path), targetDir);
            } else {
                URL entry = Activator.getContext().getBundle().getEntry(path);
                FileUtils.copyInputStreamToFile(entry.openStream(),
                        new File(destDir, FilenameUtils.getName(path)));
            }
        }
    }
}

From source file:GenerateWorkItems.java

private static void initTorque() {
    try {//from  w  w  w.ja  v  a2  s  .co m
        PropertiesConfiguration tcfg = new PropertiesConfiguration();
        URL torqueURL = GenerateWorkItems.class.getResource("/Torque.properties");
        InputStream in = torqueURL.openStream();
        tcfg.load(in);

        /*tcfg.setProperty("torque.dsfactory.track.connection.user", "sysdba");
        tcfg.setProperty("torque.dsfactory.track.connection.password", "masterkey");
        tcfg.setProperty("torque.database.track.adapter", "firebird");
        tcfg.setProperty("torque.dsfactory.track.connection.driver", "org.firebirdsql.jdbc.FBDriver");
        tcfg.setProperty("torque.dsfactory.track.connection.url", "jdbc:firebirdsql://localhost/C:/Firebird_1_5/databases/TEST34.GDB");
        tcfg.setProperty("torque.dsfactory.track.factory", "org.apache.torque.dsfactory.SharedPoolDataSourceFactory");
        tcfg.setProperty("torque.dsfactory.track.pool.maxActive", "30");
        tcfg.setProperty("torque.dsfactory.track.pool.testOnBorrow","true");
        tcfg.setProperty("torque.dsfactory.track.pool.validationQuery","SELECT PKEY FROM TSTATE");
        */

        tcfg.setProperty("torque.applicationRoot", ".");
        tcfg.setProperty("torque.database.default", "track");
        tcfg.setProperty("torque.idbroker.clever.quantity", new Boolean(false));
        tcfg.setProperty("torque.idbroker.prefetch", new Boolean(false));
        tcfg.setProperty("torque.manager.useCache", new Boolean(true));
        in.close();
        Torque.init(tcfg);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.mtag.traffic.util.JsonTools.java

public static JSONObject requestService(String service) throws JsonServiceException {
    InputStream is = null;/*from  w  ww .ja  va2s.  com*/
    try {
        URL url = new URL(service);
        JSONParser parser = new JSONParser();
        is = url.openStream();
        JSONObject result = (JSONObject) parser.parse(new BufferedReader(new InputStreamReader(is)));
        is.close();
        return result;
    } catch (MalformedURLException ex) {
        throw new JsonServiceException("Bad service address", ex);
    } catch (IOException ex) {
        throw new JsonServiceException("Service '" + service + "' not available.", ex);
    } catch (ParseException ex) {
        throw new JsonServiceException("Error parsind service '" + service + "'.", ex);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ex) {
                throw new JsonServiceException("unable to close input stream", ex);
            }
        }
    }
}

From source file:dk.sdu.mmmi.hwr.group2.Utils.java

public static String readURL(String address) throws IOException {
    StringBuilder response = new StringBuilder();
    URL url = new URL(address);
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

    String inputLine;/*ww w  .j a v  a 2s . co  m*/
    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    return response.toString();
}

From source file:net.BiggerOnTheInside.Binder.engine.JSONManager.java

private static String readUrl(String urlString) throws Exception {
    BufferedReader reader = null;
    try {/*from  w  ww.j  a  v a  2s.  c  o m*/
        URL url = new URL(urlString);
        reader = new BufferedReader(new InputStreamReader(url.openStream()));
        StringBuffer buffer = new StringBuffer();
        int read;
        char[] chars = new char[1024];

        while ((read = reader.read(chars)) != -1)
            buffer.append(chars, 0, read);

        return buffer.toString();
    } finally {
        if (reader != null)
            reader.close();
    }
}

From source file:com.pickr.utils.BitmapUtils.java

private static Bitmap loadBitmap(URL url) throws IOException {
    InputStream is = null;//from w  w w  .j a v  a2s. c o  m
    try {
        is = new BufferedInputStream(url.openStream(), 512000);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 1;

        return BitmapFactory.decodeStream(is, null, options);

    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.acmutv.ontoqa.tool.io.IOManager.java

/**
 * Returns an {@link InputStream} from a general resource.
 * @param resource the resource locator (e.g.: path for local file, http url for remote file).
 * @return the open {@link InputStream}.
 * @throws IOException when the {@link InputStream} cannot be opened.
 *///from  ww w  . j a  v a  2s  . co  m
public static InputStream getInputStream(final String resource) throws IOException {
    if (resource.startsWith("http://") || resource.startsWith("https://")) {
        final URL url = new URL(resource);
        return url.openStream();
    } else {
        final Path path = FileSystems.getDefault().getPath(resource).toAbsolutePath();
        return Files.newInputStream(path);
    }
}

From source file:com.cedarsoft.serialization.test.utils.AbstractXmlVersionTest2.java

@Nonnull
protected static VersionEntry create(@Nonnull Version version, @Nonnull URL expected) {
    try {//from   w ww  .  jav  a2s.  c o m
        return new XmlVersionEntry(version, IOUtils.toByteArray(expected.openStream()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.orthancserver.OrthancConnection.java

private static InputStream OpenUrl(String urlString) throws IOException {
    URL url = new URL(urlString);

    try {/*from  w  ww  .  j  a v  a2s .c om*/
        return url.openStream();
    } catch (ConnectException e) {
        throw new IOException();
    }
}