Refine search
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();
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 }); }
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(); }
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);
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(); }
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(); }
.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>")
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); } }
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) { } } }
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() ), ' ' );
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();
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();
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); }
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>");
@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(); } }
@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())); }
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; }
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();
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"); }