|
|
@@ -28,6 +28,12 @@ import net.ranides.assira.io.FileHelper;
|
|
|
* @author ranides
|
|
|
*/
|
|
|
public final class StringLoader {
|
|
|
+
|
|
|
+ public static class RIOException extends RuntimeException {
|
|
|
+ public RIOException(IOException cause) {
|
|
|
+ super(cause);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private StringLoader() { }
|
|
|
|
|
|
@@ -54,26 +60,30 @@ public final class StringLoader {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static String fromFile(File file, Charset charset) throws IOException {
|
|
|
- return fromStream( new FileInputStream(file), charset );
|
|
|
+ public static String fromFile(File file, Charset charset) throws RIOException {
|
|
|
+ try {
|
|
|
+ return fromStream( new FileInputStream(file), charset );
|
|
|
+ } catch(IOException cause) {
|
|
|
+ throw new RIOException(cause);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public static String fromFile(File file) throws IOException {
|
|
|
+ public static String fromFile(File file) throws RIOException {
|
|
|
return fromFile(file, TextEncoding.NIO_UTF8);
|
|
|
}
|
|
|
|
|
|
- public static String fromFile(String path, Charset charset) throws IOException {
|
|
|
+ public static String fromFile(String path, Charset charset) throws RIOException {
|
|
|
return fromFile(new File(path), charset);
|
|
|
}
|
|
|
|
|
|
- public static String fromFile(String path) throws IOException {
|
|
|
+ public static String fromFile(String path) throws RIOException {
|
|
|
return fromFile(path, TextEncoding.NIO_UTF8 );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Ładuje plik ".properties", zachowując kolejność wpisów.
|
|
|
*/
|
|
|
- public static LinkedHashMap<String,String> loadProperties(Reader reader) throws IOException {
|
|
|
+ public static LinkedHashMap<String,String> loadProperties(Reader reader) throws RIOException {
|
|
|
try {
|
|
|
LinkedHashMap<String,String> target = new LinkedHashMap<String,String>();
|
|
|
StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(reader));
|
|
|
@@ -97,13 +107,14 @@ public final class StringLoader {
|
|
|
String value = tokenizer.sval.trim();
|
|
|
target.put(key, value);
|
|
|
}
|
|
|
-
|
|
|
- } finally {
|
|
|
- reader.close();
|
|
|
+ } catch(IOException cause) {
|
|
|
+ throw new RIOException(cause);
|
|
|
+ } finally {
|
|
|
+ FileHelper.close(reader);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static List<String> linesFromFile(File file, Charset charset) throws IOException {
|
|
|
+ public static List<String> linesFromFile(File file, Charset charset) throws RIOException {
|
|
|
FileInputStream istream = null;
|
|
|
BufferedReader reader = null;
|
|
|
ArrayList<String> result = new ArrayList<String>();
|
|
|
@@ -114,6 +125,8 @@ public final class StringLoader {
|
|
|
while( null != (line=reader.readLine())) {
|
|
|
result.add(line);
|
|
|
}
|
|
|
+ } catch(IOException cause) {
|
|
|
+ throw new RIOException(cause);
|
|
|
} finally {
|
|
|
FileHelper.close(reader);
|
|
|
FileHelper.close(istream);
|
|
|
@@ -122,15 +135,15 @@ public final class StringLoader {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public static List<String> linesFromFile(String file, Charset charset) throws IOException {
|
|
|
+ public static List<String> linesFromFile(String file, Charset charset) throws RIOException {
|
|
|
return linesFromFile(new File(file), charset);
|
|
|
}
|
|
|
|
|
|
- public static List<String> linesFromFile(File file) throws IOException {
|
|
|
+ public static List<String> linesFromFile(File file) throws RIOException {
|
|
|
return linesFromFile(file, TextEncoding.NIO_UTF8);
|
|
|
}
|
|
|
|
|
|
- public static List<String> linesFromFile(String file) throws IOException {
|
|
|
+ public static List<String> linesFromFile(String file) throws RIOException {
|
|
|
return linesFromFile(file, TextEncoding.NIO_UTF8);
|
|
|
}
|
|
|
|