1111import java .io .Closeable ;
1212import java .io .File ;
1313import java .io .FileInputStream ;
14+ import java .io .FileNotFoundException ;
1415import java .io .FileOutputStream ;
1516import java .io .IOException ;
1617import java .io .InputStream ;
3637import java .util .zip .ZipOutputStream ;
3738
3839// TODO remove Jar-related methods? some of them needs SrgUtils
39- public class FileUtils {
40+ public final class FileUtils {
41+ private FileUtils () { }
42+
4043 public static final long ZIPTIME = 628041600000L ;
4144 public static final TimeZone GMT = TimeZone .getTimeZone ("GMT" );
4245
@@ -262,6 +265,17 @@ public static File makeJar(File classes, File sourcesDir, List<File> sources, Fi
262265 return jar ;
263266 }
264267
268+ public static void makeZip (File inputDir , File zip ) {
269+ try (var zos = new ZipOutputStream (new FileOutputStream (zip ))) {
270+ for (var file : listFiles (inputDir )) {
271+ var entryName = inputDir .toPath ().relativize (file .toPath ()).toString ();
272+ writeEntry (zos , new Info (entryName , file ));
273+ }
274+ } catch (IOException e ) {
275+ sneak (e );
276+ }
277+ }
278+
265279 private static void makeJarInternal (File dir , List <File > classes , JarOutputStream jos ) throws IOException {
266280 for (var file : classes ) {
267281 String entryName = file .getAbsoluteFile ().toString ().substring (dir .getAbsolutePath ().length () + 1 ).replace ('\\' , '/' );
@@ -275,7 +289,17 @@ private static void makeJarInternal(File dir, List<File> classes, JarOutputStrea
275289 }
276290 }
277291
278- private record Info (String name , Supplier <InputStream > stream ) {}
292+ private record Info (String name , Supplier <InputStream > stream ) {
293+ private Info (String name , File file ) {
294+ this (name , () -> {
295+ try {
296+ return new FileInputStream (file );
297+ } catch (FileNotFoundException e ) {
298+ return sneak (e );
299+ }
300+ });
301+ }
302+ }
279303
280304 /** @see <a href="https://github.com/MinecraftForge/ForgeGradle/blob/efa70580314c88192486e4ab089f4b970d5b080c/src/common/java/net/minecraftforge/gradle/common/util/MinecraftRepo.java#L323-L327">MinecraftRepo.splitJar(...) in ForgeGradle 6</a> */
281305 public static void splitJar (File raw , File mappings , File output , boolean slim , boolean stable ) throws IOException {
0 commit comments