Libraryless. Click here for Pure Java version (771L/6K/19K).
!752 static boolean actualCopy = true; static int maxCopy = 1024*1024*1024; p { File dest = new File("/home/stefan/Downloads/Brilliance.mp4"); //print(bytesToHex(firstBytesOfFile(dest, 10))); int downloaded = (int) dest.length(); print("Existing: " + downloaded); URL url = new URL("http://cdl37.convert2mp3.net/download.php?id=youtube_pvcsa2ZesZY&key=bV7xjw9SuB4X&d=y"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Range", "bytes=" + downloaded + "-"); InputStream in = connection.getInputStream(); try { print("Length: " + connection.getContentLength()); int status = connection.getResponseCode(); print("Code: " + status); if (status != HttpURLConnection.HTTP_PARTIAL) fail("No partial download possible!"); if (actualCopy) { FileOutputStream fos = new FileOutputStream(dest, true); // append print("Copied: " + copyStream(downloaded, downloaded+maxCopy, in, fos)); fos.close(); } else { new ByteArrayOutputStream bos; print("Tested: " + copyStream(downloaded, downloaded+10, in, bos)); byte[] bytes = bos.toByteArray(); print(bytesToHex(subArray(bytes, 0, 10))); } } finally { in.close(); } } static long copyStream(int downloaded, long maxDownload, InputStream in, OutputStream out) ctex { byte[] buf = new byte[65536]; long total = downloaded; while (total < maxDownload) { int n = in.read(buf); if (n <= 0) return total; out.write(buf, 0, n); total += n; print("Downloaded: " + toK(total) + " K"); } ret total; } static byte[] subArray(byte[] b, int start, int end) { byte[] x = new byte[end-start]; System.arraycopy(b, start, x, 0, end-start); ret x; }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1002996 |
| Snippet name: | Java Resume HTTP Test (works!) |
| Eternal ID of this version: | #1002996/1 |
| Text MD5: | 615eeaba6aff39690254052184b5e86e |
| Transpilation MD5: | 767676e9cdd5eb92e0ef62e6733bf10b |
| Author: | stefan |
| Category: | javax / networking |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-04-17 03:04:33 |
| Source code size: | 1850 bytes / 59 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 900 / 1022 |
| Referenced in: | [show references] |