Example usage for java.net MalformedURLException printStackTrace

List of usage examples for java.net MalformedURLException printStackTrace

Introduction

In this page you can find the example usage for java.net MalformedURLException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.csware.ee.utils.Tools.java

public static String readParse(String path) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    byte[] data = new byte[1024];
    int len = 0;/*from   www.j a  v  a2 s . c om*/
    URL url = null;
    try {
        url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        InputStream inputStream = conn.getInputStream();
        while ((len = inputStream.read(data)) != -1) {
            outputStream.write(data, 0, len);
        }
        inputStream.close();

    } catch (MalformedURLException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
    return new String(outputStream.toByteArray());
}

From source file:br.com.nordestefomento.jrimum.bopepo.view.ViewerPDF.java

public static URL getTemplate(String template) {
    URL templateUrl = null;/*from   w  w  w . j  a v a  2  s  .c  o m*/
    try {
        templateUrl = new URL(template);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return templateUrl;
}

From source file:edu.ucsb.eucalyptus.admin.server.EucalyptusWebBackendImpl.java

private static List<DownloadsWeb> getDownloadsFromUrl(final String downloadsUrl) {
    List<DownloadsWeb> downloadsList = new ArrayList<DownloadsWeb>();

    HttpClient httpClient = new HttpClient();
    //support for http proxy
    if (HttpServerBootstrapper.httpProxyHost != null && (HttpServerBootstrapper.httpProxyHost.length() > 0)) {
        String proxyHost = HttpServerBootstrapper.httpProxyHost;
        if (HttpServerBootstrapper.httpProxyPort != null
                && (HttpServerBootstrapper.httpProxyPort.length() > 0)) {
            int proxyPort = Integer.parseInt(HttpServerBootstrapper.httpProxyPort);
            httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
        } else {//from   ww w  .j  a v a  2 s .co  m
            httpClient.getHostConfiguration().setProxyHost(new ProxyHost(proxyHost));
        }
    }
    GetMethod method = new GetMethod(downloadsUrl);
    Integer timeoutMs = new Integer(3 * 1000);
    method.getParams().setSoTimeout(timeoutMs);

    try {
        httpClient.executeMethod(method);
        String str = "";
        InputStream in = method.getResponseBodyAsStream();
        byte[] readBytes = new byte[1024];
        int bytesRead = -1;
        while ((bytesRead = in.read(readBytes)) > 0) {
            str += new String(readBytes, 0, bytesRead);
        }
        String entries[] = str.split("[\\r\\n]+");
        for (int i = 0; i < entries.length; i++) {
            String entry[] = entries[i].split("\\t");
            if (entry.length == 3) {
                downloadsList.add(new DownloadsWeb(entry[0], entry[1], entry[2]));
            }
        }

    } catch (MalformedURLException e) {
        LOG.warn("Malformed URL exception: " + e.getMessage());
        e.printStackTrace();

    } catch (IOException e) {
        LOG.warn("I/O exception: " + e.getMessage());
        e.printStackTrace();

    } finally {
        method.releaseConnection();
    }

    return downloadsList;
}

From source file:MainClass.java

public void init() {
    audio1 = getAudioClip(getCodeBase(), "audio/bong.au");
    audio2 = getAudioClip(getCodeBase(), "audio/joy.au");
    try {//w  ww  .j  av a 2  s . c om
        audio3 = getAudioClip(new URL(getCodeBase(), "audio/return.au"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:bridge.toolkit.Controller.java

/**
 * Creates the Catalog object based off of the configuration file. 
 * @return Catalog object that contains the set of commands to be performed.
 *//*from w  w w.ja  v  a  2 s  . c  om*/
public Catalog createCatalog() {
    if (catalog == null) {
        try {
            parser.parse(this.getClass().getResource(CONFIG_FILE));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    catalog = CatalogFactoryBase.getInstance().getCatalog();
    return catalog;
}

From source file:TextureMapping.java

/**
 * Wurfeldarstellung// w  ww. j  a  va2 s .co  m
 * 
 * @return Appearance
 */
private Appearance makeAppearance() {
    Appearance a = new Appearance();
    TextureLoader loader = null;
    if (getCodeBase() != null)
        try {
            // Laden der Obj Datei als Applet mit jar
            loader = new TextureLoader(new URL("jar:" + getCodeBase() + "TextureMapping.jar!/burnstone.jpg"),
                    null);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    else
        // Laden der Obj Datei mittels jar
        loader = new TextureLoader(ClassLoader.getSystemResource("burnstone.jpg"), null);

    Texture2D texture = (Texture2D) loader.getTexture();
    a.setTexture(texture);
    return a;
}

From source file:Main.java

public void init() {
    Properties p = new Properties();
    try {//from w  w w .  ja  v  a  2 s.  com
        p.load((new URL(getCodeBase(), "user.props")).openStream());
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:fr.eolya.utils.http.HttpUtils.java

public static String urlRemoveParameters(String url, String paramsToRemove) {
    if (paramsToRemove == null || "".equals(paramsToRemove))
        return url;

    try {//from   w w w.  ja  v  a  2s.c  o m
        URL u = new URL(url);
        if (u.getQuery() == null && u.getPath().indexOf(";jsessionid=") == -1)
            return url;
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
        return null;
    }

    try {

        url = url.replace("?&", "?");

        if ("*".equals(paramsToRemove)) {
            int offset = url.lastIndexOf("?");
            if (offset != -1)
                return url.substring(0, offset);
        }

        paramsToRemove = paramsToRemove.replaceAll(" ", "").replaceAll(";", ",");
        String[] aToRemove = paramsToRemove.split(",");
        String tempUrl = url;
        for (int i = 0; i < aToRemove.length; i++) {
            boolean found = true;
            while (found) {
                found = false;
                String re = "[?&;]" + aToRemove[i].toLowerCase() + "[=&]";
                Pattern p = Pattern.compile(re);
                Matcher m = p.matcher(tempUrl.toLowerCase());
                if (m.find()) {
                    found = true;
                    int start = m.start();
                    int stop = start;
                    if ("jsessionid".equals(aToRemove[i].toLowerCase())) {
                        stop = tempUrl.indexOf("?", start + 1);
                        if (stop == -1)
                            stop = tempUrl.indexOf("&", start + 1);
                    } else {
                        stop = tempUrl.indexOf("&", start + 1);
                    }
                    if (stop == -1) {
                        tempUrl = tempUrl.substring(0, start);
                    } else {
                        String ope = tempUrl.substring(start, start + 1);
                        if (";".equals(ope))
                            ope = "?";
                        tempUrl = tempUrl.substring(0, start) + ope + tempUrl.substring(stop + 1);
                    }
                }
                re = "[?&;]" + aToRemove[i].toLowerCase() + "$";
                p = Pattern.compile(re);
                m = p.matcher(tempUrl.toLowerCase());
                if (m.find()) {
                    found = true;
                    int start = m.start();
                    int stop = start;
                    if ("jsessionid".equals(aToRemove[i].toLowerCase())) {
                        stop = tempUrl.indexOf("?", start + 1);
                        if (stop == -1)
                            stop = tempUrl.indexOf("&", start + 1);
                    } else {
                        stop = tempUrl.indexOf("&", start + 1);
                    }
                    if (stop == -1) {
                        tempUrl = tempUrl.substring(0, start);
                    } else {
                        String ope = tempUrl.substring(start, start + 1);
                        if (";".equals(ope))
                            ope = "?";
                        tempUrl = tempUrl.substring(0, start) + ope + tempUrl.substring(stop + 1);
                    }
                }
            }
        }
        return tempUrl;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

From source file:edu.asu.bscs.ihattend.jsonrpcapp.JsonRPCCalculator.java

public JsonRPCCalculator(String serviceUrl) {
    try {//  ww w  .j  a  va  2 s.  c  o m
        url = new URL(serviceUrl);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    server = new JsonRpcRequestViaHttp(url);
}

From source file:asu.edu.msse.gpeddabu.moviedescriptions.AsyncLibraryConnect.java

@Override
protected MethodInformation doInBackground(MethodInformation... aRequest) {
    try {/*  w w w  .  ja v a2  s. c  o m*/
        String result = downloadUrl(aRequest[0].urlString);
        aRequest[0].resultAsJson = result;
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return aRequest[0];
}