FileZipper.java

net.minecraft.util.FileZipper

信息

  • 全限定名:net.minecraft.util.FileZipper
  • 类型:public class
  • 包:net.minecraft.util
  • 源码路径:src/main/java/net/minecraft/util/FileZipper.java
  • 起始行号:L17
  • 实现:Closeable
  • 职责:

    TODO

字段/常量

  • LOGGER

    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L18
    • 说明:

      TODO

  • outputFile

    • 类型: Path
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

  • tempFile

    • 类型: Path
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

  • fs

    • 类型: FileSystem
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

内部类/嵌套类型

构造器

public FileZipper(Path outputFile) @ L23

  • 构造器名:FileZipper
  • 源码定位:L23
  • 修饰符:public

参数:

  • outputFile: Path

说明:

TODO

方法

下面的方法块按源码顺序生成。

public void add(Path destinationRelativePath, String content) @ L34

  • 方法名:add
  • 源码定位:L34
  • 返回类型:void
  • 修饰符:public

参数:

  • destinationRelativePath: Path
  • content: String

说明:

TODO

public void add(Path destinationRelativePath, File file) @ L45

  • 方法名:add
  • 源码定位:L45
  • 返回类型:void
  • 修饰符:public

参数:

  • destinationRelativePath: Path
  • file: File

说明:

TODO

public void add(Path path) @ L56

  • 方法名:add
  • 源码定位:L56
  • 返回类型:void
  • 修饰符:public

参数:

  • path: Path

说明:

TODO

public void close() @ L76

  • 方法名:close
  • 源码定位:L76
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

public class FileZipper implements Closeable {
    private static final Logger LOGGER = LogUtils.getLogger();
    private final Path outputFile;
    private final Path tempFile;
    private final FileSystem fs;
 
    public FileZipper(Path outputFile) {
        this.outputFile = outputFile;
        this.tempFile = outputFile.resolveSibling(outputFile.getFileName().toString() + "_tmp");
 
        try {
            this.fs = Util.ZIP_FILE_SYSTEM_PROVIDER.newFileSystem(this.tempFile, ImmutableMap.of("create", "true"));
        } catch (IOException var3) {
            throw new UncheckedIOException(var3);
        }
    }
 
    public void add(Path destinationRelativePath, String content) {
        try {
            Path root = this.fs.getPath(File.separator);
            Path path = root.resolve(destinationRelativePath.toString());
            Files.createDirectories(path.getParent());
            Files.write(path, content.getBytes(StandardCharsets.UTF_8));
        } catch (IOException var5) {
            throw new UncheckedIOException(var5);
        }
    }
 
    public void add(Path destinationRelativePath, File file) {
        try {
            Path root = this.fs.getPath(File.separator);
            Path path = root.resolve(destinationRelativePath.toString());
            Files.createDirectories(path.getParent());
            Files.copy(file.toPath(), path);
        } catch (IOException var5) {
            throw new UncheckedIOException(var5);
        }
    }
 
    public void add(Path path) {
        try {
            Path root = this.fs.getPath(File.separator);
            if (Files.isRegularFile(path)) {
                Path targetFile = root.resolve(path.getParent().relativize(path).toString());
                Files.copy(targetFile, path);
            } else {
                try (Stream<Path> sourceFiles = Files.find(path, Integer.MAX_VALUE, (p, a) -> a.isRegularFile())) {
                    for (Path sourceFile : sourceFiles.collect(Collectors.toList())) {
                        Path targetFile = root.resolve(path.relativize(sourceFile).toString());
                        Files.createDirectories(targetFile.getParent());
                        Files.copy(sourceFile, targetFile);
                    }
                }
            }
        } catch (IOException var9) {
            throw new UncheckedIOException(var9);
        }
    }
 
    @Override
    public void close() {
        try {
            this.fs.close();
            Files.move(this.tempFile, this.outputFile);
            LOGGER.info("Compressed to {}", this.outputFile);
        } catch (IOException var2) {
            throw new UncheckedIOException(var2);
        }
    }
}

引用的其他类