本文整理了Java中java.io.PrintWriter.append()
方法的一些代码示例,展示了PrintWriter.append()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintWriter.append()
方法的具体详情如下:
包路径:java.io.PrintWriter
类名称:PrintWriter
方法名:append
[英]Appends the character c to the target.
[中]将字符c追加到目标。
代码示例来源:origin: stackoverflow.com
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
) {
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
writer.append(CRLF).append(param).append(CRLF).flush();
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"textFile\"; filename=\"" + textFile.getName() + "\"").append(CRLF);
writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF); // Text file itself must be saved in this charset!
writer.append(CRLF).flush();
Files.copy(textFile.toPath(), output);
writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"binaryFile\"; filename=\"" + binaryFile.getName() + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(binaryFile.getName())).append(CRLF);
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
writer.append(CRLF).flush();
Files.copy(binaryFile.toPath(), output);
writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
writer.append("--" + boundary + "--").append(CRLF).flush();
代码示例来源:origin: spotbugs/spotbugs
public void test() throws IOException {
final File ff = File.createTempFile("sfq", ".lst");
PrintWriter mWriter = new PrintWriter(new BufferedWriter(new FileWriter(ff)));
mWriter.append('h');
closeWriters(new Writer[] { mWriter });
}
代码示例来源:origin: oblac/jodd
} else {
PrintWriter writer = response.getWriter();
writer.append(CharBuffer.wrap(pageWrapper.getBufferedChars()));
writer.flush();
代码示例来源:origin: jersey/jersey
private <T> String toString(final Map<MediaType, List<T>> set) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
for (final Map.Entry<MediaType, List<T>> e : set.entrySet()) {
pw.append(e.getKey().toString()).println(" ->");
for (final T t : e.getValue()) {
pw.append(" ").println(t.getClass().getName());
}
}
pw.flush();
return sw.toString();
}
代码示例来源:origin: org.testng/testng
writer.append("<html>\n<head>\n")
.append("<title>TestNG: ").append(testContext.getName()).append("</title>\n")
.append(HtmlHelper.getCssString())
.append(HEAD)
.append("</head>\n")
.append("<body>\n");
.append("<h2 align='center'>").append(testContext.getName()).append("</h2>")
.append("<table border='1' align=\"center\">\n")
.append("<tr>\n")
.append("<td>Tests passed/Failed/Skipped:</td><td>").append(Integer.toString(passed)).append("/").append(Integer.toString(failed)).append("/").append(Integer.toString(skipped)).append("</td>\n")
.append("</tr><tr>\n")
.append("<td>Started on:</td><td>").append(testContext.getStartDate().toString()).append("</td>\n")
.append("</tr>\n")
.append(hostLine)
.append("<tr><td>Total time:</td><td>").append(Long.toString(duration)).append(" seconds (").append(Long.toString(endDate.getTime() - startDate.getTime()))
.append(" ms)</td>\n")
.append("</tr><tr>\n")
.append("<td>Included groups:</td><td>").append(arrayToString(testContext.getIncludedGroups())).append("</td>\n")
.append("</tr><tr>\n")
.append("<td>Excluded groups:</td><td>").append(arrayToString(testContext.getExcludedGroups())).append("</td>\n")
.append("</tr>\n")
.append("</table><p/>\n");
writer.append("<small><i>(Hover the method name to see the test class name)</i></small><p/>\n");
if (!failedConfs.isEmpty()) {
generateTable(writer, "FAILED CONFIGURATIONS", failedConfs, "failed", CONFIGURATION_COMPARATOR);
代码示例来源:origin: javalite/activejdbc
private void sendField(FormField f) {
writer.append("--").append(boundary).append(LINE_FEED);
writer.append("Content-Disposition: form-data; name=\"").append(f.getName()).append("\"").append(LINE_FEED);
writer.append("Content-Type: text/plain" ).append(LINE_FEED);
writer.append(LINE_FEED);
writer.append(f.getValue()).append(LINE_FEED);
writer.flush();
}
代码示例来源:origin: jersey/jersey
private <T> String toString(final Map<MediaType, List<T>> set) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
for (final Map.Entry<MediaType, List<T>> e : set.entrySet()) {
pw.append(e.getKey().toString()).println(" ->");
for (final T t : e.getValue()) {
pw.append(" ").println(t.getClass().getName());
}
}
pw.flush();
return sw.toString();
}
代码示例来源:origin: cbeust/testng
.append("<html>\n<head>\n")
.append("<title>TestNG: ")
.append(testContext.getName())
.append("</title>\n")
.append(HtmlHelper.getCssString())
.append(HEAD)
.append("</head>\n")
.append("<body>\n");
.append("<h2 align='center'>")
.append(testContext.getName())
.append("</h2>")
.append("<table border='1' align=\"center\">\n")
.append("<tr>\n")
.append("<td>Tests passed/Failed/Skipped:</td><td>")
.append(Integer.toString(passed))
.append("/")
.append(Integer.toString(failed))
.append("/")
.append(Integer.toString(skipped))
.append("</td>\n")
.append("</tr><tr>\n")
.append("<td>Started on:</td><td>")
.append(testContext.getStartDate().toString())
.append("</td>\n")
.append("</tr>\n")
.append(hostLine)
.append("<tr><td>Total time:</td><td>")
代码示例来源:origin: javalite/activejdbc
private void sendFile(FileField f) {
try {
String fileName = f.getFile().getName();
writer.append("--").append(boundary).append(LINE_FEED);
writer.append("Content-Disposition: form-data; name=\"").append(f.getName()).append("\"; filename=\"").append(fileName).append("\"").append(LINE_FEED);
writer.append("Content-Type: ").append(URLConnection.guessContentTypeFromName(fileName)).append(LINE_FEED);
writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
writer.append(LINE_FEED);
writer.flush();
FileInputStream inputStream = new FileInputStream(f.getFile());
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.flush();
inputStream.close();
writer.append(LINE_FEED);
writer.flush();
} catch (Exception e) {
throw new HttpException(e);
}
}
代码示例来源:origin: alibaba/Sentinel
public static void selfLog(String log, Throwable e) {
long now = System.currentTimeMillis();
if (exceptionBucket.accept(now)) {
try {
String timestamp = EagleEyeCoreUtils.formatTime(now);
StringWriter sw = new StringWriter(4096);
PrintWriter pw = new PrintWriter(sw, false);
pw.append('[').append(timestamp).append("] ").append(log).append(EagleEyeCoreUtils.NEWLINE);
e.printStackTrace(pw);
pw.println();
pw.flush();
selfAppender.append(sw.toString());
} catch (Throwable t) {
}
}
}
代码示例来源:origin: neo4j/neo4j
try ( PrintWriter out = new PrintWriter( message ) )
out.append( "\t\tin " ).append( method.name ).append( method.desc ).println();
for ( int i = 0; i < method.instructions.size(); i++ )
insn.accept( mv );
Frame frame = frames[i];
out.append( "\t\t" );
out.append( insn == errorLocation ? ">>> " : " " );
out.format( "%05d [", i );
if ( frame == null )
out.append( " : " );
padding( out, stackLengths.listIterator(), '?' );
out.append( " : " );
emit( out, stackLengths, frame::getStack, frame.getStackSize() );
padding( out, stackLengths.listIterator( frame.getStackSize() ), ' ' );
代码示例来源:origin: camunda/camunda-bpm-platform
PrintWriter output = resp.getWriter();
output.append("<html>\r\n");
output.append("<head>\r\n");
printCSS(req.getContextPath(), output);
output.append("</head>\r\n");
output.append("<body>\r\n");
output.append(getPageTitle(req, resp));
output.append("<form method=\"POST\">\r\n");
output.append("<input type=\"submit\" name=\""+SUBMIT+"\" value=\""+CLEAR+"\">");
output.append("</form>\r\n");
output.append("<table>");
StringBuilder buf = new StringBuilder();
if(sm != null) {
printList(buf, sm);
} else {
output.append("Could not find status manager");
output.append(buf);
output.append("</table>");
output.append("</body>\r\n");
output.append("</html>\r\n");
output.flush();
output.close();
代码示例来源:origin: stackoverflow.com
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
) {
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
writer.append(CRLF).append(param).append(CRLF).flush();
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"textFile\"; filename=\"" + textFile.getName() + "\"").append(CRLF);
writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF); // Text file itself must be saved in this charset!
writer.append(CRLF).flush();
Files.copy(textFile.toPath(), output);
writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"binaryFile\"; filename=\"" + binaryFile.getName() + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(binaryFile.getName())).append(CRLF);
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
writer.append(CRLF).flush();
Files.copy(binaryFile.toPath(), output);
writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
writer.append("--" + boundary + "--").append(CRLF).flush();
代码示例来源:origin: cbeust/testng
private Class<?> compile(String src, String name) throws Exception {
// compile class and load it into by a custom classloader
File srcFile = new File(tmpDir, name + ".java");
try (PrintWriter pw = new PrintWriter(new FileWriter(srcFile))) {
pw.append(src);
}
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
assertEquals(0, javac.run(null, null, null, srcFile.getCanonicalPath()));
srcFile.delete();
File classFile = new File(tmpDir, name + ".class");
byte[] bytes;
try (DataInputStream dis = new DataInputStream(new FileInputStream(classFile))) {
bytes = new byte[dis.available()];
dis.readFully(bytes);
}
classFile.delete();
return defineClass(name, bytes, 0, bytes.length);
}
代码示例来源:origin: jamesagnew/hapi-fhir
theServletResponse.getWriter().append(outputBuffer);
theServletResponse.getWriter().flush();
theServletResponse.getWriter().append("<div class=\"sizeInfo\">");
theServletResponse.getWriter().append("Wrote ");
writeLength(theServletResponse, encoded.length());
theServletResponse.getWriter().append(" (");
writeLength(theServletResponse, outputBuffer.length());
theServletResponse.getWriter().append(" total including HTML)");
theServletResponse.getWriter().append(" in estimated ");
theServletResponse.getWriter().append(writeSw.toString());
theServletResponse.getWriter().append("</div>");
theServletResponse.getWriter().append("</body>");
theServletResponse.getWriter().append("</html>");
代码示例来源:origin: ACRA/acra
@Override
protected void write(OutputStream outputStream, @NonNull Pair<String, List<Uri>> content) throws IOException {
final PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, ACRAConstants.UTF8));
writer.append(SECTION_START)
.format(CONTENT_DISPOSITION, "ACRA_REPORT", "")
.format(CONTENT_TYPE, contentType)
.append(NEW_LINE)
.append(content.first);
for (Uri uri : content.second) {
try {
String name = UriUtils.getFileNameFromUri(context, uri);
writer.append(SECTION_START)
.format(CONTENT_DISPOSITION, "ACRA_ATTACHMENT", name)
.format(CONTENT_TYPE, UriUtils.getMimeType(context, uri))
.append(NEW_LINE)
.flush();
UriUtils.copyFromUri(context, outputStream, uri);
} catch (FileNotFoundException e) {
ACRA.log.w("Not sending attachment", e);
}
}
writer.append(MESSAGE_END).flush();
}
}
代码示例来源:origin: apache/flink
@Test
// We allow malformed YAML files
public void testInvalidYamlFile() throws IOException {
final File confFile = tempFolder.newFile(GlobalConfiguration.FLINK_CONF_FILENAME);
try (PrintWriter pw = new PrintWriter(confFile)) {
pw.append("invalid");
}
assertNotNull(GlobalConfiguration.loadConfiguration(tempFolder.getRoot().getAbsolutePath()));
}
代码示例来源:origin: org.apache.sling/org.apache.sling.junit.teleporter
MultipartAdapter file(String fieldName, String filename, String contentType, InputStream data) throws IOException {
pw.append(dashes).append(boundary).append(eol);
pw.append("Content-Disposition: form-data; name=\"").append(fieldName).append("\"");
pw.append("; filename=\"").append(filename).append("\"").append(eol);
pw.append("Content-Type: ").append(contentType).append(eol);
pw.append("Content-Transfer-Encoding: binary").append(eol);
pw.append(eol).flush();
copy(data, out);
pw.append(eol).flush();
return this;
}
代码示例来源:origin: apache/geode
ps = new PrintWriter(os);
ps.append(STACK_TRACE_FOR_MEMBER).append(entry.getKey()).append(" ***")
.append(System.lineSeparator());
ps.flush();
GZIPInputStream zipIn = new GZIPInputStream(new ByteArrayInputStream(entry.getValue()));
BufferedInputStream bin = new BufferedInputStream(zipIn);
os.write(buffer, 0, count);
ps.append('\n');
ps.flush();
filePath = outputFile.getCanonicalPath();
代码示例来源:origin: winder/Universal-G-Code-Sender
public GcodeStreamWriter(File f) throws FileNotFoundException {
file = f;
fileWriter = new PrintWriter(f);
// 50 bytes at the beginning of the file to store metadata
fileWriter.append(metadataReservedSize);
fileWriter.append("\n");
}
内容来源于网络,如有侵权,请联系作者删除!