personthecat.catlib.exception.FormattedIOException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of catlib-quilt Show documentation
Show all versions of catlib-quilt Show documentation
Utilities for serialization, commands, noise generation, IO, and some new data types.
The newest version!
package personthecat.catlib.exception;
import net.minecraft.class_124;
import net.minecraft.class_2561;
import net.minecraft.class_2583;
import net.minecraft.class_2585;
import net.minecraft.class_2588;
import net.minecraft.class_5250;
import net.minecraft.network.chat.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import personthecat.catlib.util.PathUtils;
import java.io.File;
public class FormattedIOException extends FormattedException {
final File root;
final File file;
final String relative;
final String msg;
public FormattedIOException(final File file, final Throwable cause) {
this(file.getParentFile(), file, cause);
}
public FormattedIOException(final File file, final Throwable cause, final String msg) {
this(file.getParentFile(), file, cause, msg);
}
public FormattedIOException(final File root, final File file, final Throwable cause) {
this(root, file, cause, createMsg(cause));
}
public FormattedIOException(final File root, final File file, final Throwable cause, final String msg) {
super(msg, cause);
this.root = root;
this.file = file;
this.relative = PathUtils.getRelativePath(root, file);
this.msg = msg;
}
@Override
public @NotNull String getCategory() {
return "catlib.errorMenu.io";
}
@Override
public @NotNull class_2561 getDisplayMessage() {
return new class_2585(this.relative);
}
@Override
public @Nullable class_2561 getTooltip() {
return new class_2588(this.msg);
}
@Override
public @NotNull class_2561 getTitleMessage() {
return new class_2588("catlib.errorText.fileError", this.relative);
}
@Override
public @NotNull class_2561 getDetailMessage() {
final class_2561 newLine = new class_2585("\n");
final class_5250 component = new class_2585("");
final class_2583 title = class_2583.field_24360.method_27705(class_124.field_1073, class_124.field_1067);
component.method_10852(new class_2588("catlib.errorText.fileDiagnostics").method_27696(title));
component.method_10852(newLine);
component.method_10852(newLine);
final class_2561 bullet = new class_2585(" * ").method_27696(class_2583.field_24360.method_10982(true));
final class_2561 space = new class_2585(" ");
final class_2583 purple = class_2583.field_24360.method_10977(class_124.field_1076);
final class_2583 orange = class_2583.field_24360.method_10977(class_124.field_1065);
final class_2583 green = class_2583.field_24360.method_10977(class_124.field_1060);
final class_2583 blue = class_2583.field_24360.method_10977(class_124.field_1058);
final class_2583 red = class_2583.field_24360.method_10977(class_124.field_1061);
try {
final boolean exists = this.file.exists();
component.method_10852(bullet);
component.method_10852(new class_2588("catlib.errorText.fileExists").method_27696(purple));
component.method_10852(space);
component.method_10852(new class_2585(String.valueOf(exists)).method_27696(orange));
component.method_10852(newLine);
final boolean dirExists = this.file.getParentFile().exists();
component.method_10852(bullet);
component.method_10852(new class_2588("catlib.errorText.directoryExists").method_27696(purple));
component.method_10852(space);
component.method_10852(new class_2585(String.valueOf(dirExists)).method_27696(orange));
component.method_10852(newLine);
final String type = PathUtils.extension(this.file);
component.method_10852(bullet);
component.method_10852(new class_2588("catlib.errorText.fileType").method_27696(purple));
component.method_10852(space);
component.method_10852(new class_2585(type).method_27696(green));
component.method_10852(newLine);
final long kb = this.file.length() / 1000;
component.method_10852(bullet);
component.method_10852(new class_2588("catlib.errorText.fileSize").method_27696(purple));
component.method_10852(space);
component.method_10852(new class_2585(kb + "kb").method_27696(blue));
component.method_10852(newLine);
} catch (final SecurityException ignored) {
component.method_10852(new class_2588("catlib.errorText.ioNotAllowed").method_27696(red));
component.method_10852(newLine);
}
component.method_10852(newLine);
component.method_10852(new class_2588("catlib.errorText.stackTrace").method_27696(title));
component.method_10852(newLine);
component.method_10852(newLine);
component.method_10852(super.getDetailMessage());
return component;
}
}