From 746ce7fb55c8973f2edc88233c529180bbfb2d73 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 7 Jun 2013 09:31:14 +0200 Subject: [PATCH] Add in a small async web util. --- src/com/massivecraft/mcore/util/WebUtil.java | 47 ++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/com/massivecraft/mcore/util/WebUtil.java diff --git a/src/com/massivecraft/mcore/util/WebUtil.java b/src/com/massivecraft/mcore/util/WebUtil.java new file mode 100644 index 00000000..610b280e --- /dev/null +++ b/src/com/massivecraft/mcore/util/WebUtil.java @@ -0,0 +1,47 @@ +package com.massivecraft.mcore.util; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class WebUtil +{ + private static final ExecutorService executor = Executors.newSingleThreadExecutor(); + + public static void asyncGetTouch(String url) + { + try + { + asyncGetTouch(new URL(url)); + } + catch (MalformedURLException e) + { + e.printStackTrace(); + } + } + + public static void asyncGetTouch(final URL url) + { + executor.execute(new Runnable() + { + @Override + public void run() + { + try + { + InputStream inputStream = null; + + inputStream = url.openStream(); + inputStream.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + }); + } +}