Reads SQL statements from file. SQL commands in file must be separated by
a semicolon.

@param url url of the file
@return array of command  strings
355516
private static String[] readSqlStatements(URL url) {
        try {
            char buffer[] = new char[256];
            StringBuilder result = new StringBuilder();
            InputStreamReader reader = new InputStreamReader(url.openStream(), "UTF-8");
            while (true) {
                int count = reader.read(buffer);
                if (count < 0) {
                    break;
                }
                result.append(buffer, 0, count);
            }
            return result.toString().split(";");
        } catch (IOException ex) {
            throw new RuntimeException("Cannot read " + url, ex);
        }
    }
476674
public static <T extends Collection<String>> T readUtf8Lines(URL url, T collection) throws IORuntimeException {
		return readLines(url, CharsetUtil.CHARSET_UTF_8, collection);
	}
99261
@Override
	public List<Sentence> readFile(String datafile) {
		// TODO Auto-generated method stub
		// read all data into a data string
		String dataStr = "";
		try{
			BufferedReader in = new BufferedReader(new InputStreamReader(
					new FileInputStream(datafile), "UTF-8"));
			String line;
			int count = 0;
			while ((line = in.readLine()) != null){
				System.out.println("Line " + count++);
				dataStr += line + "\n";
			}
			in.close();			
		}
		catch (Exception e){
			System.out.println(e.getMessage());
			return null;
		}
		return readString(dataStr);
	}
1044423
public static Environment parse(URL url) throws IOException {
		try {
			return new ConfigUtil.LowerCaseYamlMapper().readValue(url, Environment.class);
		} catch (JsonMappingException e) {
			throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
		}
	}
1110524
public String[] getColumnsBySql(Sql sql) throws SQLException {
		String columns[] = null;
		
		List<Map<String, String>> table = getMetadataBySql(sql);
		if (table != null) {
			columns = new String[table.size()];
			for (int i = 0 ; i < table.size() ; i++) {
				Map<String, String> row = table.get(i);
				if (row.containsKey("NAME") && row.get("NAME") != null) {
					columns[i] = row.get("NAME");
				}
			}
		}
		
		return columns;
	}
1056227
public static List<String> readLines(URL url, String charset) throws IORuntimeException {
		return readLines(url, charset, new ArrayList<String>());
	}
1365389
public static String readAsString(final URL url, final String encoding, final int bufSize) {
        try (final Reader reader = new InputStreamReader(url.openStream(), encoding)) {
            final StringBuilder sb = new StringBuilder();
            final char[] cbuf = new char[bufSize];
            int count;
            while ((count = reader.read(cbuf)) > -1) {
                sb.append(String.valueOf(cbuf, 0, count));
            }
            return sb.toString();
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
    }
314981
private static void executeSqlScript(Connection connection, URL scriptUrl) throws SQLException {
        for (String sqlStatement : readSqlStatements(scriptUrl)) {
            if (!sqlStatement.trim().isEmpty()) {
                connection.prepareStatement(sqlStatement).executeUpdate();
            }
        }
    }
406940
private CommandOutput<?, ?> executePreparedSql(List<Command> cmds) {
    String query = null;
    List<String> queryParameters = null;
    int fetchSize = 0;

    for (Command cmd : cmds) {
      if (cmd instanceof JdbcCommand) {
        JdbcCommandType type = (JdbcCommandType) cmd.getCommandType();
        switch (type) {
          case QUERY:
            query = cmd.getParams().get(0);
            break;
          case QUERYPARAMS:
            queryParameters = cmd.getParams();
            break;
          case FETCHSIZE:
            fetchSize = Integer.parseInt(cmd.getParams().get(0));
            break;
          default:
            this.log.error("Command " + type.toString() + " not recognized");
            break;
        }
      }
    }

    this.log.info("Executing query:" + query);
    ResultSet resultSet = null;
    try {
      this.jdbcSource = createJdbcSource();
      if (this.dataConnection == null) {
        this.dataConnection = this.jdbcSource.getConnection();
      }

      PreparedStatement statement =
          this.dataConnection.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

      int parameterPosition = 1;
      if (queryParameters != null && queryParameters.size() > 0) {
        for (String parameter : queryParameters) {
          statement.setString(parameterPosition, parameter);
          parameterPosition++;
        }
      }
      if (fetchSize != 0) {
        statement.setFetchSize(fetchSize);
      }
      final boolean status = statement.execute();
      if (status == false) {
        this.log.error("Failed to execute sql:" + query);
      }
      resultSet = statement.getResultSet();

    } catch (Exception e) {
      this.log.error("Failed to execute sql:" + query + " ;error-" + e.getMessage(), e);
    }

    CommandOutput<JdbcCommand, ResultSet> output = new JdbcCommandOutput();
    output.put((JdbcCommand) cmds.get(0), resultSet);
    return output;
  }
1045609
public static String readString(URL url, String charset) throws IORuntimeException {
		if (url == null) {
			throw new NullPointerException("Empty url provided!");
		}

		InputStream in = null;
		try {
			in = url.openStream();
			return IoUtil.read(in, charset);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		} finally {
			IoUtil.close(in);
		}
	}
506441
public static <T extends Collection<String>> T readLines(URL url, Charset charset, T collection) throws IORuntimeException {
		InputStream in = null;
		try {
			in = url.openStream();
			return IoUtil.readLines(in, charset, collection);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		} finally {
			IoUtil.close(in);
		}
	}
70643
@SuppressWarnings("MagicNumber")
    public static Optional<JdbcDatabase> findDatabase(String jdbcUrl) {
        if (StringUtils.isNotEmpty(jdbcUrl)) {
            if (!jdbcUrl.startsWith("jdbc")) {
                throw new IllegalArgumentException("JDBC URLs must start with 'jdbc'");
            }
            String partialUrl = jdbcUrl.substring(5);
            String prefix = partialUrl.substring(0, partialUrl.indexOf(':')).toLowerCase();

            return databases.stream().filter(db -> db.containsPrefix(prefix)).findFirst();
        }
        return Optional.empty();
    }
480411
public static Study readStudy(final URL url) throws IOException {
        checkNotNull(url);
        try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) {
            return readStudy(reader);
        }
    }
116308
public static List<String> readSQLFromFile(String fileName) {
		try {
			return readSQLFromFile(new FileInputStream(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}
666114
@Override
    public String[] readLine(int line, boolean readResult) throws TechnicalException {
        String sqlRequest;
        try {
            final Path file = Paths.get(dataInPath + scenarioName + ".sql");
            sqlRequest = new String(Files.readAllBytes(file), Charset.forName(Constants.DEFAULT_ENDODING));
            sqlSanitized4readOnly(sqlRequest);
        } catch (final IOException e) {
            throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE) + e.getMessage(), e);
        }
        try (Connection connection = getConnection(); PreparedStatement statement = connection.prepareStatement(sqlRequest); ResultSet rs = statement.executeQuery();) {
            final String[] ret = readResult ? new String[columns.size()] : new String[columns.size() - 1];
            if (line == 0) {
                for (int i = 0; i < ret.length; i++) {
                    ret[i] = columns.get(i);
                }
            } else {
                while (rs.next() && rs.getRow() < line) {
                }
                for (int i = 1; i <= ret.length; i++) {
                    ret[i - 1] = rs.getString(i);
                }
            }
            return ret;
        } catch (final SQLException e) {
            logger.debug("In DBDataProvider, this catch aims for testing the end of provided data. DBDataProvider.readLine({}, {})", line, readResult, e);
            return null;
        }
    }
803335
public static Sql newInstance(String url) throws SQLException {
        Connection connection = DriverManager.getConnection(url);
        return new Sql(connection);
    }
740433
public static List<String> extractUriParams(String url) {
		List<String> outParams = new ArrayList<>();
		if (StringUtils.hasText(url)) {
			String[] split = StringUtils.split(url, "/");
			for (String part : split) {
				int indexOfStart = part.indexOf("{");
				int indexOfEnd = part.indexOf("}");
				if (indexOfStart != -1 && indexOfEnd != -1 && indexOfStart < indexOfEnd) {
					outParams.add(part.substring(indexOfStart + 1, indexOfEnd));
				}
			}

		}
		return outParams;
	}