01: /*
02: * SQLeonardo :: java database frontend
03: * Copyright (C) 2004 nickyb@users.sourceforge.net
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: *
19: */
20:
21: package nickyb.sqleonardo.environment.io;
22:
23: import java.io.FileReader;
24: import java.io.FileWriter;
25: import java.io.IOException;
26: import java.io.Reader;
27: import java.io.Writer;
28:
29: import nickyb.sqleonardo.querybuilder.QueryModel;
30: import nickyb.sqleonardo.querybuilder.syntax.SQLParser;
31:
32: public class FileStreamSQL {
33: /* reader */
34: public static QueryModel read(String filename) throws IOException,
35: ClassNotFoundException {
36: Reader in = new FileReader(filename);
37: StringBuffer sb = new StringBuffer();
38:
39: int nch;
40: char[] buff = new char[4096];
41: while ((nch = in.read(buff, 0, buff.length)) != -1) {
42: sb.append(new String(buff, 0, nch));
43: }
44: in.close();
45:
46: return SQLParser.toQueryModel(sb.toString());
47: }
48:
49: /* writer */
50: public static void write(String filename, QueryModel model)
51: throws IOException {
52: Writer out = new FileWriter(filename);
53: out.write(model.toString(true));
54: out.flush();
55: out.close();
56: }
57: }
|