本文整理了Java中java.io.PrintStream.<init>()
方法的一些代码示例,展示了PrintStream.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintStream.<init>()
方法的具体详情如下:
包路径:java.io.PrintStream
类名称:PrintStream
方法名:<init>
[英]Constructs a new PrintStream with file as its target. The VM's default character set is used for character encoding.
[中]以文件为目标构造新的PrintStream。VM的默认字符集用于字符编码。
代码示例来源:origin: stackoverflow.com
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);
}
代码示例来源:origin: Alluxio/alluxio
private String stacktrace(Exception e) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os, true);
e.printStackTrace(ps);
ps.close();
return os.toString();
}
}
代码示例来源:origin: netty/netty
/**
* Gets the stack trace from a Throwable as a String.
*
* @param cause the {@link Throwable} to be examined
* @return the stack trace as generated by {@link Throwable#printStackTrace(java.io.PrintWriter)} method.
*/
public static String stackTraceToString(Throwable cause) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(out);
cause.printStackTrace(pout);
pout.flush();
try {
return new String(out.toByteArray());
} finally {
try {
out.close();
} catch (IOException ignore) {
// ignore as should never happen
}
}
}
代码示例来源:origin: alibaba/jstorm
public static void redirectOutput(String file) throws Exception {
System.out.println("Redirecting output to " + file);
FileOutputStream workerOut = new FileOutputStream(new File(file));
PrintStream ps = new PrintStream(new BufferedOutputStream(workerOut), true);
System.setOut(ps);
System.setErr(ps);
LOG.info("Successfully redirect System.out to " + file);
}
代码示例来源:origin: neo4j/neo4j
void assertClosed()
{
if ( !c.isClosed() )
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream( out );
for ( StackTraceElement traceElement : stackTrace )
{
printStream.println( "\tat " + traceElement );
}
printStream.println();
throw new IllegalStateException( format( "Closeable %s was not closed!\n%s", c, out.toString() ) );
}
}
}
代码示例来源:origin: stackoverflow.com
PrintStream fileStream = new PrintStream(new File("file.txt"));
fileStream.println("your data");
// ^^^^^^^ will add OS line separator after data
代码示例来源:origin: opentripplanner/OpenTripPlanner
public HTMLWriter(String filename, Multimap<String, String> curMap)
throws FileNotFoundException {
LOG.debug("Making file: {}", filename);
File newFile = new File(outPath, filename +".html");
FileOutputStream fileOutputStream = new FileOutputStream(newFile);
this.out = new PrintStream(fileOutputStream);
writerAnnotations = curMap;
annotationClassName = filename;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Transform path for Windows.
*/
private InputStream transformForWindows(InputStream src) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(src));
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (PrintStream p = new PrintStream(out)) {
String line;
while ((line = r.readLine()) != null) {
if (!line.startsWith("#") && Functions.isWindows())
line = line.replace("/", "\\\\");
p.println(line);
}
}
return new ByteArrayInputStream(out.toByteArray());
}
代码示例来源:origin: redisson/redisson
public static String print2String(byte minbinMsg[]) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
MBPrinter.printMessage(minbinMsg, new PrintStream(os));
try {
return os.toString("UTF8");
} catch (UnsupportedEncodingException e) {
return e.getMessage();
}
}
代码示例来源:origin: stackoverflow.com
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
public static void main(String [] args) {
System.err.println("error.");
System.out.println("out.");
System.setOut(System.err);
System.out.println("error?");
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println("out?");
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldLoadAndBootstrapJarUsingAgentBootstrapCode_specifiedInAgentManifestFile() throws Exception {
if (!OS_CHECKER.satisfy()) {
PrintStream err = System.err;
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
System.setErr(new PrintStream(os));
File agentJar = new File("agent.jar");
agentJar.delete();
new AgentBootstrapper() {
@Override
void jvmExit(int returnValue) {
}
}.go(false, new AgentBootstrapperArgs(new URL("http://" + "localhost" + ":" + server.getPort() + "/go"), null, AgentBootstrapperArgs.SslMode.NONE));
agentJar.delete();
assertThat(new String(os.toByteArray()), containsString("Hello World Fellas!"));
} finally {
System.setErr(err);
}
}
}
代码示例来源:origin: jenkinsci/jenkins
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);
代码示例来源:origin: gocd/gocd
private static void redirectStdOutAndErr() {
try {
PrintStream out = new PrintStream(new FileOutputStream(getOutFile(), true), true);
System.setErr(out);
System.setOut(out);
} catch (FileNotFoundException ignore) {
// cannot redirect out and err to file, so we don't
log("Unable to redirect stdout/stderr to file " + getOutFile() + ". Will continue without redirecting stdout/stderr.");
ignore.printStackTrace();
}
}
代码示例来源:origin: libgdx/libgdx
PrintStream out = new PrintStream(file, "UTF-8");
out.println("font.name=" + fontName);
out.println("font.size=" + fontSize);
out.println("font.bold=" + bold);
out.println("font.italic=" + italic);
out.println("font.gamma=" + gamma);
out.println();
out.close();
代码示例来源:origin: neo4j/neo4j
public static void dumpVmInfo( File directory ) throws IOException
{
File file = new File( directory, "main-vm-dump-" + System.currentTimeMillis() );
PrintStream out = null;
try
{
out = new PrintStream( file );
dumpVmInfo( out );
}
finally
{
if ( out != null )
{
out.close();
}
}
}
代码示例来源:origin: stackoverflow.com
final OutputStream os = new FileOutputStream("/tmp/out");
final PrintStream printStream = new PrintStream(os);
printStream.print("String");
printStream.close();
代码示例来源:origin: apache/incubator-pinot
@Override
public void copyFromLocalFile(File srcFile, URI dstUri)
throws Exception {
OutputStream stream = _adlStoreClient.createFile(dstUri.getPath(), IfExists.OVERWRITE);
PrintStream out = new PrintStream(stream);
byte[] inputStream = IOUtils.toByteArray(new FileInputStream(srcFile));
out.write(inputStream);
out.close();
}
代码示例来源:origin: stackoverflow.com
public static void main(String args[]) throws IOException {
PrintStream ps = null;
try {
ps = new PrintStream(new FileOutputStream("myfile.txt"));
ps.println("This data is written to a file:");
System.out.println("Write successfully");
} catch (IOException e) {
System.err.println("Error in writing to file");
throw e;
} finally {
if (ps != null) ps.close();
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testVerbosePrintNullLabelAndMap() {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final PrintStream outPrint = new PrintStream(out);
outPrint.println("null");
final String EXPECTED_OUT = out.toString();
out.reset();
MapUtils.verbosePrint(outPrint, null, null);
assertEquals(EXPECTED_OUT, out.toString());
}
代码示例来源:origin: apache/avro
public static void writeLinesTextFile(File dir) throws IOException {
FileUtil.fullyDelete(dir);
File fileLines = new File(dir, "lines.avro");
fileLines.getParentFile().mkdirs();
try(PrintStream out = new PrintStream(fileLines)) {
for (String line : LINES) {
out.println(line);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!