Here you can find the source of extractCommandsFromLine(final String line, final String delimiter, final StringBuilder bufferedCommand, final List
Parameter | Description |
---|---|
line | Line which is searched for SQL commands. |
delimiter | Delimiter that ends SQL command. Used for dividing specified string (line). |
bufferedCommand | Already buffered command from previous searches. If there's some buffered command, this method appends the first found delimited occurence to buffered command. If there's no buffered command and the string (line) not ends with delimiter, the last part is buffered. |
extractedCommands | Results list to which are found SQL commands added. |
private static void extractCommandsFromLine(final String line, final String delimiter, final StringBuilder bufferedCommand, final List<String> extractedCommands)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { /**/*from www. java2 s .com*/ * Extracts SQL commands from string. Divides the string (line) by specified delimiter * and adds found whole commands to extractedCommands or buffers unfinished commands. * @param line Line which is searched for SQL commands. * @param delimiter Delimiter that ends SQL command. Used for dividing specified string (line). * @param bufferedCommand Already buffered command from previous searches. * If there's some buffered command, this method appends the first * found delimited occurence to buffered command. * If there's no buffered command and the string (line) not ends * with delimiter, the last part is buffered. * @param extractedCommands Results list to which are found SQL commands added. */ private static void extractCommandsFromLine(final String line, final String delimiter, final StringBuilder bufferedCommand, final List<String> extractedCommands) { final String[] lineParts = line.split(delimiter); for (int i = 0; i < lineParts.length; i++) { // If there's some buffered command, append first found line part to it. if (i == 0) { extractedCommands.add(bufferedCommand.toString() + " " + lineParts[i]); bufferedCommand.setLength(0); bufferedCommand.trimToSize(); } else { // If the line doesn't end with delimiter, buffer the last line part. if (i == (lineParts.length - 1) && !line.endsWith(delimiter)) { bufferedCommand.append(lineParts[i]); } else { extractedCommands.add(lineParts[i]); } } } } }