本文整理汇总了Java中java.io.PrintStream类的典型用法代码示例。如果您正苦于以下问题:Java PrintStream类的具体用法?Java PrintStream怎么用?Java PrintStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrintStream类属于java.io包,在下文中一共展示了PrintStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PluginPrinter
import java.io.PrintStream; //导入依赖的package包/类
/**
* This is called from the Java Plug-in to print an Applet's
* contents as EPS to a postscript stream provided by the browser.
* @param applet the applet component to print.
* @param stream the print stream provided by the plug-in
* @param x the x location of the applet panel in the browser window
* @param y the y location of the applet panel in the browser window
* @param w the width of the applet panel in the browser window
* @param h the width of the applet panel in the browser window
*/
public PluginPrinter(Component applet,
PrintStream stream,
int x, int y, int w, int h) {
this.applet = applet;
this.epsTitle = "Java Plugin Applet";
this.stream = stream;
bx = x;
by = y;
bw = w;
bh = h;
width = applet.size().width;
height = applet.size().height;
epsPrinter = new EPSPrinter(this, epsTitle, stream,
0, 0, width, height);
}
示例2: testShortFile
import java.io.PrintStream; //导入依赖的package包/类
@Test
public void testShortFile() throws Exception {
// short file: 2 characters worth (shorter than the UTF-8 BOM), without BOMs
File testFolder = tempDir.newFolder("testShortFilesFolder");
File testFile2 = new File(testFolder, "twobyte.csv");
PrintStream p2 = new PrintStream(testFile2);
p2.print("y\n");
p2.close();
testBuilder()
.sqlQuery(String.format("select * from table(dfs.`%s` (type => 'text', " +
"fieldDelimiter => ',', lineDelimiter => '\n', extractHeader => true)) ",
testFile2.getAbsolutePath()))
.unOrdered()
.baselineColumns("y")
.expectsEmptyResultSet()
.go();
}
示例3: testImportMain
import java.io.PrintStream; //导入依赖的package包/类
/**
* test main method. Import should print help and call System.exit
*/
@Test
public void testImportMain() throws Exception {
PrintStream oldPrintStream = System.err;
SecurityManager SECURITY_MANAGER = System.getSecurityManager();
LauncherSecurityManager newSecurityManager= new LauncherSecurityManager();
System.setSecurityManager(newSecurityManager);
ByteArrayOutputStream data = new ByteArrayOutputStream();
String[] args = {};
System.setErr(new PrintStream(data));
try {
System.setErr(new PrintStream(data));
Import.main(args);
fail("should be SecurityException");
} catch (SecurityException e) {
assertEquals(-1, newSecurityManager.getExitCode());
assertTrue(data.toString().contains("Wrong number of arguments:"));
assertTrue(data.toString().contains("-Dimport.bulk.output=/path/for/output"));
assertTrue(data.toString().contains("-Dimport.filter.class=<name of filter class>"));
assertTrue(data.toString().contains("-Dimport.bulk.output=/path/for/output"));
assertTrue(data.toString().contains("-Dmapreduce.reduce.speculative=false"));
} finally {
System.setErr(oldPrintStream);
System.setSecurityManager(SECURITY_MANAGER);
}
}
示例4: printSentence
import java.io.PrintStream; //导入依赖的package包/类
protected void printSentence(PrintStream out, StringBuilder sb, Layer sentence, boolean withPos) {
boolean notFirst = false;
for (Annotation word : sentence) {
String form = word.getLastFeature(formFeatureName);
if (form.isEmpty())
continue;
sb.setLength(0);
if (notFirst)
sb.append(' ');
else
notFirst = true;
Strings.escapeWhitespaces(sb, form, '|', '.');
if (withPos) {
sb.append('|');
sb.append(word.getLastFeature(posFeatureName));
}
out.print(sb);
}
out.println();
}
示例5: exec
import java.io.PrintStream; //导入依赖的package包/类
@Override
public ExitCode exec(PrintStream out) throws CannotCreateSessionException,
PermissionDeniedException, ServerError {
client c = newClient();
ServiceFactoryPrx serviceFactory = c.createSession();
serviceFactory.setSecurityPassword(password);
Session initialSession = serviceFactory.getSessionService()
.getSession(c.getSessionId());
Session newSession = serviceFactory.getSessionService()
.createUserSession(0,
timeToIdle(initialSession),
group(initialSession));
c.killSession(); // close initial session.
out.print(newSession.getUuid().getValue());
return ExitCode.Ok;
}
示例6: run
import java.io.PrintStream; //导入依赖的package包/类
public void run() throws IOException {
final TargetMonitor monitor = useSocketMonitor
? TargetMonitor.await(monitorPort)
: TargetMonitor.forPrintStream(System.out);
PrintStream monitorPrintStream = new PrintStreamDecorator(System.out) {
@Override public void print(String str) {
monitor.output(str != null ? str : "null");
}
};
System.setOut(monitorPrintStream);
System.setErr(monitorPrintStream);
try {
run(monitor);
} catch (Throwable internalError) {
internalError.printStackTrace(monitorPrintStream);
} finally {
monitor.close();
}
}
示例7: testFAttrs
import java.io.PrintStream; //导入依赖的package包/类
public void testFAttrs() throws Exception {
FileObject resolver = FileUtil.createData(FileUtil.getConfigRoot(), "Services/MIMEResolver/r.xml");
resolver.setAttribute("position", 2);
OutputStream os = resolver.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("<!DOCTYPE MIME-resolver PUBLIC '-//NetBeans//DTD MIME Resolver 1.0//EN' 'http://www.netbeans.org/dtds/mime-resolver-1_0.dtd'>");
ps.println("<MIME-resolver>");
ps.println(" <file>");
ps.println(" <fattr name='foo' text='yes'/>");
ps.println(" <resolver mime='text/x-boo'/>");
ps.println(" </file>");
ps.println("</MIME-resolver>");
os.close();
FileObject foo = FileUtil.createMemoryFileSystem().getRoot().createData("somefile");
assertEquals("content/unknown", foo.getMIMEType());
foo.setAttribute("foo", Boolean.FALSE);
assertEquals("content/unknown", foo.getMIMEType());
foo.setAttribute("foo", "no");
assertEquals("content/unknown", foo.getMIMEType());
foo.setAttribute("foo", "yes");
assertEquals("text/x-boo", foo.getMIMEType());
}
示例8: stop
import java.io.PrintStream; //导入依赖的package包/类
protected void stop() {
PrintStream printStream = new PrintStream(out);
printStream.println("stop");
printStream.flush();
printStream.close();
restartItem.setEnabled(false);
stopItem.setEnabled(false);
startItem.setEnabled(true);
}
示例9: CommandProcessor
import java.io.PrintStream; //导入依赖的package包/类
public CommandProcessor(DebuggerInterface debugger, BufferedReader in, PrintStream out, PrintStream err) {
this.debugger = debugger;
this.agent = debugger.getAgent();
this.in = in;
this.out = out;
this.err = err;
for (int i = 0; i < commandList.length; i++) {
Command c = commandList[i];
if (commands.get(c.name) != null) {
throw new InternalError(c.name + " has multiple definitions");
}
commands.put(c.name, c);
}
if (debugger.isAttached()) {
postAttach();
}
}
示例10: printTo
import java.io.PrintStream; //导入依赖的package包/类
private void printTo(PrintStream ps, int num_args) {
// print items from the top of the stack
// # of items
if (num_args == 0) {
// display $0
ps.println(jrt.jrtGetInputField(0));
} else {
// cache $OFS to separate fields below
// (no need to execute getOFS for each field)
String ofs_string = getOFS().toString();
for (int i = 0; i < num_args; i++) {
String s = JRT.toAwkStringForOutput(pop(), getOFMT().toString());
ps.print(s);
// if more elements, display $FS
if (i < num_args - 1) {
// use $OFS to separate fields
ps.print(ofs_string);
}
}
ps.println();
}
// for now, since we are not using Process.waitFor()
if (IS_WINDOWS) {
ps.flush();
}
}
示例11: BytesOf
import java.io.PrintStream; //导入依赖的package包/类
/**
* Ctor.
* @param error The exception to serialize
* @param charset Charset
*/
public BytesOf(final Throwable error, final CharSequence charset) {
this(
() -> {
try (
final ByteArrayOutputStream baos =
new ByteArrayOutputStream()
) {
error.printStackTrace(
new PrintStream(baos, true, charset.toString())
);
return baos.toByteArray();
}
}
);
}
示例12: writeInput
import java.io.PrintStream; //导入依赖的package包/类
private void writeInput(Corpus corpus) throws IOException {
EvaluationContext evalCtx = new EvaluationContext(logger);
WapitiResolvedObjects resObj = getResolvedObjects();
try (PrintStream ps = new PrintStream(inputFile)) {
for (Section sec : Iterators.loop(sectionIterator(evalCtx, corpus))) {
for (Layer sentence : sec.getSentences(tokenLayerName, sentenceLayerName)) {
for (Annotation a : sentence) {
boolean notFirst = false;
for (Evaluator feat : resObj.features) {
if (notFirst) {
ps.print('\t');
}
else {
notFirst = true;
}
String value = feat.evaluateString(evalCtx, a);
ps.print(value);
}
ps.println();
}
ps.println();
}
}
}
}
示例13: processMultipleStorageTypesContent
import java.io.PrintStream; //导入依赖的package包/类
private void processMultipleStorageTypesContent(boolean quotaUsageOnly)
throws Exception {
Path path = new Path("mockfs:/test");
when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat);
PathData pathData = new PathData(path.toString(), conf);
PrintStream out = mock(PrintStream.class);
Count count = new Count();
count.out = out;
LinkedList<String> options = new LinkedList<String>();
options.add(quotaUsageOnly ? "-u" : "-q");
options.add("-t");
options.add("SSD,DISK");
options.add("dummy");
count.processOptions(options);
count.processPath(pathData);
String withStorageType = BYTES + StorageType.SSD.toString()
+ " " + StorageType.DISK.toString() + " " + pathData.toString();
verify(out).println(withStorageType);
verifyNoMoreInteractions(out);
}
示例14: writeSentence
import java.io.PrintStream; //导入依赖的package包/类
private void writeSentence(PrintStream ps, Layer sent) {
boolean notFirst = false;
for (Annotation word : sent) {
if (notFirst) {
ps.print(' ');
}
else {
notFirst = true;
}
writeToken(ps, word.getLastFeature(enjuParser.getWordFormFeatureName()));
if (word.hasFeature(enjuParser.getPosFeatureName())) {
ps.print('/');
writeToken(ps, word.getLastFeature(enjuParser.getPosFeatureName()));
}
}
ps.println();
}
示例15: write
import java.io.PrintStream; //导入依赖的package包/类
@Override
public void write(Collection<Rule> rules) {
try (PrintStream workspaceStream = new PrintStream(workspaceFile);
PrintStream buildStream = new PrintStream(buildFile)) {
writeWorkspace(workspaceStream, rules);
writeBuild(buildStream, rules);
} catch (IOException e) {
logger.severe(
"Could not write WORKSPACE and BUILD files to " + buildFile.getParent() + ": "
+ e.getMessage());
return;
}
System.err.println("Wrote:\n" + workspaceFile + "\n" + buildFile);
}