当前位置: 首页>>代码示例>>Java>>正文


Java Util.printWriter方法代码示例

本文整理汇总了Java中org.apache.calcite.util.Util.printWriter方法的典型用法代码示例。如果您正苦于以下问题:Java Util.printWriter方法的具体用法?Java Util.printWriter怎么用?Java Util.printWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.util.Util的用法示例。


在下文中一共展示了Util.printWriter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scan

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
public Enumerable<Object[]> scan(DataContext root) {
  final Random random = seed >= 0 ? new Random(seed) : new Random();
  final Maze maze = new Maze(width, height);
  final PrintWriter pw = Util.printWriter(System.out);
  maze.layout(random, pw);
  if (Maze.DEBUG) {
    maze.print(pw, true);
  }
  return new AbstractEnumerable<Object[]>() {
    public Enumerator<Object[]> enumerator() {
      final Set<Integer> solutionSet;
      if (solution) {
        solutionSet = maze.solve(0, 0);
      } else {
        solutionSet = null;
      }
      return Linq4j.transform(maze.enumerator(solutionSet),
          new Function1<String, Object[]>() {
            public Object[] apply(String s) {
              return new Object[] {s};
            }
          });
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:MazeTable.java

示例2: testTableB6

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/** 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();
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:CalciteRemoteDriverTest.java

示例3: checkScriptFile

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/**
 * 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));
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:SqlLineTest.java

示例4: compile

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
public ArrayBindable compile(ClassDeclaration expr, String s) {
  final String className = "CalciteProgram" + classId.getAndIncrement();
  final File file = new File(SRC_DIR, className + ".java");
  try (Writer w = Util.printWriter(file)) {
    String source = "public class " + className + "\n"
        + "    implements " + ArrayBindable.class.getName()
        + ", " + Serializable.class.getName()
        + " {\n"
        + s + "\n"
        + "}\n";

    System.out.println("======================");
    System.out.println(source);
    System.out.println("======================");

    w.write(source);
    w.close();
    JaninoCompiler compiler = new JaninoCompiler();
    compiler.getArgs().setDestdir(CLASS_DIR.getAbsolutePath());
    compiler.getArgs().setSource(source, file.getAbsolutePath());
    compiler.getArgs().setFullClassName(className);
    compiler.compile();
    @SuppressWarnings("unchecked")
    final Class<ArrayBindable> clazz =
        (Class<ArrayBindable>) Class.forName(className);
    final Constructor<ArrayBindable> constructor = clazz.getConstructor();
    return constructor.newInstance();
  } catch (IOException | ClassNotFoundException | InstantiationException
      | IllegalAccessException | NoSuchMethodException
      | InvocationTargetException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:SparkHandlerImpl.java

示例5: flushDoc

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/**
 * 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);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:DiffRepository.java

示例6: checkCustomSchemaInFileInPwd

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
private void checkCustomSchemaInFileInPwd(String fileName)
    throws SQLException {
  final File file = new File(fileName);
  try (final PrintWriter pw = Util.printWriter(file)) {
    file.deleteOnExit();
    pw.println("{\n"
        + "  version: '1.0',\n"
        + "  defaultSchema: 'adhoc',\n"
        + "  schemas: [\n"
        + "    {\n"
        + "      name: 'empty'\n"
        + "    },\n"
        + "    {\n"
        + "      name: 'adhoc',\n"
        + "      type: 'custom',\n"
        + "      factory: '"
        + MySchemaFactory.class.getName()
        + "',\n"
        + "      operand: {'tableName': 'ELVIS'}\n"
        + "    }\n"
        + "  ]\n"
        + "}");
    pw.flush();
    final String url = "jdbc:calcite:model=" + file;
    try (Connection c = DriverManager.getConnection(url);
         Statement s = c.createStatement();
         ResultSet r = s.executeQuery("values 1")) {
      assertThat(r.next(), is(true));
    }
    //noinspection ResultOfMethodCallIgnored
    file.delete();
  } catch (IOException e) {
    // current directory is not writable; an environment issue, not
    // necessarily a bug
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:37,代码来源:JdbcTest.java

示例7: run

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
public int run(String[] args) {
  try (final PrintWriter w = Util.printWriter(System.out)) {
    if (!parseCommand(args)) {
      usage();
      return 2;
    }

    Class z = Class.forName(driver); // load driver
    Properties jdbcProps = new Properties();
    if (user != null) {
      jdbcProps.setProperty("user", user);
    }
    if (password != null) {
      jdbcProps.setProperty("password", password);
    }

    for (String file : files) {
      ConcurrentTestCommandScript script =
          new ConcurrentTestCommandScript();
      try {
        script.setQuiet(quiet);
        script.setVerbose(verbose);
        script.setDebug(debug);
        script.prepare(file, bindings);
        script.setDataSource(server, jdbcProps);
        script.execute();
      } finally {
        if (!quiet) {
          script.printResults(w);
        }
      }
    }
  } catch (Exception e) {
    System.err.println(e.getMessage());
    return 1;
  }
  return 0;
}
 
开发者ID:apache,项目名称:calcite,代码行数:39,代码来源:ConcurrentTestCommandScript.java

示例8: testCsvStream

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test(timeout = 10000) public void testCsvStream() throws Exception {
  final File file = File.createTempFile("stream", "csv");
  final String model = "{\n"
      + "  version: '1.0',\n"
      + "  defaultSchema: 'STREAM',\n"
      + "  schemas: [\n"
      + "    {\n"
      + "      name: 'SS',\n"
      + "      tables: [\n"
      + "        {\n"
      + "          name: 'DEPTS',\n"
      + "          type: 'custom',\n"
      + "          factory: '" + CsvStreamTableFactory.class.getName()
      + "',\n"
      + "          stream: {\n"
      + "            stream: true\n"
      + "          },\n"
      + "          operand: {\n"
      + "            file: " + escapeString(file.getAbsolutePath()) + ",\n"
      + "            flavor: \"scannable\"\n"
      + "          }\n"
      + "        }\n"
      + "      ]\n"
      + "    }\n"
      + "  ]\n"
      + "}\n";
  final String[] strings = {
      "DEPTNO:int,NAME:string",
      "10,\"Sales\"",
      "20,\"Marketing\"",
      "30,\"Engineering\""
  };

  try (final Connection connection =
           DriverManager.getConnection("jdbc:calcite:model=inline:" + model);
       final PrintWriter pw = Util.printWriter(file);
       final Worker<Void> worker = new Worker<>()) {
    final Thread thread = new Thread(worker);
    thread.start();

    // Add some rows so that the table can deduce its row type.
    final Iterator<String> lines = Arrays.asList(strings).iterator();
    pw.println(lines.next()); // header
    pw.flush();
    worker.queue.put(writeLine(pw, lines.next())); // first row
    worker.queue.put(writeLine(pw, lines.next())); // second row
    final CalciteConnection calciteConnection =
        connection.unwrap(CalciteConnection.class);
    final String sql = "select stream * from \"SS\".\"DEPTS\"";
    final PreparedStatement statement =
        calciteConnection.prepareStatement(sql);
    final ResultSet resultSet = statement.executeQuery();
    int count = 0;
    try {
      while (resultSet.next()) {
        ++count;
        if (lines.hasNext()) {
          worker.queue.put(sleep(10));
          worker.queue.put(writeLine(pw, lines.next()));
        } else {
          worker.queue.put(cancel(statement));
        }
      }
      fail("expected exception, got end of data");
    } catch (SQLException e) {
      assertThat(e.getMessage(), is("Statement canceled"));
    }
    assertThat(count, anyOf(is(strings.length - 2), is(strings.length - 1)));
    assertThat(worker.e, nullValue());
    assertThat(worker.v, nullValue());
  } finally {
    Util.discard(file.delete());
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:75,代码来源:CsvTest.java


注:本文中的org.apache.calcite.util.Util.printWriter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。