Use try with resource to close ClipboardReader and stop adding "atic" to schematic files or not reason

This commit is contained in:
dordsor21 2020-03-26 20:55:27 +00:00
parent f9bf576d2e
commit 2994b2c158

View File

@ -282,7 +282,7 @@ public abstract class SchematicHandler {
Settings.Paths.SCHEMATICS + File.separator + name); Settings.Paths.SCHEMATICS + File.separator + name);
if (!file.exists()) { if (!file.exists()) {
file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
Settings.Paths.SCHEMATICS + File.separator + name + "atic"); Settings.Paths.SCHEMATICS + File.separator + name);
} }
return getSchematic(file); return getSchematic(file);
} }
@ -319,19 +319,18 @@ public abstract class SchematicHandler {
if (!file.exists()) { if (!file.exists()) {
return null; return null;
} }
try {
ClipboardFormat format = ClipboardFormats.findByFile(file); ClipboardFormat format = ClipboardFormats.findByFile(file);
if (format != null) { if (format != null) {
ClipboardReader reader = format.getReader(new FileInputStream(file)); try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
Clipboard clip = reader.read(); Clipboard clip = reader.read();
return new Schematic(clip); return new Schematic(clip);
} catch (IOException e) {
e.printStackTrace();
}
} else { } else {
throw new UnsupportedFormatException( throw new UnsupportedFormatException(
"This schematic format is not recognised or supported."); "This schematic format is not recognised or supported.");
} }
} catch (IOException e) {
e.printStackTrace();
}
return null; return null;
} }