1 24 25 package org.objectweb.cjdbc.scenario.tools.util; 26 27 import java.io.BufferedReader ; 28 import java.io.IOException ; 29 import java.io.Reader ; 30 31 36 public class MyBufferedReader extends BufferedReader 37 { 38 39 private static final String BEGIN_REQUEST = "#begin"; 40 41 42 private static final String END_REQUEST = "#end"; 43 44 47 private String fileDescription; 48 49 55 public MyBufferedReader(Reader reader, String description) 56 { 57 super(reader); 58 fileDescription = description; 59 } 60 61 67 public boolean readBoolean() throws IOException 68 { 69 String line = readLine(); 70 if ("true".equals(line)) 71 return true; 72 else if ("false".equals(line)) 73 return false; 74 throw new IOException ( 75 "Syntax error in " 76 + fileDescription 77 + " file: unknow token '" 78 + line 79 + "' found, expected 'true' or 'false'"); 80 } 81 82 89 public String readString(String stringName) throws IOException 90 { 91 String line = readLine(); 92 93 if ((line == null) || line.equals("")) 94 throw new IOException ( 95 "Syntax error in " 96 + fileDescription 97 + " file: " 98 + stringName 99 + " missing"); 100 return line; 101 } 102 103 112 public String readSQLRequest(String line) throws IOException 113 { 114 if (!BEGIN_REQUEST.equals(line)) 115 throw new IOException ( 116 "Syntax error in requests file: '" 117 + BEGIN_REQUEST 118 + "' token expected instead of '" 119 + line 120 + "')"); 121 122 StringBuffer buffer = new StringBuffer (); 123 while (((line = readLine()) != null) && !line.equals(END_REQUEST)) 124 { 125 buffer.append(line); 126 buffer.append(System.getProperty("line.separator")); 127 } 128 String request = buffer.toString(); 129 130 if (!END_REQUEST.equals(line)) 131 throw new IOException ( 132 "Syntax error in requests file: '" + END_REQUEST + "' token not found"); 133 134 return request; 135 } 136 137 142 public String readNextLine() throws IOException 143 { 144 String line = this.readLine(); 145 while((line!=null)&&(line.startsWith("//")||line.startsWith("#"))) 146 line = readLine(); 147 return line; 148 } 149 150 } | Popular Tags |