示例#1
0
 /**
  * Read a script from the provided {@code LineNumberReader}, using the supplied comment prefix and
  * statement separator, and build a {@code String} containing the lines.
  *
  * <p>Lines <em>beginning</em> with the comment prefix are excluded from the results; however,
  * line comments anywhere else &mdash; for example, within a statement &mdash; will be included in
  * the results.
  *
  * @param lineNumberReader the {@code LineNumberReader} containing the script to be processed
  * @param commentPrefix the prefix that identifies comments in the SQL script &mdash; typically
  *     "--"
  * @param separator the statement separator in the SQL script &mdash; typically ";"
  * @return a {@code String} containing the script lines
  * @throws IOException in case of I/O errors
  */
 public static String readScript(
     LineNumberReader lineNumberReader, String commentPrefix, String separator)
     throws IOException {
   String currentStatement = lineNumberReader.readLine();
   StringBuilder scriptBuilder = new StringBuilder();
   while (currentStatement != null) {
     if (commentPrefix != null && !currentStatement.startsWith(commentPrefix)) {
       if (scriptBuilder.length() > 0) {
         scriptBuilder.append('\n');
       }
       scriptBuilder.append(currentStatement);
     }
     currentStatement = lineNumberReader.readLine();
   }
   appendSeparatorToScriptIfNecessary(scriptBuilder, separator);
   return scriptBuilder.toString();
 }