Launcher/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java

63 lines
2 KiB
Java
Raw Normal View History

package pro.gravit.launchserver.binary;
2018-09-19 16:14:50 +03:00
2019-10-19 19:46:04 +03:00
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
import pro.gravit.utils.helper.IOHelper;
2018-09-19 16:14:50 +03:00
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
2018-09-19 16:29:31 +03:00
import java.util.Set;
2018-09-19 16:14:50 +03:00
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
2018-09-19 16:14:50 +03:00
import java.util.zip.ZipOutputStream;
public class BuildContext {
public final ZipOutputStream output;
public final LauncherConfigurator config;
public final MainBuildTask data;
public final HashSet<String> fileList;
2018-09-19 16:14:50 +03:00
public BuildContext(ZipOutputStream output, LauncherConfigurator config, MainBuildTask data) {
2018-09-19 16:14:50 +03:00
this.output = output;
this.config = config;
this.data = data;
fileList = new HashSet<>(1024);
2018-09-19 16:14:50 +03:00
}
2018-09-22 17:33:00 +03:00
public void pushFile(String filename, InputStream inputStream) throws IOException {
2018-09-19 16:14:50 +03:00
ZipEntry zip = IOHelper.newZipEntry(filename);
output.putNextEntry(zip);
2018-09-22 17:33:00 +03:00
IOHelper.transfer(inputStream, output);
fileList.add(filename);
2018-09-19 16:14:50 +03:00
}
2018-09-22 17:33:00 +03:00
public void pushJarFile(ZipInputStream input) throws IOException {
2018-09-19 16:14:50 +03:00
ZipEntry e = input.getNextEntry();
while (e != null) {
if (fileList.contains(e.getName())) {
e = input.getNextEntry();
continue;
}
2018-12-26 16:17:47 +03:00
output.putNextEntry(IOHelper.newZipEntry(e));
2018-09-22 17:33:00 +03:00
IOHelper.transfer(input, output);
fileList.add(e.getName());
2018-09-19 16:14:50 +03:00
e = input.getNextEntry();
}
}
2018-09-22 17:33:00 +03:00
public void pushJarFile(ZipInputStream input, Set<String> blacklist) throws IOException {
2018-09-19 16:29:31 +03:00
ZipEntry e = input.getNextEntry();
while (e != null) {
2019-09-30 10:01:41 +03:00
if (fileList.contains(e.getName()) || blacklist.contains(e.getName())) {
2018-09-19 16:29:31 +03:00
e = input.getNextEntry();
continue;
}
2018-12-26 16:17:47 +03:00
output.putNextEntry(IOHelper.newZipEntry(e));
2018-09-22 17:33:00 +03:00
IOHelper.transfer(input, output);
fileList.add(e.getName());
2018-09-19 16:29:31 +03:00
e = input.getNextEntry();
}
}
2018-09-19 16:14:50 +03:00
}