Class FileUtil

java.lang.Object
io.github.andreipunko.util.FileUtil

public class FileUtil extends Object
  • Method Details

    • formatDouble

      public static String formatDouble(double value)
      Locale-independent numeric text for exports: US decimal point, %.17g (up to 17 significant digits).
      Parameters:
      value - number to format
      Returns:
      formatted string suitable for text export files
    • serialize

      public static void serialize(StringBuilder sb, String fileName) throws IOException
      Save text data from StringBuilder instance into file using UTF-8 encoding.
      Parameters:
      sb - StringBuilder instance
      fileName - name of file (parent directories are created if they do not exist)
      Throws:
      IllegalArgumentException - if sb or fileName is null
      IOException - if an I/O error occurs creating directories or writing the file
    • saveFunc

      public static void saveFunc(Interval interval, Function<Double,Double> func, String fileName) throws IOException
      Save function y(x) on given interval into file. Lines starting with # describe columns; data rows use formatDouble(double).
      Parameters:
      interval - interval
      func - function y = y(x)
      fileName - name of file
      Throws:
      IllegalArgumentException - if interval, func or fileName is null
      IOException - if an I/O error occurs writing the file
    • saveFunc

      public static void saveFunc(Interval timeInterval, Function<Double,Double> xFunc, Function<Double,Double> yFunc, String fileName) throws IOException
      Save function y(x) on given time interval into file for parameterized functions x(t) and y(t). Lines starting with # describe columns; data rows use formatDouble(double).
      Parameters:
      timeInterval - time interval
      xFunc - function x = x(t)
      yFunc - function y = y(t)
      fileName - name of file
      Throws:
      IllegalArgumentException - if any argument is null
      IOException - if an I/O error occurs writing the file
    • save

      public static void save(Matrix2D m, String fileName, boolean rotate) throws IOException
      Save matrix into file. Lines starting with # give dimensions and layout; data rows use formatDouble(double).
      Parameters:
      m - matrix to save
      fileName - name of file
      rotate - flag - rotate matrix or not before saving
      Throws:
      IllegalArgumentException - if m or fileName is null
      IOException - if an I/O error occurs writing the file