summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-01 03:23:45 (EDT)
committerEike Stepper2007-08-01 03:23:45 (EDT)
commit9d555b37b8b59e4f2397376c9839d421462b00b1 (patch)
treed22093012ae54920f94a5f0661a9cb485651efb5
parentdc322c6f3ce3dba0bc063a59d780cee54ab138df (diff)
downloadcdo-9d555b37b8b59e4f2397376c9839d421462b00b1.zip
cdo-9d555b37b8b59e4f2397376c9839d421462b00b1.tar.gz
cdo-9d555b37b8b59e4f2397376c9839d421462b00b1.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java55
1 files changed, 48 insertions, 7 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java
index 4a828cb..77161a9 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.util.io;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
@@ -30,6 +32,8 @@ import java.util.List;
*/
public final class IOUtil
{
+ public static final int DEFAULT_BUFFER_SIZE = 8192;
+
private IOUtil()
{
}
@@ -165,6 +169,47 @@ public final class IOUtil
return deleted;
}
+ public static void copyText(File source, File target, IOFilter<String>... lineFilters) throws IORuntimeException
+ {
+ BufferedReader reader = null;
+ BufferedWriter writer = null;
+
+ try
+ {
+ reader = new BufferedReader(openReader(source));
+ writer = new BufferedWriter(openWriter(target));
+
+ copyText(reader, writer, lineFilters);
+ }
+ finally
+ {
+ closeSilent(reader);
+ closeSilent(writer);
+ }
+ }
+
+ public static void copyText(BufferedReader reader, BufferedWriter writer, IOFilter<String>... lineFilters)
+ {
+ try
+ {
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ for (IOFilter<String> lineFilter : lineFilters)
+ {
+ line = lineFilter.filter(line);
+ }
+
+ writer.write(line);
+ writer.newLine();
+ }
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ }
+
public static void copy(InputStream input, OutputStream output, byte buffer[]) throws IORuntimeException
{
try
@@ -188,7 +233,7 @@ public final class IOUtil
public static void copy(InputStream input, OutputStream output) throws IORuntimeException
{
- copy(input, output, 4096);
+ copy(input, output, DEFAULT_BUFFER_SIZE);
}
/**
@@ -201,15 +246,11 @@ public final class IOUtil
try
{
- input = new FileInputStream(source);
- output = new FileOutputStream(target);
+ input = openInputStream(source);
+ output = openOutputStream(target);
copy(input, output);
}
- catch (IOException ex)
- {
- throw new IORuntimeException(ex);
- }
finally
{
closeSilent(input);