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:de.uni.stuttgart.informatik.ToureNPlaner.Net.Handler.SyncCoreLoader.java

private InputStream readCoreFileFromNetAndCache() throws IOException {
    HttpURLConnection con = null;
    try {/*from  w  w w . j  av  a 2  s  .  co  m*/
        URL url = new URL(coreURL + pathPrefix + corePrefix + coreLevel + coreSuffix);
        con = (HttpURLConnection) url.openConnection();
        File cacheDirFile = ToureNPlanerApplication.getContext().getExternalCacheDir();
        Log.d(TAG, "Trying to download core to " + cacheDirFile.getAbsolutePath() + corePrefix + coreLevel
                + coreSuffix);
        FileOutputStream coreFileStream = new FileOutputStream(
                new File(cacheDirFile, corePrefix + coreLevel + coreSuffix));
        Log.d(TAG, "Content-Length: " + con.getContentLength());
        InputStream in = new BufferedInputStream(con.getInputStream());
        TeeInputStream teeStream = new TeeInputStream(in, coreFileStream, true);
        return teeStream;

    } catch (MalformedURLException e) {
        e.printStackTrace();
        if (con != null) {
            con.disconnect();
        }
        return null;
    }
}

From source file:de.uni.stuttgart.informatik.ToureNPlaner.Net.Handler.SyncCoreLoader.java

private long getLastModifiedOnServer() throws IOException {
    HttpURLConnection con = null;
    long result = new Date().getTime();
    try {/*from  w ww.ja va  2  s  .  c om*/
        URL url = new URL(coreURL + pathPrefix + corePrefix + coreLevel + coreSuffix);
        con = (HttpURLConnection) url.openConnection();

        con.setRequestMethod("HEAD");
        con.setDoInput(true);
        con.setAllowUserInteraction(false);
        result = con.getHeaderFieldDate("Last-Modified", result);
        Log.d(TAG, "Last modified is parsed " + new Date(result));

    } catch (MalformedURLException e) {
        e.printStackTrace();
        return result;
    } finally {
        if (con != null) {
            con.disconnect();
        }
    }
    return result;
}

From source file:cm.aptoide.pt.LatestLikesComments.java

public Cursor getLikes() {
    endPointLikes = String.format(endPointLikes, repoName);
    MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "apkid", "name", "like", "username" });

    try {//from w  w  w .j  ava  2 s . c o  m
        HttpURLConnection connection = (HttpURLConnection) new URL(endPointLikes).openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line + "\n");
        }
        br.close();

        JSONObject respJSON = new JSONObject(sb.toString());
        JSONArray array = respJSON.getJSONArray("listing");

        for (int i = 0; i != array.length(); i++) {

            String apkid = ((JSONObject) array.get(i)).getString("apkid");
            String name = ((JSONObject) array.get(i)).getString("name");
            String like = ((JSONObject) array.get(i)).getString("like");
            String username = ((JSONObject) array.get(i)).getString("username");
            if (username.equals("NOT_SIGNED_UP")) {
                username = "";
            }
            cursor.newRow().add(i).add(apkid).add(name).add(like).add(username);

        }

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return cursor;
}

From source file:blackman.matt.catalog.CatalogActivity.java

/**
 * Creates all the things on startup of the activity.
 *
 * @param savedInstanceState A saved state if this is being opened again.
 *//*from w w w.j a va2s  .co m*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);

    Intent intent = getIntent();

    mBoardRoot = intent.getStringExtra(ARG_CATALOG_BOARD);
    String fileUrl = mBoardRoot + "/catalog.json";

    //noinspection ConstantConditions
    getActionBar().setTitle("Catalog - /" + mBoardRoot + "/");

    mPosts = new ArrayList<Post>();

    CatalogLoader loader = new CatalogLoader();
    loader.setNotifier(this);

    URL url;
    try {
        url = new URL("https", "8chan.co", fileUrl);
        loader.execute(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:com.tangfan.test.UserServiceTest.java

@Before
public void init() {
    try {//w  w w.  j  av a2  s.c o  m
        URL url = new URL("http://localhost:8085/soap/us?wsdl");
        QName qName = new QName(ns, "UserService");
        ws = new UserService_Service(url, qName);
        //         port = ws.getUserServicePort(new MTOMFeature());
        port = ws.getUserServicePort();
        BindingProvider bp = (BindingProvider) port;
        SOAPBinding binding = (SOAPBinding) bp.getBinding();
        binding.setMTOMEnabled(true);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:weavebytes.com.futureerp.activities.DashBoardActivity.java

public boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnected()) {
        try {//from w  w w.  jav  a2s .c o m
            URL url = new URL("http://www.google.com");
            HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
            urlc.setConnectTimeout(2000);
            urlc.connect();
            if (urlc.getResponseCode() == 200) {
                return new Boolean(true);
            }
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return false;
}

From source file:com.athena.dolly.cloudant.CloudantEventListener.java

public void init() {
    try {//from w  w  w  . j ava 2s  .c om
        HttpClient httpClient = new StdHttpClient.Builder().url(url).username("ighlyesesedisentstoldneg")
                .password("cOlugjOsPXtkHyR1SPvNDYME").connectionTimeout(5000).socketTimeout(30000).build();

        StdCouchDbInstance dbInst = new StdCouchDbInstance(httpClient);

        System.out.println("*** Database connection is established");

        conn = dbInst.createConnector("a_samsung_file", true);
        connSeq = dbInst.createConnector("a_seq", true);

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:net.portalblockz.portalbot.FeatureListener.java

@Override
public void receiveEvent(IRCEvent ircEvent) {
    if (ircEvent.getType() == IRCEvent.Type.CHANNEL_MESSAGE) {
        MessageEvent me = (MessageEvent) ircEvent;
        if (me.getMessage().startsWith("?")) {
            Remember.triggerMemory(me.getMessage().replaceFirst("\\?", "").split(" ")[0], me);
            return;
        }// w w  w  .  j  av a 2  s . c  o  m
        String id = null;
        for (String temp : me.getMessage().split(" ")) {
            if (getID(temp) != null) {
                id = getID(temp);
            }
        }
        String json = "";
        JSONObject object = null;
        if (id != null) {
            try {
                URL link = new URL("https://gdata.youtube.com/feeds/api/videos/" + id + "?v=2&alt=json");
                BufferedReader br = new BufferedReader(new InputStreamReader(link.openStream()));
                String input;
                while ((input = br.readLine()) != null) {
                    json += input;
                    object = new JSONObject(json);
                }
                br.close();
                if (object == null) {
                    return;
                }
                String title = object.getJSONObject("entry").getJSONObject("title").getString("$t");
                JSONArray array = object.getJSONObject("entry").getJSONArray("author");
                String author = array.getJSONObject(0).getJSONObject("name").getString("$t");
                int duration = object.getJSONObject("entry").getJSONObject("media$group")
                        .getJSONObject("yt$duration").getInt("seconds");
                int min = duration / 60;
                double sec = duration % 60;
                int views = object.getJSONObject("entry").getJSONObject("yt$statistics").getInt("viewCount");
                int dislikes = object.getJSONObject("entry").getJSONObject("yt$rating").getInt("numDislikes");
                int likes = object.getJSONObject("entry").getJSONObject("yt$rating").getInt("numLikes");
                int total = dislikes + likes;
                double percent = likes / total * 100;
                me.getChannel()
                        .say("(" + me.getNick() + ") " + Colors.DARK_GREEN + title + Colors.BLACK + " by "
                                + Colors.DARK_GREEN + author + Colors.BLACK + " - views: " + Colors.DARK_GREEN
                                + views + Colors.BLACK + " - likes: " + Colors.DARK_GREEN + percent + "%"
                                + Colors.BLACK + " - length: " + Colors.DARK_GREEN + min + "m " + sec + "s");
            } catch (MalformedURLException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
}

From source file:cms.service.account.HTMLGenerator.java

public final String generate(final String url) {
    // isBlank??0(whitespace) ? 
    if (StringUtils.isBlank(url))
        return null;

    //URL/*from w w  w.j  a  v  a 2  s . co m*/
    Pattern pattern = Pattern.compile("(http://|https://){1}[\\w\\.\\-/:]+");
    Matcher matcher = pattern.matcher(url);
    if (!matcher.find())
        return null;

    //
    StringBuffer sb = new StringBuffer();

    try {
        //?XHMTL
        URL _url = new URL(url);
        URLConnection urlconnection = _url.openConnection();

        //System.out.println(urlconnection.getContentType());

        //?XHMTL
        BufferedReader in = new BufferedReader(new InputStreamReader(urlconnection.getInputStream(), "UTF-8"));

        String inputLine;//XHML,SB
        while ((inputLine = in.readLine()) != null) {
            sb.append(inputLine + "\n");
            //System.out.println(inputLine);
        }

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return sb.toString();
}

From source file:logistify.core.ModuloGoogleApiMatrix.java

public String readUrl(String url1) {
    try {//from  w  w  w .java2 s .  c  om
        URL oracle;
        oracle = new URL(url1);
        BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));

        String inputLine;
        StringBuilder strbuilder = new StringBuilder();
        while ((inputLine = in.readLine()) != null)
            strbuilder.append(inputLine);
        in.close();
        return strbuilder.toString();
    } catch (MalformedURLException murlee) {
        murlee.printStackTrace();
        return null;
    } catch (IOException ioe) {
        ioe.printStackTrace();
        return null;
    }
}