|
|
@@ -8,13 +8,8 @@
|
|
|
package net.ranides.assira.io;
|
|
|
|
|
|
import java.io.*;
|
|
|
-import java.security.AccessController;
|
|
|
-import java.security.PrivilegedAction;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
import java.util.MissingResourceException;
|
|
|
-import java.util.Scanner;
|
|
|
import net.ranides.assira.generic.PrivilegedActions;
|
|
|
import net.ranides.assira.generic.ValueUtils;
|
|
|
import net.ranides.assira.trace.StackInspector;
|
|
|
@@ -54,7 +49,7 @@ public final class FileHelper {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static byte[] getFileContent(File file) throws IOException {
|
|
|
+ public static byte[] getContent(File file) throws IOException {
|
|
|
RandomAccessFile istream = new RandomAccessFile(file, "r");
|
|
|
byte[] content = new byte[ (int)istream.length() ];
|
|
|
istream.readFully(content);
|
|
|
@@ -68,90 +63,10 @@ public final class FileHelper {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static byte[] getFileContent(String file) throws IOException {
|
|
|
- return getFileContent(new File(file));
|
|
|
+ public static byte[] getContent(String file) throws IOException {
|
|
|
+ return getContent(new File(file));
|
|
|
}
|
|
|
|
|
|
- public static List<String> getFileText(File file, String charset) throws IOException {
|
|
|
- FileInputStream istream = null;
|
|
|
- BufferedReader reader = null;
|
|
|
- ArrayList<String> result = new ArrayList<String>();
|
|
|
- try {
|
|
|
- istream = new FileInputStream(file);
|
|
|
- reader = new BufferedReader(new InputStreamReader(istream, charset));
|
|
|
- String line;
|
|
|
- while( null != (line=reader.readLine())) {
|
|
|
- result.add(line);
|
|
|
- }
|
|
|
- } finally {
|
|
|
- FileHelper.close(reader);
|
|
|
- FileHelper.close(istream);
|
|
|
- }
|
|
|
- result.trimToSize();
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public static List<String> getFileText(String file, String charset) throws IOException {
|
|
|
- return getFileText(new File(file), charset);
|
|
|
- }
|
|
|
-
|
|
|
- public static List<String> getFileText(File file) throws IOException {
|
|
|
- return getFileText(file, "UTF-8");
|
|
|
- }
|
|
|
-
|
|
|
- public static List<String> getFileText(String file) throws IOException {
|
|
|
- return getFileText(file, "UTF-8");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Ładuje zawartość podanego pliku i zwraca w postaci tekstu.
|
|
|
- * Funkcja do przetworzenia tekstu używa podanego kodowania znaków.
|
|
|
- * @param file
|
|
|
- * @param charset
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public static String getFileTextContent(File file, String charset) throws IOException {
|
|
|
- Scanner scanner = new Scanner(file, charset);
|
|
|
- String result = scanner.useDelimiter("\\Z").next();
|
|
|
- scanner.close();
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Ładuje zawartość podanego pliku i zwraca w postaci tekstu.
|
|
|
- * Funkcja do przetworzenia tekstu używa podanego kodowania znaków.
|
|
|
- * @param file
|
|
|
- * @param charset
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public static String getFileTextContent(String file, String charset) throws IOException {
|
|
|
- return getFileTextContent(new File(file), charset);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Ładuje zawartość podanego pliku i zwraca w postaci tekstu.
|
|
|
- * Funkcja do przetworzenia tekstu używa kodowania UTF-8.
|
|
|
- * @param file
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public static String getFileTextContent(File file) throws IOException {
|
|
|
- return getFileTextContent(file, "UTF-8");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Ładuje zawartość podanego pliku i zwraca w postaci tekstu.
|
|
|
- * Funkcja do przetworzenia tekstu używa kodowania UTF-8.
|
|
|
- * @param file
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public static String getFileTextContent(String file) throws IOException {
|
|
|
- return getFileTextContent(new File(file));
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Zamyka podany plik. Funkcja odporna na {@code null}. Nie rzuca wyjątków.
|
|
|
* <table style="margin: 10px 0 0 0; background: #c0F0c0; border: solid 1px #006000;" cellpadding="0"><tr><td>{@code null} safe method</td></tr></table>
|