类java.io.PrintStream源码实例Demo

下面列出了怎么用java.io.PrintStream的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: appinventor-extensions   文件: Compiler.java
/**
 * Creates a new YAIL compiler.
 *
 * @param project  project to build
 * @param compTypes component types used in the project
 * @param compBlocks component types mapped to blocks used in project
 * @param out  stdout stream for compiler messages
 * @param err  stderr stream for compiler messages
 * @param userErrors stream to write user-visible error messages
 * @param childProcessMaxRam  maximum RAM for child processes, in MBs.
 */
@VisibleForTesting
Compiler(Project project, Set<String> compTypes, Map<String, Set<String>> compBlocks, PrintStream out, PrintStream err,
         PrintStream userErrors, boolean isForCompanion, boolean isForEmulator, boolean includeDangerousPermissions,
         int childProcessMaxRam, String dexCacheDir, BuildServer.ProgressReporter reporter) {
  this.project = project;
  this.compBlocks = compBlocks;

  prepareCompTypes(compTypes);
  readBuildInfo();

  this.out = out;
  this.err = err;
  this.userErrors = userErrors;
  this.isForCompanion = isForCompanion;
  this.isForEmulator = isForEmulator;
  this.includeDangerousPermissions = includeDangerousPermissions;
  this.childProcessRamMb = childProcessMaxRam;
  this.dexCacheDir = dexCacheDir;
  this.reporter = reporter;

}
 
源代码2 项目: hottub   文件: Method.java
public void dumpReplayData(PrintStream out) {
    NMethod nm = getNativeMethod();
    int code_size = 0;
    if (nm != null) {
      code_size = (int)nm.codeEnd().minus(nm.getVerifiedEntryPoint());
    }
    Klass holder = getMethodHolder();
    out.println("ciMethod " +
                holder.getName().asString() + " " +
                OopUtilities.escapeString(getName().asString()) + " " +
                getSignature().asString() + " " +
                getInvocationCount() + " " +
                getBackedgeCount() + " " +
                interpreterInvocationCount() + " " +
                interpreterThrowoutCount() + " " +
                code_size);
}
 
源代码3 项目: vespa   文件: ConsoleLogListenerTestCase.java
@Test
public void requireThatLogEntryWithLevelAboveThresholdIsNotOutput() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    LogListener listener = new ConsoleLogListener(new PrintStream(out), null, "5");
    for (int i = 0; i < 10; ++i) {
        listener.logged(new MyEntry(0, i, "message"));
    }
    // TODO: Should use ConsoleLogFormatter.ABSENCE_REPLACEMENT instead of literal '-'. See ticket 7128315.
    assertEquals("0.000000\t" + HOSTNAME + "\t" + PROCESS_ID + "\t-\t-\tunknown\tmessage\n" +
                 "0.000000\t" + HOSTNAME + "\t" + PROCESS_ID + "\t-\t-\terror\tmessage\n" +
                 "0.000000\t" + HOSTNAME + "\t" + PROCESS_ID + "\t-\t-\twarning\tmessage\n" +
                 "0.000000\t" + HOSTNAME + "\t" + PROCESS_ID + "\t-\t-\tinfo\tmessage\n" +
                 "0.000000\t" + HOSTNAME + "\t" + PROCESS_ID + "\t-\t-\tdebug\tmessage\n" +
                 "0.000000\t" + HOSTNAME + "\t" + PROCESS_ID + "\t-\t-\tunknown\tmessage\n",
                 out.toString());
}
 
源代码4 项目: nextreports-designer   文件: MergeProperties.java
/**
 * Writes the merged properties to a single file while preserving any
 * comments.
 *
 * @param fileContents list of file contents
 * @throws Exception if the destination file can't be created
 */
private void writeFile(List fileContents) throws Exception {
    Iterator iterate = fileContents.iterator();
    try {
        FileOutputStream out = new FileOutputStream(destFile);
        PrintStream p = new PrintStream(out);
        try {
            // write original file with updated values
            while (iterate.hasNext()) {
                FileContents fc = (FileContents) iterate.next();
                if (fc.comment != null && !fc.comment.equals("")) {
                    p.println();
                    p.print(fc.comment);
                }
                p.println(fc.value);
            }
        } catch (Exception e) {
            throw new Exception("Could not write file: " + destFile, e);
        } finally {
            out.close();
        }
    } catch (IOException IOe) {
        throw new Exception("Could not write file: " + destFile, IOe);
    }
}
 
源代码5 项目: Drop-seq   文件: SplitBamByCellTest.java
@Test
public void testReadBamList() throws IOException {
    // Create a bam_list with one relative path and one absolute, and confirm that reader
    // resolves them correctly.
    final File bamList = TestUtils.getTempReportFile("testReadBamList.", ".bam_list");
    final PrintStream out = new ErrorCheckingPrintStream(IOUtil.openFileForWriting(bamList));
    final String relative = "foo.bam";
    out.println(relative);
    final String absolute = "/an/absolute/path.bam";
    out.println(absolute);
    out.close();
    final List<File> expected = Arrays.asList(
      new File(bamList.getCanonicalFile().getParent(), relative),
      new File(absolute)
    );
    Assert.assertEquals(expected, FileListParsingUtils.readFileList(bamList));
    // Confirm that when reading a symlink to a bam_list, relative paths are resolved relative to the directory
    // of the actually bam_list file, not the directory containing the symlink.
    final File otherDir = Files.createTempDirectory("testReadBamList").toFile();
    otherDir.deleteOnExit();
    final File symlink = new File(otherDir, "testReadBamList.bam_list");
    symlink.deleteOnExit();
    Files.createSymbolicLink(symlink.toPath(), bamList.toPath());
    Assert.assertEquals(expected, FileListParsingUtils.readFileList(symlink));
}
 
源代码6 项目: hadoop   文件: TestCount.java
@Test
public void processOptionsHeaderNoQuotas() {
  LinkedList<String> options = new LinkedList<String>();
  options.add("-v");
  options.add("dummy");

  PrintStream out = mock(PrintStream.class);

  Count count = new Count();
  count.out = out;

  count.processOptions(options);

  String noQuotasHeader =
  // <----12----> <----12----> <-------18------->
    "   DIR_COUNT   FILE_COUNT       CONTENT_SIZE PATHNAME";
  verify(out).println(noQuotasHeader);
  verifyNoMoreInteractions(out);
}
 
源代码7 项目: MtgDesktopCompanion   文件: PostgresqlDAO.java
@Override
public void backup(File f) throws IOException {

	if (getString(URL_PGDUMP).length() <= 0) {
		throw new NullPointerException("Please fill URL_PGDUMP var");
	}

	String dumpCommand = getString(URL_PGDUMP) + "/pg_dump" + " -d" + getString(DB_NAME)
			+ " -h" + getString(SERVERNAME) + " -U" + getString(LOGIN) + " -p"
			+ getString(SERVERPORT);

	Runtime rt = Runtime.getRuntime();
	logger.info("begin Backup :" + dumpCommand);

	Process child = rt.exec(dumpCommand);
	try (PrintStream ps = new PrintStream(f)) {
		InputStream in = child.getInputStream();
		int ch;
		while ((ch = in.read()) != -1) {
			ps.write(ch);
		}
		logger.info("Backup " + getString(DB_NAME) + " done");
	}

}
 
@Override
protected int mainExec(OutputStream out, PrintStream err) throws IOException {
  final CFlags flags = mFlags;
  final PortableRandom random;
  if (flags.isSet(SEED)) {
    random = new PortableRandom((Integer) flags.getValue(SEED));
  } else {
    random = new PortableRandom();
  }
  final long seed = random.getSeed();
  final int distance = (Integer) flags.getValue(DISTANCE);
  final File input = (File) flags.getValue(REFERENCE_SDF);
  final Mutator mutator = new Mutator((String) flags.getValue(SNP_SPECIFICATION));
  final File outputVcf = VcfUtils.getZippedVcfFileName(true, (File) flags.getValue(OUTPUT_VCF));
  final double af = (Double) flags.getValue(FREQUENCY);
  try (SequencesReader dsr = SequencesReaderFactory.createMemorySequencesReader(input, true, LongRange.NONE)) {
    final FixedStepPopulationVariantGenerator fs = new FixedStepPopulationVariantGenerator(dsr, distance, mutator, random, af);
    PopulationVariantGenerator.writeAsVcf(outputVcf, fs.generatePopulation(), dsr, seed);
    return 0;
  }
}
 
源代码9 项目: hadoop-gpu   文件: GenericOptionsParser.java
/**
 * Print the usage message for generic command-line options supported.
 * 
 * @param out stream to print the usage message to.
 */
public static void printGenericCommandUsage(PrintStream out) {
  
  out.println("Generic options supported are");
  out.println("-conf <configuration file>     specify an application configuration file");
  out.println("-D <property=value>            use value for given property");
  out.println("-fs <local|namenode:port>      specify a namenode");
  out.println("-jt <local|jobtracker:port>    specify a job tracker");
  out.println("-files <comma separated list of files>    " + 
    "specify comma separated files to be copied to the map reduce cluster");
  out.println("-libjars <comma separated list of jars>    " +
    "specify comma separated jar files to include in the classpath.");
  out.println("-archives <comma separated list of archives>    " +
              "specify comma separated archives to be unarchived" +
              " on the compute machines.\n");
  out.println("The general command line syntax is");
  out.println("bin/hadoop command [genericOptions] [commandOptions]\n");
}
 
源代码10 项目: ironjacamar   文件: Main.java
/**
 * hasValidatingMcfInterface
 * 
 * @param out output stream
 * @param classname classname
 * @param cl classloader
 */
private static void hasValidatingMcfInterface(PrintStream out, PrintStream error, String classname,
      URLClassLoader cl)
{
   try
   {
      out.print("  Validating: ");
      Class<?> clazz = Class.forName(classname, true, cl);

      if (hasInterface(clazz, "javax.resource.spi.ValidatingManagedConnectionFactory"))
      {
         out.println("Yes");
      }
      else
      {
         out.println("No");
      }
   }
   catch (Throwable t)
   {
      // Nothing we can do
      t.printStackTrace(error);
      out.println("Unknown");
   }
}
 
public void saveToChangeLog(File changeLogFile, ExtractChangeLogParser.ExtractChangeLogEntry changeLog) throws IOException {
    FileOutputStream outputStream = new FileOutputStream(changeLogFile);

    PrintStream stream = new PrintStream(outputStream, false, "UTF-8");

    stream.println("<?xml version='1.0' encoding='UTF-8'?>");
    stream.println("<extractChanges>");
    stream.println("<entry>");
    stream.println("<zipFile>" + escapeForXml(changeLog.getZipFile()) + "</zipFile>");

    for (String fileName : changeLog.getAffectedPaths()) {
        stream.println("<file>");
        stream.println("<fileName>" + escapeForXml(fileName) + "</fileName>");
        stream.println("</file>");
    }

    stream.println("</entry>");
    stream.println("</extractChanges>");

    stream.close();
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: Compilation.java
public void printShort(PrintStream stream) {
    if (getMethod() == null) {
        stream.println(getSpecial());
    } else {
        int bc = isOsr() ? getOsr_bci() : -1;
        stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc));
    }
}
 
源代码13 项目: TencentKona-8   文件: ArrayAccessExpression.java
/**
 * Print
 */
public void print(PrintStream out) {
    out.print("(" + opNames[op] + " ");
    right.print(out);
    out.print(" ");
    if (index != null) {
        index.print(out);
    } else {
    out.print("<empty>");
    }
    out.print(")");
}
 
源代码14 项目: MCPELauncher   文件: LoggingPrintStream.java
@Override
public synchronized PrintStream append(
        CharSequence csq, int start, int end) {
    builder.append(csq, start, end);
    flush(false);
    return this;
}
 
源代码15 项目: appinventor-extensions   文件: BuildServer.java
private void buildAndCreateZip(String userName, File inputZipFile, ProgressReporter reporter)
  throws IOException, JSONException {
  Result buildResult = build(userName, inputZipFile, reporter);
  boolean buildSucceeded = buildResult.succeeded();
  outputZip = File.createTempFile(inputZipFile.getName(), ".zip");
  outputZip.deleteOnExit();  // In case build server is killed before cleanUp executes.
  ZipOutputStream zipOutputStream =
    new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputZip)));
  if (buildSucceeded) {
    if (outputKeystore != null) {
      zipOutputStream.putNextEntry(new ZipEntry(outputKeystore.getName()));
      Files.copy(outputKeystore, zipOutputStream);
    }
    zipOutputStream.putNextEntry(new ZipEntry(outputApk.getName()));
    Files.copy(outputApk, zipOutputStream);
    successfulBuildRequests.getAndIncrement();
  } else {
    LOG.severe("Build " + buildCount.get() + " Failed: " + buildResult.getResult() + " " + buildResult.getError());
    failedBuildRequests.getAndIncrement();
  }
  zipOutputStream.putNextEntry(new ZipEntry("build.out"));
  String buildOutputJson = genBuildOutput(buildResult);
  PrintStream zipPrintStream = new PrintStream(zipOutputStream);
  zipPrintStream.print(buildOutputJson);
  zipPrintStream.flush();
  zipOutputStream.flush();
  zipOutputStream.close();
}
 
源代码16 项目: byte-buddy   文件: AgentBuilderListenerTest.java
@Test
public void testStreamWritingOnDiscovery() throws Exception {
    PrintStream printStream = mock(PrintStream.class);
    AgentBuilder.Listener listener = new AgentBuilder.Listener.StreamWriting(printStream);
    listener.onDiscovery(FOO, classLoader, module, LOADED);
    verify(printStream).printf("[Byte Buddy] DISCOVERY %s [%s, %s, loaded=%b]%n", FOO, classLoader, module, LOADED);
    verifyNoMoreInteractions(printStream);
}
 
源代码17 项目: scheduling   文件: ErrorCases.java
@Before
public void captureInputOutput() throws Exception {
    System.setProperty(WindowsTerminal.DIRECT_CONSOLE, "false"); // to be able to type input on Windows
    inputLines = "";
    capturedOutput = new ByteArrayOutputStream();
    PrintStream captureOutput = new PrintStream(capturedOutput);
    System.setOut(captureOutput);
}
 
源代码18 项目: openjdk-jdk8u   文件: RunTest.java
void testRun() throws BadArgs, IOException {
    System.err.println("test run(String[])");
    DocLint dl = new DocLint();
    String[] args = { "-help" };
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream prev = System.out;
    try {
        System.setOut(ps);
        dl.run(args);
    } finally {
        System.setOut(prev);
    }
    ps.close();
    String stdout = baos.toString();

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    dl.run(pw, args);
    pw.close();
    String direct = sw.toString();

    if (!stdout.equals(direct)) {
        error("unexpected output");
        System.err.println("EXPECT>>" + direct + "<<");
        System.err.println("FOUND>>" + stdout + "<<");
    }
}
 
源代码19 项目: rtg-tools   文件: RocSlopeTest.java
public void test1() throws IOException {
  final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try (PrintStream ps = new PrintStream(baos)) {
    RocSlope.writeSlope(new ByteArrayInputStream(ROC1.getBytes()), ps);
  }
  mNano.check("roc-slope-1.txt", TestUtils.sanitizeTsvHeader(baos.toString()));
}
 
源代码20 项目: jdk8u-jdk   文件: ThrowStatement.java
/**
 * Print
 */
public void print(PrintStream out, int indent) {
    super.print(out, indent);
    out.print("throw ");
    expr.print(out);
    out.print(":");
}
 
源代码21 项目: jdk8u60   文件: OctaneTest.java
public Double genericV8Test(final String benchmark, final String testPath) throws Throwable {

        System.out.println("genericV8Test");
        if (!checkV8Presence()) {
            return null;
        }
        final String v8shell = System.getProperty("v8.shell.full.path");
        final PrintStream systemOut = System.out;

        try {

            final Process process = Runtime.getRuntime().exec(v8shell + " " + testPath);
            process.waitFor();
            final InputStream processOut = process.getInputStream();
            final BufferedInputStream bis = new BufferedInputStream(processOut);

            final byte[] output = new byte[bis.available()];
            bis.read(output, 0, bis.available());
            final List<String> result = outputToStrings(output);
            return filterBenchmark(result, benchmark);

        } catch (final Throwable e) {
            System.setOut(systemOut);
            e.printStackTrace();
            throw e;
        }
    }
 
源代码22 项目: openjdk-8-source   文件: CategoryClassFile.java
@Override public void writeBeginning(final PrintStream out) {
    String targetCls = category.category.superClass.getFullPath();
    out.format("\tpublic %1$s(final %2$s obj, final %3$s runtime) {\n" +
            "\t\tsuper(obj, runtime);\n" +
            "\t}\n",
        className, targetCls, JObjCRuntime.class.getCanonicalName());
    super.writeBeginning(out);
}
 
源代码23 项目: openjdk-8   文件: CategoryClassFile.java
@Override public void writeBeginning(final PrintStream out) {
    String targetCls = category.category.superClass.getFullPath();
    out.format("\tpublic %1$s(final %2$s obj, final %3$s runtime) {\n" +
            "\t\tsuper(obj, runtime);\n" +
            "\t}\n",
        className, targetCls, JObjCRuntime.class.getCanonicalName());
    super.writeBeginning(out);
}
 
源代码24 项目: vxquery   文件: XMLSerializer.java
private void printInteger(PrintStream ps, TaggedValuePointable tvp) {
    LongPointable lp = pp.takeOne(LongPointable.class);
    try {
        tvp.getValue(lp);
        ps.print(lp.longValue());
    } finally {
        pp.giveBack(lp);
    }
}
 
@Override
protected PrintStream initialValue() {
    return AccessController.doPrivileged(new PrivilegedAction<PrintStream>() {
        public PrintStream run() {
            return new PrintStream(new LineBufferingOutputStream(handler));
        }
    });
}
 
源代码26 项目: openjdk-8   文件: ServerTool.java
public void printCommandHelp(PrintStream out, boolean helpType)
{
    if (helpType == longHelp) {
        out.println(CorbaResourceUtil.getText("servertool.listappnames"));
    } else {
        out.println(CorbaResourceUtil.getText("servertool.listappnames1"));
    }
}
 
源代码27 项目: buck   文件: VerifyCachesCommand.java
private boolean verifyRuleKeyCache(
    CellProvider cellProvider,
    PrintStream stdOut,
    RuleKeyConfiguration ruleKeyConfiguration,
    FileHashLoader fileHashLoader,
    RuleKeyCacheRecycler<RuleKey> recycler) {
  ImmutableList<Map.Entry<BuildRule, RuleKey>> contents = recycler.getCachedBuildRules();
  RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(ruleKeyConfiguration);
  ActionGraphBuilder graphBuilder =
      new MultiThreadedActionGraphBuilder(
          MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()),
          TargetGraph.EMPTY,
          ConfigurationRuleRegistryFactory.createRegistry(TargetGraph.EMPTY),
          new DefaultTargetNodeToBuildRuleTransformer(),
          cellProvider);
  contents.forEach(e -> graphBuilder.addToIndex(e.getKey()));
  DefaultRuleKeyFactory defaultRuleKeyFactory =
      new DefaultRuleKeyFactory(fieldLoader, fileHashLoader, graphBuilder);
  stdOut.println(String.format("Examining %d build rule keys.", contents.size()));
  ImmutableList<BuildRule> mismatches =
      RichStream.from(contents)
          .filter(entry -> !defaultRuleKeyFactory.build(entry.getKey()).equals(entry.getValue()))
          .map(Map.Entry::getKey)
          .toImmutableList();
  if (mismatches.isEmpty()) {
    stdOut.println("No rule key cache errors found.");
  } else {
    stdOut.println("Found rule key cache errors:");
    for (BuildRule rule : mismatches) {
      stdOut.println(String.format("  %s", rule));
    }
  }
  return true;
}
 
@Override
protected void handleLabels(PrintStream out, List<String> labels) {
    out.println("\t\t<tr>");
    for (String label : labels) {
        out.printf("\t\t\t<td>%s</td>%n", label);
    }
    out.println("\t\t</tr>");
}
 
源代码29 项目: gemfirexd-oss   文件: JDBCDisplayUtil.java
static public void ShowException(PrintStream out, Throwable e) {
	if (e == null) return;

	if (e instanceof SQLException)
		ShowSQLException(out, (SQLException)e);
	else
		e.printStackTrace(out);
}
 
源代码30 项目: spork   文件: TestMapReduce.java
@Test
public void testQualifiedFunctionsWithNulls() throws Throwable {

    //create file
    File tmpFile = File.createTempFile("test", ".txt");
    PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
    for(int i = 0; i < 1; i++) {
    if ( i % 10 == 0 ){
           ps.println("");
    } else {
           ps.println(i);
    }
    }
    ps.close();

    // execute query
    String query = "foreach (group (load '"
            + Util.generateURI(tmpFile.toString(), pig.getPigContext())
            + "' using " + MyStorage.class.getName() + "()) by "
            + MyGroup.class.getName() + "('all')) generate flatten("
            + MyApply.class.getName() + "($1)) ;";
    System.out.println(query);
    pig.registerQuery("asdf_id = " + query);

    //Verfiy query
    Iterator<Tuple> it = pig.openIterator("asdf_id");
    Tuple t;
    int count = 0;
    while(it.hasNext()) {
        t = it.next();
        assertEquals(t.get(0).toString(), "Got");
        Integer.parseInt(t.get(1).toString());
        count++;
    }

    assertEquals( MyStorage.COUNT, count );
    tmpFile.delete();
}
 
 类所在包
 同包方法