Refine search
for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { System.out.println(header.getKey() + "=" + header.getValue()); }
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); @Before public void setUpStreams() { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); } @After public void cleanUpStreams() { System.setOut(null); System.setErr(null); }
static void usage() { System.err.printf("Usage: java %s <query-file> <k> <out-file>\n", WordCluster.class.getName()); System.err.println("\t<query-file> contains word projections in the text format\n"); System.err.println("\t<k> number of clustering\n"); System.err.println("\t<out-file> output file\n"); System.exit(0); }
try (Scanner scanner = new Scanner(response)) { String responseBody = scanner.useDelimiter("\\A").next(); System.out.println(responseBody); }
public static void main(String[] args) throws InterruptedException { Volatile aVolatile = new Volatile(); new Thread(aVolatile,"thread A").start(); System.out.println("main 线程正在运行") ; Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String value = sc.next(); if(value.equals("1")){ new Thread(new Runnable() { @Override public void run() { aVolatile.stopThread(); } }).start(); break ; } } System.out.println("主线程退出了!"); }
protected Process sudoWithPass(ArgumentListBuilder args) throws IOException { args.prepend(sudoExe(),"-S"); listener.getLogger().println("$ "+Util.join(args.toList()," ")); ProcessBuilder pb = new ProcessBuilder(args.toCommandArray()); Process p = pb.start(); // TODO: use -p to detect prompt // TODO: detect if the password didn't work PrintStream ps = new PrintStream(p.getOutputStream()); ps.println(rootPassword); ps.println(rootPassword); ps.println(rootPassword); return p; } }.start(listener,rootPassword);
@Override protected void printThisBefore() { System.out.print(c); } }
public static void INFO_LOG(String format, Object ... args) { System.err.printf(format, args); } }
private String record(Runnable runnable) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); PrintStream written = new PrintStream(stream); setStream(written); runnable.run(); written.flush(); String result = stream.toString(); quiet(() -> { written.close(); return null; }); return result; }
private void doFizzBuzz(final int n, final String s) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final BufferedOutputStream bos = new BufferedOutputStream(baos); System.setOut(new PrintStream(bos)); this.fb.fizzBuzz(n); System.out.flush(); String platformDependentExpectedResult = s.replaceAll("\\n", System.getProperty("line.separator")); assertEquals(platformDependentExpectedResult, baos.toString()); }
/** * Get long description as a string. */ @Restricted(NoExternalUse.class) public final String getLongDescription() { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(out); printUsageSummary(ps); ps.close(); return out.toString(); }
public static void checkWrite(final OutputStream output) throws Exception { try { new java.io.PrintStream(output).write(0); } catch (final Throwable t) { throw new AssertionFailedError( "The copy() method closed the stream " + "when it shouldn't have. " + t.getMessage()); } }
String content = new Scanner(new File("filename")).useDelimiter("\\Z").next(); System.out.println(content);
@Override protected void printThisAfter() { System.out.print("."); } }