Skip to content

Commit

Permalink
FileUtil UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
SoccerFive18 committed Jan 27, 2024
1 parent 5731d92 commit b920df4
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 10 deletions.
20 changes: 20 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ javadoc*
**/classes/**
**/RegressionTestData_Extracted/**
**/output/**
/target/
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>OpenTDK</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
10 changes: 10 additions & 0 deletions src/org/opentdk/api/datastorage/TabularContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@ public List<String[]> getColumnsList(String[] columnHeaders, int[] rowIndexes, F
return colList;
}

public List<?> getColumnsList(Filter rowFilter, Class<?> storageObject) {
List<?> ret = new ArrayList<>();
List<String[]> rows = getColumnsList(new String[0], new int[0], rowFilter);
for(String[] row : rows) {
for(int i = 0; i < row.length; i++) {
// .. TODO
}
}
return ret;
}

public int getHeaderIndex(String headerName) {
int retVal = -1;
Expand Down
1 change: 0 additions & 1 deletion src/org/opentdk/api/datastorage/TreeContainer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.opentdk.api.datastorage;

import org.opentdk.api.filter.Filter;
import org.w3c.dom.Element;

public interface TreeContainer extends SpecificContainer {

Expand Down
1 change: 0 additions & 1 deletion src/org/opentdk/api/dispatcher/BaseDispatchComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import java.io.IOException;
import java.util.logging.Level;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.opentdk.api.application.EBaseSettings;
Expand Down
39 changes: 32 additions & 7 deletions src/org/opentdk/api/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,21 +470,33 @@ public static String getRowsAsString(File file) {
public static String getRowsAsString(String path) {
return getRowsAsString(path, -1);
}

/**
* Read the lines of a ASCII file to a String by using the {@link java.io.BufferedReader}. This is a
* very fast type of reading. Especially for large files. Line breaks (\n) are included, too.
*
* @param path Full name (path + name) of the file to work with.
* @param lineCount Possibility to determine the number of iterations/lines. Use {@literal -} 1 to
* switch off.
* @param lineCount Possibility to determine the number of iterations/lines. Use {@literal -} 1 to switch off.
* @return A list of type string with all lines of the file as elements.
*/
public static String getRowsAsString(String path, int lineCount) {
return getRowsAsString(path, lineCount, StandardCharsets.UTF_8);
}

/**
* Read the lines of a ASCII file to a String by using the {@link java.io.BufferedReader}. This is a
* very fast type of reading. Especially for large files. Line breaks (\n) are included, too.
*
* @param path Full name (path + name) of the file to work with.
* @param lineCount Possibility to determine the number of iterations/lines. Use {@literal -} 1 to switch off.
* @param encoding Character encoding, see {@link java.nio.charset.StandardCharsets}
* @return A list of type string with all lines of the file as elements.
*/
public static String getRowsAsString(String path, int lineCount, Charset encoding) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
try {
br = new BufferedReader(new FileReader(path));
br = new BufferedReader(new FileReader(path, encoding));

String line = null;
int i = 0;
Expand Down Expand Up @@ -521,18 +533,31 @@ public static List<String> getRowsAsList(File file) {
return FileUtil.getRowsAsList(file.getPath());
}

/**
* Read the lines of a ASCII file to a {@link java.util.List} by using the
* {@link java.io.BufferedReader}. This is a very fast type of reading. Especially for large files.
* Default character encoding is UTF8.
*
* @param path Full name (path + name) of the file to work with.
* @return A list of type string with all lines of the file as elements.
*/
public static List<String> getRowsAsList(String path) {
return getRowsAsList(path, StandardCharsets.UTF_8);
}

/**
* Read the lines of a ASCII file to a {@link java.util.List} by using the
* {@link java.io.BufferedReader}. This is a very fast type of reading. Especially for large files.
*
* @param path Full name (path + name) of the file to work with.
* @param encoding Character encoding, see {@link java.nio.charset.StandardCharsets}
* @return A list of type string with all lines of the file as elements.
*/
public static List<String> getRowsAsList(String path) {
public static List<String> getRowsAsList(String path, Charset encoding) {
BufferedReader br = null;
List<String> rows = new ArrayList<>();
try {
br = new BufferedReader(new FileReader(path));
br = new BufferedReader(new FileReader(path, encoding));

String line = null;
while ((line = br.readLine()) != null) {
Expand Down Expand Up @@ -581,7 +606,7 @@ public static String getContent(String path, Charset cs) {
MLogger.getInstance().log(Level.SEVERE, e);
throw new RuntimeException(e);
}
return FileUtil.getContent(stream, cs);
return getContent(stream, cs);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/org/opentdk/api/io/XMLEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down

0 comments on commit b920df4

Please sign in to comment.