From bdede5758ac73b9237d40a3ced80e305bdb09d17 Mon Sep 17 00:00:00 2001 From: Novampr Date: Tue, 25 Jun 2024 20:28:21 +0100 Subject: [PATCH] Remove test --- src/test/java/pojlib/util/StreamDLTest.java | 67 --------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/test/java/pojlib/util/StreamDLTest.java diff --git a/src/test/java/pojlib/util/StreamDLTest.java b/src/test/java/pojlib/util/StreamDLTest.java deleted file mode 100644 index 4c456cd1..00000000 --- a/src/test/java/pojlib/util/StreamDLTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package pojlib.util; - -import org.apache.commons.io.IOUtils; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.file.Files; - -class StreamDLTest { - - private static void download(URL url, OutputStream os) throws IOException { - InputStream is = null; - try { - // System.out.println("Connecting: " + url.toString()); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setConnectTimeout(10000); - conn.setDoInput(true); - conn.connect(); - if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { - throw new IOException("Server returned HTTP " + conn.getResponseCode() - + ": " + conn.getResponseMessage()); - } - is = new StreamDL(conn.getInputStream()); - - ((StreamDL)is).addListener((b, count) -> { - System.out.println(b); - System.out.println(count); - }); - - IOUtils.copy(is, os); - } catch (IOException e) { - throw new IOException("Unable to download from " + url, e); - } finally { - if (is != null) { - try { - is.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - - public static void downloadFile(String url, File out) throws IOException { - out.getParentFile().mkdirs(); - File tempOut = File.createTempFile(out.getName(), ".part", out.getParentFile()); - BufferedOutputStream bos = null; - try { - OutputStream bos2 = new BufferedOutputStream(Files.newOutputStream(tempOut.toPath())); - try { - download(new URL(url), bos2); - tempOut.renameTo(out); - bos2.close(); - if (tempOut.exists()) tempOut.delete(); - - } catch (IOException th2) { - if (tempOut.exists()) tempOut.delete(); - throw th2; - } - } catch (IOException th3) { - if (tempOut.exists()) tempOut.delete(); - throw th3; - } - } - -}