List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:net.cristcost.study.services.ServiceTestUtil.java
private static void dumpSecurityInformation(PrintWriter writer, AuthenticationManager authenticationManager) { writer.println("### General Security Information ###"); writer.println("Security Strategy is " + SecurityContextHolder.getContextHolderStrategy().toString()); writer.println("Current Thread is " + Thread.currentThread().getName() + " (" + Thread.currentThread().getId() + ")"); writer.println();//from w w w .j av a 2s . c om if (authenticationManager != null) { writer.println("I've been injected with the AuthenticationManager"); } else { writer.println("I've not been injected with the AuthenticationManager"); } writer.println(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { writer.println("There is an Authentication of type: " + authentication.getClass().getName()); writer.println("Principal is of type: " + authentication.getPrincipal().getClass().getName() + " and is value is: " + authentication.getPrincipal().toString()); for (GrantedAuthority ga : authentication.getAuthorities()) { writer.println(" - you have " + ga.getAuthority() + " authority"); } } else { writer.println("There is no Authentication!"); } writer.println(); }
From source file:com.sec.ose.osi.util.tools.FileOperator.java
public static boolean saveFile(String filePath, String contents) { File writeFile = new File(filePath); PrintWriter writer = null; try {/*from w ww. ja v a2 s. c om*/ writer = new PrintWriter(new FileWriter(writeFile)); writer.println(contents); } catch (IOException e) { // TODO Auto-generated catch block log.warn(e); return false; } finally { if (writer != null) { writer.flush(); writer.close(); } writer = null; } return true; }
From source file:edu.vassar.cs.cmpu331.tvi.Main.java
private static void renumber(String filename) throws IOException { Path file = Paths.get(filename); if (Files.notExists(file)) { System.out.println("File not found: " + filename); return;//from www. j a v a2 s . c o m } System.out.println("Renumbering " + filename); Function<String, String> trim = s -> { int i = s.indexOf(':'); if (i > 0) { return s.substring(i + 1).trim(); } return s.trim(); }; List<String> list = Files.lines(file).filter(line -> !line.startsWith("CODE")).map(line -> trim.apply(line)) .collect(Collectors.toList()); int size = list.size(); PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file)); // PrintStream writer = System.out; writer.println("CODE"); IntStream.range(0, size).forEach(index -> { String line = list.get(index); writer.println(index + ": " + line); }); writer.close(); System.out.println("Done."); }
From source file:com.adobe.aem.demomachine.communities.SetupCommunities.java
private static void printCheckbox(PrintWriter out, String fieldName, String fieldLabel, String fieldTooltip) { out.println("<div class=\"coral-Form-fieldwrapper coral-Form-fieldwrapper--singleline\">"); out.println("<label class=\"coral-Form-field coral-Checkbox\">"); out.println(/*from w w w . j a va 2 s . c o m*/ "<input class=\"coral-Checkbox-input\" type=\"checkbox\" name=\"" + fieldName + "\" checked=\"\">"); out.println("<span class=\"coral-Checkbox-checkmark\"></span>"); out.println("<span class=\"coral-Checkbox-description\">" + fieldLabel + "</span>"); out.println("</label>"); out.println("<span id=\"coral-Form-Vertical-Checkbox-" + fieldName + "\" class=\"coral-Form-fieldinfo coral-Icon coral-Icon--infoCircle coral-Icon--sizeS\"></span>"); out.println("<coral-tooltip variant=\"info\" placement=\"right\" target=\"#coral-Form-Vertical-Checkbox-" + fieldName + "\" class=\"coral3-Tooltip coral3-Tooltip--info\" aria-hidden=\"true\" tabindex=\"-1\" role=\"tooltip\" style=\"display: none;\"><coral-tooltip-content>" + fieldTooltip + "</coral-tooltip-content></coral-tooltip>"); out.println("</div>"); }
From source file:edu.brown.benchmark.voteresper.EPRuntimeUtil.java
public static void writeToFile(String toWrite) { try {//from w w w.j a v a 2s.com if (!VoterConstants.PRINT_TO_CONSOLE) { PrintWriter out = new PrintWriter( new BufferedWriter(new FileWriter(VoterConstants.OUT_FILE, true))); out.println(toWrite); out.flush(); out.close(); } else { System.out.println(toWrite); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
static public void writeMultiLine(PrintWriter writer, String message) { BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(message.getBytes()))); try {/*from w w w .j a v a2s . c om*/ String line = reader.readLine(); while (line != null) { writer.println(line); line = reader.readLine(); } } catch (IOException e) { } }
From source file:com.github.seqware.queryengine.system.Utility.java
/** * Write to output file a tab separated key value file represented by map * * @param outputFile a {@link java.io.File} object. * @param map a {@link java.util.Map} object. */// w w w.j a v a2 s. c o m public static void writeKeyValueFile(File outputFile, Map<String, String> map) { if (outputFile != null) { try { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile))); for (Map.Entry<String, String> e : map.entrySet()) { out.println(e.getKey() + "\t" + e.getValue()); Logger.getLogger(FeatureImporter.class.getName()) .info("Writing " + e.getKey() + " " + e.getValue() + " file"); } out.close(); } catch (IOException ex) { Logger.getLogger(FeatureImporter.class.getName()).fatal("Could not write to output file"); } } }
From source file:Main.java
/** * This method get string and create local file with that string * @param st/* w ww . j a v a 2 s. c om*/ * @param fileName */ private static void writeFile(String st, String fileName) { FileOutputStream fos = null; PrintWriter pw = null; try { File rootDir = new File("/storage/emulated/0/dbSuperZol/"); fos = new FileOutputStream(new File(rootDir, fileName)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fos))); pw.println(st); } catch (Exception e) { e.printStackTrace(); } finally { if (pw != null) { pw.close(); } if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:net.cristcost.study.services.ServiceTestUtil.java
public static void testSecurity(String simpleName, HttpServletRequest request, PrintWriter writer, AuthenticationManager authenticationManager, List<TestService> services) { writer.println("Performing test on " + simpleName); writer.println();/*from w w w .ja v a2 s .co m*/ writer.println("I will perform a serie of method invocation on " + services.size() + " different beans"); writer.println(); // Suspend the the Thread for ms of time from "wait" parameter, // used to make some test on behavior of SecurityContext with multiple threads ServiceTestUtil.wait(writer, request, authenticationManager); SecurityContext oldContext = null; try { // if "user" and "pass" parameter are sent, override the security context and perform a new // authentication. Return old context that is needed to be restored at the end of the method oldContext = ServiceTestUtil.authenticate(writer, request, authenticationManager); // Dump current security information ServiceTestUtil.dumpSecurityInformation(writer, authenticationManager); // Invoke the beans for (TestService service : services) { ServiceTestUtil.invokeSecuredBean(writer, service); } } finally { ServiceTestUtil.clearAuthentication(writer, oldContext); // Note: I'm not resetting to anonymous, do it with SecurityStudyUtil.initAnonymous(); } }
From source file:de.hasait.genesis.base.util.GenesisUtils.java
public static void printStackTrace(final Messager pMessager, final Element pElement, final Throwable pThrowable, final String pFormat, final Object... pArgs) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); final String message = String.format(pFormat, pArgs); pw.println(message); pThrowable.printStackTrace(pw);/*from w w w .j ava 2 s. c om*/ pw.flush(); pMessager.printMessage(Diagnostic.Kind.ERROR, sw.toString(), pElement); }