mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 14:51:51 -04:00
Boost up download game data
This commit is contained in:
parent
00fec7364b
commit
3d2050ce63
@ -5,6 +5,7 @@ import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.charset.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import org.apache.commons.io.*;
|
||||
|
||||
public class DownloadUtils {
|
||||
public static final String USER_AGENT = Tools.APP_NAME;
|
||||
@ -20,7 +21,6 @@ public class DownloadUtils {
|
||||
|
||||
public static void download(URL url, OutputStream os) throws Throwable {
|
||||
InputStream is = null;
|
||||
byte[] buf; // 16384
|
||||
try {
|
||||
// System.out.println("Connecting: " + url.toString());
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
@ -32,9 +32,8 @@ public class DownloadUtils {
|
||||
throw new RuntimeException("Server returned HTTP " + conn.getResponseCode()
|
||||
+ ": " + conn.getResponseMessage());
|
||||
}
|
||||
buf = new byte[conn.getContentLength()];
|
||||
is = conn.getInputStream();
|
||||
IoUtil.pipe(is, os, buf);
|
||||
IOUtils.copy(is, os);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
|
@ -1,107 +0,0 @@
|
||||
package net.kdt.pojavlaunch.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import android.os.*;
|
||||
|
||||
public class IoUtil {
|
||||
|
||||
//public static volatile boolean cancel = false;
|
||||
|
||||
private IoUtil() {
|
||||
}
|
||||
|
||||
public static void pipe( /*PojavLauncherActivity activity,*/ InputStream is, OutputStream out, byte[] buf) throws IOException {
|
||||
while (true) {
|
||||
//if (cancel) throw new CancelException();
|
||||
|
||||
int amt = is.read(buf);
|
||||
if (amt >= 0) {
|
||||
out.write(buf, 0, amt);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void copy(File from, File to, byte[] buf) throws IOException {
|
||||
InputStream in = new FileInputStream(from);
|
||||
OutputStream out;
|
||||
try {
|
||||
out = new FileOutputStream(to);
|
||||
pipe(in, out, buf);
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (Throwable th) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyZipWithoutEmptyDirectories(File inputFile, File outputFile) throws IOException {
|
||||
byte[] buf = new byte[8192];
|
||||
ZipFile inputZip = new ZipFile(inputFile);
|
||||
ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(outputFile));
|
||||
try {
|
||||
Enumeration<? extends ZipEntry> e = inputZip.entries();
|
||||
ArrayList<ZipEntry> sortedList = new ArrayList();
|
||||
while (e.hasMoreElements()) {
|
||||
sortedList.add((ZipEntry) e.nextElement());
|
||||
}
|
||||
Collections.sort(sortedList, new Comparator<ZipEntry>() {
|
||||
public int compare(ZipEntry o1, ZipEntry o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
for (int i = sortedList.size() - 1; i >= 0; i--) {
|
||||
boolean isEmptyDirectory;
|
||||
ZipEntry inputEntry = (ZipEntry) sortedList.get(i);
|
||||
String name = inputEntry.getName();
|
||||
if (!inputEntry.isDirectory()) {
|
||||
isEmptyDirectory = false;
|
||||
} else if (i == sortedList.size() - 1) {
|
||||
isEmptyDirectory = true;
|
||||
} else {
|
||||
isEmptyDirectory = !((ZipEntry) sortedList.get(i + 1)).getName().startsWith(name);
|
||||
}
|
||||
if (isEmptyDirectory) {
|
||||
sortedList.remove(inputEntry);
|
||||
} else {
|
||||
outputStream.putNextEntry(new ZipEntry(inputEntry));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
InputStream is = inputZip.getInputStream(inputEntry);
|
||||
pipe(is, baos, buf);
|
||||
is.close();
|
||||
outputStream.write(baos.toByteArray());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearDirectory(File dir) {
|
||||
File[] fileList = dir.listFiles();
|
||||
if (fileList != null) {
|
||||
for (File f : fileList) {
|
||||
if (f.isDirectory()) {
|
||||
clearDirectory(f);
|
||||
}
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user