Package hlcd.exporter

Class CodeObjectIO

java.lang.Object
hlcd.exporter.CodeObjectIO

public class CodeObjectIO extends Object
Exports the code found to file as a persistent object (.bin file). Unlike CodeExporter, this will automatically override the file if it already exists because it doesn't use a timestamp.
 //minimal example to execute this class:
 public static void main(String[] args) {
     System.out.println("Running CodeObjectIO...");
     byte n = 7;
     byte k = 4;
     byte d = 3;
     byte base = 4;
     boolean printPathToConsole = true;
     CodeParameters cp = new CodeParameters(n, k, d, base);
     CodeValidatorParameters cvp = new CodeValidatorParameters();
     CodeExporterParameters cep = new CodeExporterParameters();
     Code code = new Code(cp, cvp);
     code.startEngine();
     CodeObjectIO co = new CodeObjectIO(
        code,               //the code object to export
        Paths.DEFAULT_PATH, //path to write to
        "0",                //the id of the generator matrix
        printPathToConsole  //should print the path of the file
     );
     System.out.println("The generator matrix of the code to be written:");
     code.printGeneratorMatrix(true, Style.DECIMAL, true);
     co.writeCodeObject();
     Code c2 = co.readCodeObject();
     System.out.println("The generator matrix of the code read:");
     code.printGeneratorMatrix(true, Style.DECIMAL, true);
     System.out.println("CodeObjectIO completed.");
 }
Since:
1.8
Version:
1.0 (January 24th, 2022)
Author:
Maysara Al Jumaily
  • Constructor Details

    • CodeObjectIO

      public CodeObjectIO(Code code, String filepath, String id, boolean printPathToConsole)
      Initializes the Code object I/O based on the parameters specified. Requires the filepath as well as the code found in order to write it as a persistent object.
      Parameters:
      filepath - the filepath to write the .bin file in
      code - the code to write as a persistent object
      id - the id of the code instance (can be left as "0")
      printPathToConsole - should the file paths generated be printed to console
  • Method Details

    • writeCodeObject

      public void writeCodeObject()
      Writes the code object that was passed in the constructor.
    • readCodeObject

      public Code readCodeObject()
      Reads the .bin file that was previously written.

      TODO: This is not a complete method to use when running the program. It needs to be appropriately implemented so that it reads specified filename in a specific folder. Maybe pass the filepath as well as the filename here.

      Returns:
      the code object that was read