Beispiel #1
0
 private void create() {
   try {
     Messaging.log("Creating file: " + this.file.getName());
     Files.createParentDirs(this.file);
     this.file.createNewFile();
   } catch (IOException ex) {
     Messaging.severe("Could not create file: " + this.file.getName());
     ex.printStackTrace();
   }
 }
Beispiel #2
0
 @Override
 public boolean load() {
   NBTInputStream stream = null;
   try {
     stream = new NBTInputStream(new GZIPInputStream(new FileInputStream(this.file)));
     final Tag tag = stream.readTag();
     if (tag == null || !(tag instanceof CompoundTag)) {
       return false;
     }
     this.root.clear();
     this.root.putAll(((CompoundTag) tag).getValue());
   } catch (IOException ex) {
     ex.printStackTrace();
     return false;
   } finally {
     try {
       stream.close();
     } catch (IOException ex2) {
     }
   }
   return true;
 }
Beispiel #3
0
 @Override
 public void save() {
   NBTOutputStream stream = null;
   try {
     Files.createParentDirs(this.file);
     final File temporaryFile =
         File.createTempFile(this.file.getName(), null, this.file.getParentFile());
     temporaryFile.deleteOnExit();
     stream = new NBTOutputStream(new FileOutputStream(temporaryFile));
     stream.writeTag(new CompoundTag(this.name, this.root));
     stream.close();
     this.file.delete();
     temporaryFile.renameTo(this.file);
     temporaryFile.delete();
   } catch (IOException ex) {
     ex.printStackTrace();
   } finally {
     try {
       stream.close();
     } catch (IOException ex2) {
     }
   }
 }