提交 9b21163b authored 作者: Thomas Mueller's avatar Thomas Mueller

Use the file system abstraction whenever possible.

上级 d83e9a32
...@@ -10,7 +10,6 @@ import java.io.BufferedInputStream; ...@@ -10,7 +10,6 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
...@@ -25,7 +24,6 @@ import java.sql.SQLException; ...@@ -25,7 +24,6 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Types; import java.sql.Types;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.util.FileUtils; import org.h2.util.FileUtils;
...@@ -221,12 +219,12 @@ public class Csv implements SimpleRowSource { ...@@ -221,12 +219,12 @@ public class Csv implements SimpleRowSource {
private void initWrite() throws IOException { private void initWrite() throws IOException {
if (output == null) { if (output == null) {
try { try {
OutputStream out = new FileOutputStream(fileName); OutputStream out = FileUtils.openFileOutputStream(fileName, false);
out = new BufferedOutputStream(out, bufferSize); out = new BufferedOutputStream(out, bufferSize);
output = new BufferedWriter(new OutputStreamWriter(out, streamCharset)); output = new BufferedWriter(new OutputStreamWriter(out, streamCharset));
} catch (IOException e) { } catch (SQLException e) {
close(); close();
throw e; throw Message.convertToIOException(e);
} }
} }
} }
......
...@@ -10,7 +10,6 @@ import java.io.BufferedInputStream; ...@@ -10,7 +10,6 @@ import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
...@@ -145,7 +144,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -145,7 +144,7 @@ public class Recover extends Tool implements DataHandler {
* INTERNAL * INTERNAL
*/ */
public static InputStream readBlob(String fileName) throws IOException { public static InputStream readBlob(String fileName) throws IOException {
return new BufferedInputStream(new FileInputStream(fileName)); return new BufferedInputStream(FileUtils.openFileInputStream(fileName));
} }
private void removePassword(String dir, String db) throws SQLException { private void removePassword(String dir, String db) throws SQLException {
......
...@@ -9,17 +9,21 @@ package org.h2.util; ...@@ -9,17 +9,21 @@ package org.h2.util;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileWriter; //import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Writer;
import java.sql.SQLException;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.Vector; import java.util.Vector;
import org.h2.message.Message;
import org.h2.message.TraceSystem; import org.h2.message.TraceSystem;
/** /**
...@@ -105,7 +109,12 @@ public class SortedProperties extends Properties { ...@@ -105,7 +109,12 @@ public class SortedProperties extends Properties {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
InputStreamReader reader = new InputStreamReader(in, "ISO8859-1"); InputStreamReader reader = new InputStreamReader(in, "ISO8859-1");
LineNumberReader r = new LineNumberReader(reader); LineNumberReader r = new LineNumberReader(reader);
FileWriter w = new FileWriter(fileName); Writer w;
try {
w = new OutputStreamWriter(FileUtils.openFileOutputStream(fileName, false));
} catch (SQLException e) {
throw Message.convertToIOException(e);
}
PrintWriter writer = new PrintWriter(new BufferedWriter(w)); PrintWriter writer = new PrintWriter(new BufferedWriter(w));
while (true) { while (true) {
String line = r.readLine(); String line = r.readLine();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论