Class FileReader

java.lang.Object
org.cloudsimplus.traces.FileReader
Direct Known Subclasses:
TraceReaderAbstract

public class FileReader extends Object
Reads and parses data inside text, zip and gzip files.
Since:
CloudSim Plus 8.1.0
Author:
Manoel Campos da Silva Filho, Anton Beloglazov
  • Field Details

  • Constructor Details

    • FileReader

      public FileReader(@NonNull @NonNull String filePath)
      Creates a file reader that considers spaces as field delimiter.
      Parameters:
      filePath - path of the file to read
      See Also:
    • FileReader

      public FileReader(String fieldDelimiterRegex, @NonNull @NonNull String filePath)
    • FileReader

      public FileReader(@NonNull @NonNull String filePath, int maxLinesToRead)
      Creates a file reader that considers spaces as field delimiter.
      Parameters:
      filePath - path of the file to read
      maxLinesToRead - The maximum number of lines from the trace reader that will be read. Integer.MAX_VALUE indicates that all lines will be read.
      See Also:
    • FileReader

      public FileReader(String fieldDelimiterRegex, @NonNull @NonNull String filePath, int maxLinesToRead)
      Creates a file reader.
      Parameters:
      fieldDelimiterRegex - A regex defining how fields are delimited in the trace file. See
      invalid reference
      #getFieldDelimiterRegex()
      for details.
      filePath - path of the file to read
      maxLinesToRead - The maximum number of lines from the trace reader that will be read. Integer.MAX_VALUE indicates that all lines will be read.
      See Also:
  • Method Details

    • getSingleLineReader

      public static FileReader getSingleLineReader(@NonNull @NonNull String filePath)
      Gets a reader that parses only the first line inside the given file, considering space as the field delimiter
      Parameters:
      filePath - the path of the file to read
      Returns:
      the file reader
    • setCommentString

      public FileReader setCommentString(@NonNull @NonNull String... commentString)
      Sets Strings that identify the start of a comment line.
      Parameters:
      commentString - the comment Strings to set
    • getCommentString

      public String[] getCommentString()
      Gets the Strings that identifies the start of a comment line.
      For instance ; # % //, according to the file to read.
    • setMaxLinesToRead

      public final FileReader setMaxLinesToRead(int maxLinesToRead)
      Sets the maximum number of lines from the workload reader that will be read. Integer.MAX_VALUE indicates that all lines will be read.
      Parameters:
      maxLinesToRead - the maximum number of lines to set
      Returns:
      the file reader
    • readFile

      public String[] readFile()
      Reads a trace file indicated by the
      invalid reference
      #getFilePath()
      .
      Returns:
      the last parsed line
      Throws:
      UncheckedIOException - if there was any error reading the file
    • readFile

      protected String[] readFile(Function<String[],Boolean> processParsedLineFunc)
      Reads a trace file indicated by the
      invalid reference
      #getFilePath()
      . It performs additional processing after parsing the line.
      Parameters:
      processParsedLineFunc - a Function that receives each parsed line as an array and performs an operation over it, returning true if the operation was executed
      Returns:
      the last parsed line
      Throws:
      UncheckedIOException - if there was any error reading the file