Package io.github.andreipunko.util
Class FileUtil
java.lang.Object
io.github.andreipunko.util.FileUtil
Utilities to write text data to files. All textual output uses UTF-8.
saveFunc(io.github.andreipunko.math.space.Interval, java.util.function.Function<java.lang.Double, java.lang.Double>, java.lang.String), save(Matrix2D, String, boolean), and PDE Solution
methods (Solution.sUt(String, double[]), Solution.sUx(String, double[]))
prefix a short # header and format numbers with formatDouble(double) (data comes from Solution.matrix()).-
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDouble(double value) Locale-independent numeric text for exports: US decimal point,%.17g(up to 17 significant digits).static voidSave matrix into file.static voidSave function y(x) on given interval into file.static voidsaveFunc(Interval timeInterval, Function<Double, Double> xFunc, Function<Double, Double> yFunc, String fileName) Save function y(x) on given time interval into file for parameterized functions x(t) and y(t).static voidserialize(StringBuilder sb, String fileName) Save text data from StringBuilder instance into file using UTF-8 encoding.
-
Method Details
-
formatDouble
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
Save text data from StringBuilder instance into file using UTF-8 encoding.- Parameters:
sb- StringBuilder instancefileName- name of file (parent directories are created if they do not exist)- Throws:
IllegalArgumentException- if sb or fileName is nullIOException- 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 IOExceptionSave function y(x) on given interval into file. Lines starting with#describe columns; data rows useformatDouble(double).- Parameters:
interval- intervalfunc- function y = y(x)fileName- name of file- Throws:
IllegalArgumentException- if interval, func or fileName is nullIOException- if an I/O error occurs writing the file
-
saveFunc
public static void saveFunc(Interval timeInterval, Function<Double, Double> xFunc, Function<Double, throws IOExceptionDouble> yFunc, String fileName) 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 useformatDouble(double).- Parameters:
timeInterval- time intervalxFunc- function x = x(t)yFunc- function y = y(t)fileName- name of file- Throws:
IllegalArgumentException- if any argument is nullIOException- if an I/O error occurs writing the file
-
save
Save matrix into file. Lines starting with#give dimensions and layout; data rows useformatDouble(double).- Parameters:
m- matrix to savefileName- name of filerotate- flag - rotate matrix or not before saving- Throws:
IllegalArgumentException- if m or fileName is nullIOException- if an I/O error occurs writing the file
-