package droplauncher.util;

import adakite.utils.FileOperation;
import adakite.utils.ReadFile;
import adakite.utils.WriteFile;
import java.io.File;
import java.util.ArrayList;

public class MemoryFile  {

  private File file;
  private ArrayList<String> lines;

  public MemoryFile() {
    this.file = null;
    this.lines = new ArrayList<>();
  }

  public void reset() {
    this.file = null;
    this.lines.clear();
  }

  public File getFile() {
    return this.file;
  }

  public ArrayList<String> getLines() {
    return this.lines;
  }

  public boolean open(File file) {
    reset();

    if (file == null) {
      return false;
    }

    this.file = file;
    if (!(new FileOperation(file).doesFileExist()) && !(new FileOperation(file).createFile())) {
      //TODO: error message
      this.file = null;
      return false;
    }

    ReadFile rf = new ReadFile();
    if (!rf.open(this.file)) {
      //TODO: error message
      return false;
    }
    String line;
    while ((line = rf.getNextLine()) != null) {
      this.lines.add(line);
    }
    rf.close();

    return true;
  }

  public boolean dumpToFile(File file) {
    if (file == null) {
      //TODO: error
      return false;
    }

    WriteFile wf = new WriteFile();
    if (!wf.open(file)) {
      //TODO: error
      return false;
    }
    for (String line : this.lines) {
      wf.writeLine(line);
    }
    wf.close();

    return true;
  }

  public boolean dumpToFile() {
    return this.dumpToFile(this.file);
  }

  public void dumpToConsole() {
    StringBuilder sb = new StringBuilder();
    for (String line : this.lines) {
      sb.append(line).append(System.lineSeparator());
    }
    System.out.print(sb.toString());
  }

}

@@ -21,16 +21,52 @@
 .util;%0A%0A
+import adakite.debugging.Debugging;%0A
 import a
@@ -209,35 +209,226 @@
 st;%0A
-%0Apublic class MemoryFile  %7B
+import java.util.logging.Logger;%0A%0Apublic class MemoryFile  %7B%0A%0A  private static final Logger LOGGER = Logger.getLogger(MemoryFile.class.getName());%0A  private static final boolean CLASS_DEBUG = (Constants.DEBUG && true);
 %0A%0A  
@@ -994,531 +994,873 @@
     
-//TODO: error message%0A      this.file = null;%0A      return false;%0A    %7D%0A%0A    ReadFile rf = new ReadFile();%0A    if (!rf.open(this.file)) %7B%0A      //TODO: error message%0A      return false;%0A    %7D%0A    String line;%0A    while ((line = rf.getNextLine()) != null) %7B%0A      this.lines.add(line);%0A    %7D%0A    rf.close();%0A%0A    return true;%0A  %7D%0A%0A  public boolean dumpToFile(File file) %7B%0A    if (file == null) %7B%0A      //TODO: error%0A      return false;%0A    %7D%0A%0A    WriteFile wf = new WriteFile();%0A    if (!wf.open(file)) %7B%0A      //TODO: error
+if (CLASS_DEBUG) %7B%0A        LOGGER.log(Constants.DEFAULT_LOG_LEVEL, Debugging.createFail(file));%0A      %7D%0A      reset();%0A      return false;%0A    %7D%0A%0A    ReadFile rf = new ReadFile();%0A    if (!rf.open(this.file)) %7B%0A      if (CLASS_DEBUG) %7B%0A        LOGGER.log(Constants.DEFAULT_LOG_LEVEL, Debugging.openFail(file));%0A      %7D%0A      reset();%0A      return false;%0A    %7D%0A    String line;%0A    while ((line = rf.getNextLine()) != null) %7B%0A      this.lines.add(line);%0A    %7D%0A    rf.close();%0A%0A    return true;%0A  %7D%0A%0A  public boolean dumpToFile(File file) %7B%0A    if (file == null) %7B%0A      if (CLASS_DEBUG) %7B%0A        LOGGER.log(Constants.DEFAULT_LOG_LEVEL, Debugging.nullObject());%0A      %7D%0A      return false;%0A    %7D%0A%0A    WriteFile wf = new WriteFile();%0A    if (!wf.open(file)) %7B%0A      if (CLASS_DEBUG) %7B%0A        LOGGER.log(Constants.DEFAULT_LOG_LEVEL, Debugging.openFail(file));%0A      %7D
 %0A   

Refactor MemoryFile.java