Libraryless. Click here for Pure Java version (90L/1K/4K).
| 1 | !636 | 
| 2 | !modern | 
| 3 | |
| 4 | main {
 | 
| 5 |   psvm {
 | 
| 6 | split(args[0]); | 
| 7 | } | 
| 8 | |
| 9 | static long splitSize = 1024*1024; // 0 = auto | 
| 10 | static int n; | 
| 11 | |
| 12 |   static void split(String path) ctex {
 | 
| 13 | File file = new File(path); | 
| 14 |     print("== Processing " + path);
 | 
| 15 | long destSize = splitSize != 0 ? splitSize : file.length()/2; | 
| 16 | ZipFile zipFile = new ZipFile(file); | 
| 17 | Enumeration entries = zipFile.entries(); | 
| 18 | |
| 19 | n = 1; | 
| 20 | String outPath = path + "." + n; | 
| 21 |     print("Writing " + outPath);
 | 
| 22 | FileOutputStream fout = new FileOutputStream(outPath); | 
| 23 | ZipOutputStream zout = new ZipOutputStream(fout); | 
| 24 | long size = 0; | 
| 25 |     while (entries.hasMoreElements()) {
 | 
| 26 | ZipEntry entry = (ZipEntry) entries.nextElement(); | 
| 27 |       System.out.println("File found: " + entry.getName());
 | 
| 28 | zout.putNextEntry(new ZipEntry(entry.getName())); | 
| 29 | |
| 30 | InputStream fin = zipFile.getInputStream(entry); | 
| 31 | copyStream(fin, zout); | 
| 32 | fin.close(); | 
| 33 | |
| 34 | size += entry.getCompressedSize(); | 
| 35 |       if (size >= destSize) {
 | 
| 36 | size = 0; | 
| 37 | zout.close(); | 
| 38 | fout.close(); | 
| 39 | |
| 40 | ++n; | 
| 41 | outPath = path + "." + n; | 
| 42 |         print("Writing " + outPath);
 | 
| 43 | fout = new FileOutputStream(outPath); | 
| 44 | zout = new ZipOutputStream(fout); | 
| 45 | } | 
| 46 | } | 
| 47 | |
| 48 | zout.close(); | 
| 49 | fout.close(); | 
| 50 | zipFile.close(); | 
| 51 | } | 
| 52 | } | 
Began life as a copy of #683
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000728 | 
| Snippet name: | Split zip/jar file into two | 
| Eternal ID of this version: | #1000728/1 | 
| Text MD5: | 7376ccf4189325b2cbe73ae452dde842 | 
| Transpilation MD5: | 924113f1ddadd591bc1cfce677999ffc | 
| Author: | stefan | 
| Category: | |
| Type: | JavaX (input.txt to output.txt) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2015-08-24 01:31:07 | 
| Source code size: | 1380 bytes / 52 lines | 
| Pitched / IR pitched: | No / Yes | 
| Views / Downloads: | 935 / 1380 | 
| Referenced in: | [show references] |