org.apache.calcite.util.Util.printWriter()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中org.apache.calcite.util.Util.printWriter()方法的一些代码示例,展示了Util.printWriter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.printWriter()方法的具体详情如下:
包路径:org.apache.calcite.util.Util
类名称:Util
方法名:printWriter

Util.printWriter介绍

[英]Creates a PrintWriter to a given file using UTF-8 character set.

Does not use the default character set.
[中]使用UTF-8字符集为给定文件创建PrintWriter。
不使用默认字符集。

代码示例

代码示例来源:origin: Qihoo360/Quicksql

/** Creates a {@link PrintWriter} to a given file using UTF-8
 * character set.
 *
 * <p>Does not use the default character set. */
public static PrintWriter printWriter(File file)
  throws FileNotFoundException {
 return printWriter(new FileOutputStream(file));
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** Creates a {@link PrintWriter} to a given file using UTF-8
 * character set.
 *
 * <p>Does not use the default character set. */
public static PrintWriter printWriter(File file)
  throws FileNotFoundException {
 return printWriter(new FileOutputStream(file));
}

代码示例来源:origin: Qihoo360/Quicksql

public Iterable<? extends Lattice.Tile> tiles() {
 final Algorithm algorithm = new MonteCarloAlgorithm();
 final PrintWriter pw = Util.printWriter(System.out);
 final Progress progress = new ArgumentUtils.TextProgress(pw);
 final StatisticsProvider statisticsProvider =
   new StatisticsProviderImpl(lattice);
 final double f = statisticsProvider.getFactRowCount();
 final ImmutableMap.Builder<Parameter, Object> map = ImmutableMap.builder();
 if (lattice.algorithmMaxMillis >= 0) {
  map.put(Algorithm.ParameterEnum.timeLimitSeconds,
    Math.max(1, (int) (lattice.algorithmMaxMillis / 1000L)));
 }
 map.put(Algorithm.ParameterEnum.aggregateLimit, 3);
 map.put(Algorithm.ParameterEnum.costLimit, f * 5d);
 final SchemaImpl schema = new SchemaImpl(lattice, statisticsProvider);
 final Result result = algorithm.run(schema, map.build(), progress);
 final ImmutableList.Builder<Lattice.Tile> tiles = ImmutableList.builder();
 for (Aggregate aggregate : result.getAggregates()) {
  tiles.add(toTile(aggregate));
 }
 return tiles.build();
}

代码示例来源:origin: org.apache.calcite/calcite-core

public Iterable<? extends Lattice.Tile> tiles() {
 final Algorithm algorithm = new MonteCarloAlgorithm();
 final PrintWriter pw = Util.printWriter(System.out);
 final Progress progress = new ArgumentUtils.TextProgress(pw);
 final StatisticsProvider statisticsProvider =
   new StatisticsProviderImpl(lattice);
 final double f = statisticsProvider.getFactRowCount();
 final ImmutableMap.Builder<Parameter, Object> map = ImmutableMap.builder();
 if (lattice.algorithmMaxMillis >= 0) {
  map.put(Algorithm.ParameterEnum.timeLimitSeconds,
    Math.max(1, (int) (lattice.algorithmMaxMillis / 1000L)));
 }
 map.put(Algorithm.ParameterEnum.aggregateLimit, 3);
 map.put(Algorithm.ParameterEnum.costLimit, f * 5d);
 final SchemaImpl schema = new SchemaImpl(lattice, statisticsProvider);
 final Result result = algorithm.run(schema, map.build(), progress);
 final ImmutableList.Builder<Lattice.Tile> tiles = ImmutableList.builder();
 for (Aggregate aggregate : result.getAggregates()) {
  tiles.add(toTile(aggregate));
 }
 return tiles.build();
}

代码示例来源:origin: Qihoo360/Quicksql

/**
 * Flushes the reference document to the file system.
 */
private void flushDoc() {
 try {
  boolean b = logFile.getParentFile().mkdirs();
  Util.discard(b);
  try (Writer w = Util.printWriter(logFile)) {
   write(doc, w, indent);
  }
 } catch (IOException e) {
  throw new RuntimeException("error while writing test reference log '"
    + logFile + "'", e);
 }
}

代码示例来源:origin: Qihoo360/Quicksql

private void genValidatorTest() {
 final File file = new File("validatorTest.sql");
 try (PrintWriter pw = Util.printWriter(file)) {
  Method[] methods = getJunitMethods(SqlValidatorSpooler.class);
  for (Method method : methods) {
   final SqlValidatorSpooler test = new SqlValidatorSpooler(pw);
   final Object result = method.invoke(test);
   assert result == null;
  }
 } catch (IOException | IllegalAccessException
   | IllegalArgumentException e) {
  throw new RuntimeException(e);
 } catch (InvocationTargetException e) {
  throw new RuntimeException(e.getCause());
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

private void genValidatorTest() {
 final File file = new File("validatorTest.sql");
 try (PrintWriter pw = Util.printWriter(file)) {
  Method[] methods = getJunitMethods(SqlValidatorSpooler.class);
  for (Method method : methods) {
   final SqlValidatorSpooler test = new SqlValidatorSpooler(pw);
   final Object result = method.invoke(test);
   assert result == null;
  }
 } catch (IOException | IllegalAccessException
   | IllegalArgumentException e) {
  throw new RuntimeException(e);
 } catch (InvocationTargetException e) {
  throw new RuntimeException(e.getCause());
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

/**
 * Flushes the reference document to the file system.
 */
private void flushDoc() {
 try {
  boolean b = logFile.getParentFile().mkdirs();
  Util.discard(b);
  try (Writer w = Util.printWriter(logFile)) {
   write(doc, w, indent);
  }
 } catch (IOException e) {
  throw new RuntimeException("error while writing test reference log '"
    + logFile + "'", e);
 }
}

代码示例来源:origin: Qihoo360/Quicksql

private void checkCustomSchemaInFileInPwd(String fileName)
  throws SQLException {
 final File file = new File(fileName);
 try (PrintWriter pw = Util.printWriter(file)) {
  file.deleteOnExit();
  pw.println("{\n"

代码示例来源:origin: org.apache.calcite/calcite-core

private void checkCustomSchemaInFileInPwd(String fileName)
  throws SQLException {
 final File file = new File(fileName);
 try (PrintWriter pw = Util.printWriter(file)) {
  file.deleteOnExit();
  pw.println("{\n"

代码示例来源:origin: Qihoo360/Quicksql

/** Check that the "get" conversion table looks like Table B-5 in JDBC 4.1
 * specification */
@Test public void testTableB6() {
 SqlType[] columns = {
   SqlType.TINYINT, SqlType.SMALLINT, SqlType.INTEGER, SqlType.BIGINT,
   SqlType.REAL, SqlType.FLOAT, SqlType.DOUBLE, SqlType.DECIMAL,
   SqlType.NUMERIC, SqlType.BIT, SqlType.BOOLEAN, SqlType.CHAR,
   SqlType.VARCHAR, SqlType.LONGVARCHAR, SqlType.BINARY, SqlType.VARBINARY,
   SqlType.LONGVARBINARY, SqlType.DATE, SqlType.TIME, SqlType.TIMESTAMP,
   SqlType.CLOB, SqlType.BLOB, SqlType.ARRAY, SqlType.REF,
   SqlType.DATALINK, SqlType.STRUCT, SqlType.JAVA_OBJECT, SqlType.ROWID,
   SqlType.NCHAR, SqlType.NVARCHAR, SqlType.LONGNVARCHAR, SqlType.NCLOB,
   SqlType.SQLXML
 };
 final PrintWriter out =
   CalcitePrepareImpl.DEBUG
     ? Util.printWriter(System.out)
     : new PrintWriter(new StringWriter());
 for (SqlType.Method row : SqlType.Method.values()) {
  out.print(pad(row.methodName));
  for (SqlType column : columns) {
   out.print(SqlType.canGet(row, column) ? "x " : ". ");
  }
  out.println();
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** Check that the "get" conversion table looks like Table B-5 in JDBC 4.1
 * specification */
@Test public void testTableB6() {
 SqlType[] columns = {
   SqlType.TINYINT, SqlType.SMALLINT, SqlType.INTEGER, SqlType.BIGINT,
   SqlType.REAL, SqlType.FLOAT, SqlType.DOUBLE, SqlType.DECIMAL,
   SqlType.NUMERIC, SqlType.BIT, SqlType.BOOLEAN, SqlType.CHAR,
   SqlType.VARCHAR, SqlType.LONGVARCHAR, SqlType.BINARY, SqlType.VARBINARY,
   SqlType.LONGVARBINARY, SqlType.DATE, SqlType.TIME, SqlType.TIMESTAMP,
   SqlType.CLOB, SqlType.BLOB, SqlType.ARRAY, SqlType.REF,
   SqlType.DATALINK, SqlType.STRUCT, SqlType.JAVA_OBJECT, SqlType.ROWID,
   SqlType.NCHAR, SqlType.NVARCHAR, SqlType.LONGNVARCHAR, SqlType.NCLOB,
   SqlType.SQLXML
 };
 final PrintWriter out =
   CalcitePrepareImpl.DEBUG
     ? Util.printWriter(System.out)
     : new PrintWriter(new StringWriter());
 for (SqlType.Method row : SqlType.Method.values()) {
  out.print(pad(row.methodName));
  for (SqlType column : columns) {
   out.print(SqlType.canGet(row, column) ? "x " : ". ");
  }
  out.println();
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

/**
 * Attempts to execute a simple script file with the -f option to SqlLine.
 * Tests for presence of an expected pattern in the output (stdout or stderr).
 *
 * @param scriptText Script text
 * @param flag Command flag (--run or -f)
 * @param statusMatcher Checks whether status is as expected
 * @param outputMatcher Checks whether output is as expected
 * @throws Exception on command execution error
 */
private void checkScriptFile(String scriptText, boolean flag,
  Matcher<SqlLine.Status> statusMatcher,
  Matcher<String> outputMatcher) throws Throwable {
 // Put the script content in a temp file
 File scriptFile = File.createTempFile("foo", "temp");
 scriptFile.deleteOnExit();
 try (PrintWriter w = Util.printWriter(scriptFile)) {
  w.print(scriptText);
 }
 Pair<SqlLine.Status, String> pair = runScript(scriptFile, flag);
 // Check output before status. It gives a better clue what went wrong.
 assertThat(pair.right, outputMatcher);
 assertThat(pair.left, statusMatcher);
 final boolean delete = scriptFile.delete();
 assertThat(delete, is(true));
}

代码示例来源:origin: Qihoo360/Quicksql

/**
 * Attempts to execute a simple script file with the -f option to SqlLine.
 * Tests for presence of an expected pattern in the output (stdout or stderr).
 *
 * @param scriptText Script text
 * @param flag Command flag (--run or -f)
 * @param statusMatcher Checks whether status is as expected
 * @param outputMatcher Checks whether output is as expected
 * @throws Exception on command execution error
 */
private void checkScriptFile(String scriptText, boolean flag,
  Matcher<SqlLine.Status> statusMatcher,
  Matcher<String> outputMatcher) throws Throwable {
 // Put the script content in a temp file
 File scriptFile = File.createTempFile("foo", "temp");
 scriptFile.deleteOnExit();
 try (PrintWriter w = Util.printWriter(scriptFile)) {
  w.print(scriptText);
 }
 Pair<SqlLine.Status, String> pair = runScript(scriptFile, flag);
 // Check output before status. It gives a better clue what went wrong.
 assertThat(pair.right, outputMatcher);
 assertThat(pair.left, statusMatcher);
 final boolean delete = scriptFile.delete();
 assertThat(delete, is(true));
}

代码示例来源:origin: org.apache.calcite/calcite-core

try (BufferedReader r = Util.reader(inFile);
   FileOutputStream fos = new FileOutputStream(outFile);
   PrintWriter w = Util.printWriter(outFile)) {
 String line;
 int stage = 0;

代码示例来源:origin: Qihoo360/Quicksql

try (BufferedReader r = Util.reader(inFile);
   FileOutputStream fos = new FileOutputStream(outFile);
   PrintWriter w = Util.printWriter(outFile)) {
 String line;
 int stage = 0;

代码示例来源:origin: Qihoo360/Quicksql

public int run(String[] args) {
 try (PrintWriter w = Util.printWriter(System.out)) {
  if (!parseCommand(args)) {
   usage();

代码示例来源:origin: org.apache.calcite/calcite-core

public int run(String[] args) {
 try (PrintWriter w = Util.printWriter(System.out)) {
  if (!parseCommand(args)) {
   usage();

代码示例来源:origin: Qihoo360/Quicksql

Writer writer = Util.printWriter(outFile);
  Closer closer = new Closer()) {
final Quidem.Config config = Quidem.configBuilder()

代码示例来源:origin: org.apache.calcite/calcite-core

Writer writer = Util.printWriter(outFile);
  Closer closer = new Closer()) {
final Quidem.Config config = Quidem.configBuilder()

相关文章