RealmsUploadWorldPacker.java
com.mojang.realmsclient.client.worldupload.RealmsUploadWorldPacker
信息
- 全限定名:com.mojang.realmsclient.client.worldupload.RealmsUploadWorldPacker
- 类型:public class
- 包:com.mojang.realmsclient.client.worldupload
- 源码路径:src/main/java/com/mojang/realmsclient/client/worldupload/RealmsUploadWorldPacker.java
- 起始行号:L17
- 职责:
TODO
字段/常量
-
SIZE_LIMIT- 类型:
long - 修饰符:
private static final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
WORLD_FOLDER_NAME- 类型:
String - 修饰符:
private static final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
isCanceled- 类型:
BooleanSupplier - 修饰符:
private final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
directoryToPack- 类型:
Path - 修饰符:
private final - 源码定位:
L21 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private RealmsUploadWorldPacker(Path directoryToPack, BooleanSupplier isCanceled) @ L27
- 构造器名:RealmsUploadWorldPacker
- 源码定位:L27
- 修饰符:private
参数:
- directoryToPack: Path
- isCanceled: BooleanSupplier
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static File pack(Path directoryToPack, BooleanSupplier isCanceled) @ L23
- 方法名:pack
- 源码定位:L23
- 返回类型:File
- 修饰符:public static
参数:
- directoryToPack: Path
- isCanceled: BooleanSupplier
说明:
TODO
private File tarGzipArchive() @ L32
- 方法名:tarGzipArchive
- 源码定位:L32
- 返回类型:File
- 修饰符:private
参数:
- 无
说明:
TODO
private void addFileToTarGz(TarArchiveOutputStream out, Path path, String base, boolean root) @ L57
- 方法名:addFileToTarGz
- 源码定位:L57
- 返回类型:void
- 修饰符:private
参数:
- out: TarArchiveOutputStream
- path: Path
- base: String
- root: boolean
说明:
TODO
private void verifyBelowSizeLimit(long sizeInByte) @ L84
- 方法名:verifyBelowSizeLimit
- 源码定位:L84
- 返回类型:void
- 修饰符:private
参数:
- sizeInByte: long
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RealmsUploadWorldPacker {
private static final long SIZE_LIMIT = 5368709120L;
private static final String WORLD_FOLDER_NAME = "world";
private final BooleanSupplier isCanceled;
private final Path directoryToPack;
public static File pack(Path directoryToPack, BooleanSupplier isCanceled) throws IOException {
return new RealmsUploadWorldPacker(directoryToPack, isCanceled).tarGzipArchive();
}
private RealmsUploadWorldPacker(Path directoryToPack, BooleanSupplier isCanceled) {
this.isCanceled = isCanceled;
this.directoryToPack = directoryToPack;
}
private File tarGzipArchive() throws IOException {
TarArchiveOutputStream tar = null;
File var3;
try {
File file = File.createTempFile("realms-upload-file", ".tar.gz");
tar = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
tar.setLongFileMode(3);
this.addFileToTarGz(tar, this.directoryToPack, "world", true);
if (this.isCanceled.getAsBoolean()) {
throw new RealmsUploadCanceledException();
}
tar.finish();
this.verifyBelowSizeLimit(file.length());
var3 = file;
} finally {
if (tar != null) {
tar.close();
}
}
return var3;
}
private void addFileToTarGz(TarArchiveOutputStream out, Path path, String base, boolean root) throws IOException {
if (this.isCanceled.getAsBoolean()) {
throw new RealmsUploadCanceledException();
} else {
this.verifyBelowSizeLimit(out.getBytesWritten());
File file = path.toFile();
String entryName = root ? base : base + file.getName();
TarArchiveEntry entry = new TarArchiveEntry(file, entryName);
out.putArchiveEntry(entry);
if (file.isFile()) {
try (InputStream is = new FileInputStream(file)) {
is.transferTo(out);
}
out.closeArchiveEntry();
} else {
out.closeArchiveEntry();
File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
this.addFileToTarGz(out, child.toPath(), entryName + "/", false);
}
}
}
}
}
private void verifyBelowSizeLimit(long sizeInByte) {
if (sizeInByte > 5368709120L) {
throw new RealmsUploadTooLargeException(5368709120L);
}
}
}引用的其他类
-
- 引用位置:
构造调用 - 关联成员:
RealmsUploadCanceledException()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
RealmsUploadTooLargeException()
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
File.createTempFile()
- 引用位置: