List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:com.cloudera.knittingboar.conf.cmdline.DataConverterCmdLineDriver.java
static void mainToOutput(String[] args, PrintWriter output) throws Exception { if (!parseArgs(args)) { output.write("Parse:Incorrect"); return;/* w w w . j a va 2s. co m*/ } // if output.write("Parse:correct"); int shard_rec_count = Integer.parseInt(strrecordsPerBlock); System.out.println("Converting "); System.out.println("From: " + strInputFile); System.out.println("To: " + strOutputFile); System.out.println("File shard size (record count/file): " + shard_rec_count); int count = DatasetConverter.ConvertNewsgroupsFromSingleFiles(strInputFile, strOutputFile, shard_rec_count); output.write("Total Records Converted: " + count); }
From source file:com.memetix.gun4j.GunshortenAPI.java
protected static JSONObject post(final String serviceUrl, final String paramsString) throws Exception { final URL url = new URL(serviceUrl); final HttpURLConnection uc = (HttpURLConnection) url.openConnection(); if (referrer != null) uc.setRequestProperty("referer", referrer); uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=" + ENCODING); uc.setRequestProperty("Accept-Charset", ENCODING); uc.setRequestMethod("POST"); uc.setDoOutput(true);/*w ww .j av a 2 s . c om*/ final PrintWriter pw = new PrintWriter(uc.getOutputStream()); pw.write(paramsString); pw.close(); uc.getOutputStream().close(); try { final int responseCode = uc.getResponseCode(); final String result = inputStreamToString(uc.getInputStream()); if (responseCode != 200) { throw new Exception("Error from Gunshorten API: " + result); } return parseJSON(result); } finally { uc.getInputStream().close(); if (uc.getErrorStream() != null) { uc.getErrorStream().close(); } } }
From source file:com.progressiveaccess.cmlspeech.base.FileHandler.java
/** * Writes a document to a CML file./*from ww w.ja v a2 s. c o m*/ * * @param doc * The output document. * @param fileName * The base filename. * @param extension * The additional extension. * * @throws IOException * Problems with opening output file. * @throws CDKException * Problems with writing the CML XOM. */ public static void writeFile(final Document doc, final String fileName, final String extension) throws IOException, CDKException { final String basename = FilenameUtils.getBaseName(fileName); final OutputStream outFile = new BufferedOutputStream( new FileOutputStream(basename + "-" + extension + ".cml")); final PrintWriter output = new PrintWriter(outFile); output.write(XOMUtil.toPrettyXML(doc)); output.flush(); output.close(); }
From source file:io.proleap.vb6.TestGenerator.java
public static void generateTreeFile(final File vb6InputFile, final File outputDirectory) throws IOException { final File outputFile = new File(outputDirectory + "/" + vb6InputFile.getName() + TREE_EXTENSION); final boolean createdNewFile = outputFile.createNewFile(); if (createdNewFile) { LOG.info("Creating tree file {}.", outputFile); final InputStream inputStream = new FileInputStream(vb6InputFile); final VisualBasic6Lexer lexer = new VisualBasic6Lexer(new ANTLRInputStream(inputStream)); final CommonTokenStream tokens = new CommonTokenStream(lexer); final VisualBasic6Parser parser = new VisualBasic6Parser(tokens); final StartRuleContext startRule = parser.startRule(); final String inputFileTree = TreeUtils.toStringTree(startRule, parser); final PrintWriter pWriter = new PrintWriter(new FileWriter(outputFile)); pWriter.write(inputFileTree); pWriter.flush();//from ww w. j a va2 s. com pWriter.close(); } }
From source file:com.jredrain.base.utils.CommandUtils.java
public static File createShellFile(String command, String shellFileName) { String dirPath = IOUtils.getTempFolderPath(); File dir = new File(dirPath); if (!dir.exists()) dir.mkdirs();/*from www .j a v a2 s . com*/ String tempShellFilePath = dirPath + File.separator + shellFileName + ".sh"; File shellFile = new File(tempShellFilePath); try { if (!shellFile.exists()) { PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tempShellFilePath))); out.write("#!/bin/bash\n" + command); out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } finally { return shellFile; } }
From source file:Main.java
public static void saveToFile(File folder, String name, String data) { File file = new File(folder, name); PrintWriter pw = null; try {//from w w w . j a v a 2 s . com Writer w = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); pw = new PrintWriter(w); pw.write(data); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } finally { if (pw != null) { pw.close(); } } }
From source file:com.google.api.GoogleAPI.java
/** * Forms an HTTP request, sends it using POST method and returns the result of the request as a JSONObject. * /*w w w . jav a2 s . c om*/ * @param url The URL to query for a JSONObject. * @param parameters Additional POST parameters * @return The translated String. * @throws Exception on error. */ protected static JSONObject retrieveJSON(final URL url, final String parameters) throws Exception { try { final HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setRequestProperty("referer", referrer); uc.setRequestMethod("POST"); uc.setDoOutput(true); final PrintWriter pw = new PrintWriter(uc.getOutputStream()); pw.write(parameters); pw.flush(); try { final String result = inputStreamToString(uc.getInputStream()); return new JSONObject(result); } finally { // http://java.sun.com/j2se/1.5.0/docs/guide/net/http-keepalive.html uc.getInputStream().close(); if (uc.getErrorStream() != null) { uc.getErrorStream().close(); } pw.close(); } } catch (Exception ex) { throw new Exception("[google-api-translate-java] Error retrieving translation.", ex); } }
From source file:com.arsdigita.util.parameter.ParameterPrinter.java
private static void field(final PrintWriter out, final String name, final String value) { if (value != null) { out.write("<"); out.write(name);//from ww w .ja v a 2 s .c o m out.write("><![CDATA["); out.write(value); out.write("]]></"); out.write(name); out.write(">"); } }
From source file:io.proleap.cobol.TestGenerator.java
public static void generateTreeFile(final File cobolInputFile, final File outputDirectory) throws IOException { final File outputFile = new File(outputDirectory + "/" + cobolInputFile.getName() + TREE_EXTENSION); final boolean createdNewFile = outputFile.createNewFile(); if (createdNewFile) { LOG.info("Creating tree file {}.", outputFile); final File parentDirectory = cobolInputFile.getParentFile(); final CobolSourceFormat format = getCobolSourceFormat(parentDirectory); final String preProcessedInput = CobolGrammarContext.getInstance().getCobolPreprocessor() .process(cobolInputFile, parentDirectory, format); final Cobol85Lexer lexer = new Cobol85Lexer(new ANTLRInputStream(preProcessedInput)); final CommonTokenStream tokens = new CommonTokenStream(lexer); final Cobol85Parser parser = new Cobol85Parser(tokens); final StartRuleContext startRule = parser.startRule(); final String inputFileTree = TreeUtils.toStringTree(startRule, parser); final PrintWriter pWriter = new PrintWriter(new FileWriter(outputFile)); pWriter.write(inputFileTree); pWriter.flush();/*from w w w .j a v a2 s .c o m*/ pWriter.close(); } }
From source file:Main.java
public static void writeXML(PrintWriter out, String str) { for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); switch (ch) { case '<': out.write("<"); break; case '>': out.write(">"); break; case '&': out.write("&"); break; case '"': out.write("""); break; case '\'': out.write("'"); break; case '\r': case '\n': out.write(ch);//from ww w .j a va2 s . co m break; default: if ((ch < 32) || (ch > 126)) { out.write("&#x"); out.write(Integer.toString(ch, 16)); out.write(';'); } else { out.write(ch); } break; } } }