List of usage examples for java.io PrintWriter append
public PrintWriter append(char c)
From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicProperties.java
/** * If the indexer file do not exists, build the indexer using the passed configuration and * return the corresponding properties object * //from w ww .j a va 2 s . co m * @note: here we suppose that elevation are stored as double * @note: for a list of available SPI refer to:<br> * geotools/trunk/modules/plugin/imagemosaic/src/main/resources/META-INF/services/org. * geotools.gce.imagemosaic.properties.PropertiesCollectorSPI * * @param indexer * @param configuration * @return * @throws NullPointerException * @throws IOException */ protected static Properties buildIndexer(File indexer, ImageMosaicConfiguration configuration) throws NullPointerException, IOException { // //// // INDEXER // //// if (!indexer.exists()) { FileWriter outFile = null; PrintWriter out = null; try { indexer.createNewFile(); if (!indexer.canWrite()) { final String message = "Unable to write on indexer.properties file at URL: " + indexer.getAbsolutePath(); if (LOGGER.isErrorEnabled()) LOGGER.error(message); throw new IOException(message); } outFile = new FileWriter(indexer); out = new PrintWriter(outFile); File baseDir = indexer.getParentFile(); // Write text to file // setting caching of file to false // create a private copy and fix inconsistencies in it configuration = configuration.clone(); ConfigUtil.sanitize(configuration); // create regex files for (DomainAttribute domainAttr : configuration.getDomainAttributes()) { final File regexFile = new File(baseDir, domainAttr.getAttribName() + "regex.properties"); ImageMosaicProperties.createRegexFile(regexFile, domainAttr.getRegEx()); if (domainAttr.getEndRangeAttribName() != null) { final File endRangeRegexFile = new File(baseDir, domainAttr.getEndRangeAttribName() + "regex.properties"); ImageMosaicProperties.createRegexFile(endRangeRegexFile, domainAttr.getEndRangeRegEx()); } } StringBuilder indexerSB = createIndexer(configuration); out.append(indexerSB); // out.println(org.geotools.gce.imagemosaic.Utils.Prop.CACHING+"=false"); // // // create indexer // DomainAttribute timeAttr = ConfigUtil.getTimeAttribute(configuration); // DomainAttribute elevAttr = ConfigUtil.getElevationAttribute(configuration); // // if(timeAttr != null) { // out.println(org.geotools.gce.imagemosaic.Utils.Prop.TIME_ATTRIBUTE+"="+getAttribDeclaration(timeAttr)); // } // if(elevAttr != null) { // out.println(org.geotools.gce.imagemosaic.Utils.Prop.ELEVATION_ATTRIBUTE+"="+getAttribDeclaration(elevAttr)); // } // // List<DomainAttribute> customAttribs = ConfigUtil.getCustomDimensions(configuration); // if( ! customAttribs.isEmpty() ) { // out.println("AdditionalDomainAttributes"); // String sep="="; // for (DomainAttribute customAttr : customAttribs) { // out.print(sep); // sep=","; // out.print(getDimensionDeclaration(customAttr)); // } // out.println(); // } // // out.print("Schema=*the_geom:Polygon,location:String"); // for (DomainAttribute attr : configuration.getDomainAttributes()) { // TYPE type = attr.getType(); // printSchemaField(out, attr.getAttribName(), type); // if(attr.getEndRangeAttribName() != null) // printSchemaField(out, attr.getEndRangeAttribName(), type); // } // out.println(); // // String sep=""; // out.print("PropertyCollectors="); // for (DomainAttribute attr : configuration.getDomainAttributes()) { // TYPE type = attr.getType(); // out.print(sep); // sep=";"; // printCollectorField(out, attr.getAttribName(), type); // if(attr.getEndRangeAttribName() != null) // printCollectorField(out, attr.getEndRangeAttribName(), type); // } // out.println(); } catch (IOException e) { if (LOGGER.isErrorEnabled()) LOGGER.error("Error occurred while writing indexer.properties file at URL: " + indexer.getAbsolutePath(), e); return null; } finally { if (out != null) { out.flush(); IOUtils.closeQuietly(out); } out = null; if (outFile != null) { IOUtils.closeQuietly(outFile); } outFile = null; } return getPropertyFile(indexer); } else { // file -> indexer.properties /** * get the Caching property and set it to false */ Properties indexerProps = getPropertyFile(indexer); String caching = indexerProps.getProperty(CACHING_KEY); if (caching != null) { if (caching.equals("true")) { indexerProps.setProperty(CACHING_KEY, "false"); } } else { if (LOGGER.isWarnEnabled()) LOGGER.warn("Unable to get the " + CACHING_KEY + " property into the " + indexer.getAbsolutePath() + " file."); } return indexerProps; } }
From source file:org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests.java
protected final ServletContextInitializer sessionServletRegistration() { ServletRegistrationBean<ExampleServlet> bean = new ServletRegistrationBean<>(new ExampleServlet() { @Override//from w ww.j av a 2s. c o m public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { HttpSession session = ((HttpServletRequest) request).getSession(true); long value = System.currentTimeMillis(); Object existing = session.getAttribute("boot"); session.setAttribute("boot", value); PrintWriter writer = response.getWriter(); writer.append(String.valueOf(existing) + ":" + value); } }, "/session"); bean.setName("session"); return bean; }
From source file:org.sonarqube.cppcheck.CppcheckRuleRepositoryTest.java
public static void generate() throws Exception { PrintWriter writer = new PrintWriter(new FileWriter("target/generated-cppcheck.xml")); TreeMap<String, RuleDescription> map = Maps.newTreeMap(); String prevVersion = ""; for (String version : listVersions()) { for (CppcheckXmlParser.Message msg : CppcheckXmlParser .parse(new File("src/main/files/cppcheck-" + version + ".xml"))) { RuleDescription ruleDescription = map.get(msg.getId()); if (ruleDescription == null) { // new rule ruleDescription = new RuleDescription(); map.put(msg.getId(), ruleDescription); ruleDescription.minVersion = version; } else { // existing rule if (!prevVersion.equals(ruleDescription.maxVersion)) { System.err.println("Merge of rule, which appear and disappear from version to version: " + msg.getId()); }/* w w w . ja va 2 s . c o m*/ } ruleDescription.maxVersion = version; // Supposed that message from newer version is better ruleDescription.msg = msg; } prevVersion = version; } Properties replacements = loadReplacements(); writer.println("<results version=\"2\">"); writer.println("<errors>"); for (Map.Entry<String, RuleDescription> entry : map.entrySet()) { RuleDescription description = entry.getValue(); final String versions; if (description.maxVersion.equals(prevVersion)) { versions = " (since Cppcheck " + description.minVersion + ")"; } else if (description.minVersion.equals(description.maxVersion)) { versions = " (Cppcheck " + description.minVersion + ")"; } else { versions = " (Cppcheck " + description.minVersion + "-" + description.maxVersion + ")"; } writer.append("<error "); if (replacements.containsKey(entry.getKey())) { writer.append("SonarQube=\"").append(replacements.getProperty(entry.getKey())).append("\"\n "); } writer.append("id=\"").append(entry.getKey()).append("\" msg=\"") .append(StringEscapeUtils.escapeXml(description.msg.getMsg() + versions)) .append("\" verbose=\"").append(StringEscapeUtils.escapeXml(description.msg.getVerbose())) .append("\" />").println(); } writer.println("</errors>"); writer.println("</results>"); writer.close(); }
From source file:org.jahia.utils.maven.plugin.resources.JavaScriptDictionaryMojo.java
/** * Performs conversion of the property file into JavaScript file. * //from w ww . ja v a 2 s .c o m * @param locale * locale to be used * @throws IOException * in case of an error */ protected void convert(String locale) throws IOException { ResourceBundle defBundle = lookupBundle("", "en"); if (defBundle == null) { throw new FileNotFoundException("ERROR : Couldn't find bundle with name " + resourceBundle + ".properties nor " + resourceBundle + "_en.properties in " + src + " folder, skipping..."); } ResourceBundle bundle = locale != null ? lookupBundle(locale) : null; if (!dest.exists() && !dest.mkdirs()) { throw new IOException("Unable to create folder " + dest); } File target = new File(dest, targetFileName + (locale != null ? "_" + locale : "") + ".js"); getLog().info("Creating " + target + " ..."); PrintWriter out = new PrintWriter(target); Enumeration<String> keyEnum = defBundle.getKeys(); List<String> keys = new LinkedList<String>(); while (keyEnum.hasMoreElements()) { keys.add(keyEnum.nextElement()); } Collections.sort(keys); out.print("var "); out.print(dictionaryName); out.print("={"); if (prettyPrint) { out.println(); } for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) { String key = iterator.next(); String value = bundle != null ? getValue(bundle, key) : null; if (value == null) { value = getValue(defBundle, key); } if (value != null) { if (quoteKeys) { out.append("\""); } out.append(processKey(key)); if (quoteKeys) { out.append("\""); } out.append(":\"").append(processValue(value)).append("\""); if (iterator.hasNext()) { out.append(","); } if (prettyPrint) { out.println(); } } } out.print("};"); if (prettyPrint) { out.println(); } out.flush(); out.close(); getLog().info("done"); }
From source file:com.ifeng.vdn.ip.repository.service.impl.AliIPAddressCheckerTest.java
public void wrap(String input, String output) { Workbook wb = null;//from www. jav a 2 s .com PrintWriter pw = null; try { pw = new PrintWriter(output, "UTF-8"); IPAddressChecker checker = new AliIPAddressChecker(); wb = WorkbookFactory.create(new FileInputStream(input)); Sheet sheet = wb.getSheetAt(0); int totalRows = sheet.getPhysicalNumberOfRows(); Cell ipCell = null; Cell locCell = null; String location = ""; String ipString = ""; for (int i = 1; i < totalRows; i++) { Row row = sheet.getRow(i); ipCell = row.getCell(1); locCell = row.getCell(3); try { ipString = ipCell.getStringCellValue(); AliIPBean ip = (AliIPBean) checker.ipcheck(ipString); location = ip.getIpString(); } catch (Exception e) { log.error(e.getMessage(), e); location = "ERROR"; } finally { //locCell.setCellValue(location); pw.append(ipString + " " + location); pw.println(); } } wb.write(new FileOutputStream(output)); } catch (InvalidFormatException | IOException e) { log.error(e.getMessage(), e); } finally { if (wb != null) try { wb.close(); } catch (IOException e) { e.printStackTrace(); } pw.flush(); pw.close(); } }
From source file:org.commoncrawl.io.internal.NIODNSCache.java
void dumpIPNode(PrintWriter printWriter, Node node) throws IOException { if (node.isTerminalNode()) { printWriter.append(node.getFullName()); printWriter.append(","); printWriter.append(node.getCannonicalName()); printWriter.append("\n"); }/*from ww w . j a v a 2 s . c om*/ for (int i = 0; i < node.getChildCount(); ++i) { dumpIPNode(printWriter, node.getChildAt(i)); } }
From source file:org.energy_home.jemma.internal.shapi.HapProxy.java
private void writeStringObject(HttpServletResponse servletResponse, String object) throws IOException { PrintWriter pw = servletResponse.getWriter(); try {//from w w w . j a v a2 s. c o m if (indexPage != null) pw.append(object); } finally { if (pw != null) pw.close(); } }
From source file:com.esd.ps.EmployerController.java
/** * txt//from w w w. ja va2s. c o m * * @param url * @param packId */ public void writeInTXT(String url, int packId) { try { // String totle = ":" + taskService.getTaskCountByPackId(packId) + "\r\n"; // ? String finishCount = "?:" + workerRecordService.getFinishTaskCountByPackId(packId, 1) + "\r\n"; // ,taskMarkTime == 0 String invalidCount = ":" + workerRecordService.getTaskMarkTimeZeroCountByPackId(packId) + "\r\n"; // wav.length == 0 String wavZeroKB = "0KB:" + taskService.getWorkerIdZeroCountByPackId(packId) + "\r\n"; File f = new File(url + "/readme.txt"); // FileWriter fw = new FileWriter(f); // ?utf-8? PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8")); // pw.append(totle); pw.append(finishCount); pw.append(invalidCount); pw.append(wavZeroKB); pw.flush(); pw.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:quickforms.controller.PutLookup.java
/** * Handles the HTTP/*from w w w .ja va2 s . co m*/ * <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //response.setContentType("text/html;charset=UTF-8"); String application = ""; String field = ""; System.out.println("Saving Lookup"); Database db = null; String json = null; ArrayList<LookupPair> filter = null; PrintWriter out = response.getWriter(); try { List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (item.getFieldName().equals("app")) { application = item.getString(); InitialContext cxt = new InitialContext(); DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/" + application); db = new Database(ds); } else if (item.getFieldName().equals("field")) { field = item.getString(); } else if (item.getFieldName().equals("filter")) { filter = GetMultiData.getFilterList(item.getString()); } } for (FileItem item : items) { System.out.println("Item " + item); if (!item.isFormField()) { File csv = saveFile(item); db.updateLookup(application, field, parseLookup(csv, field), filter); } } } catch (Exception e) { Logger.log(application, e); out.append("Error : " + e.toString()); db.disconnect(); } out.close(); }
From source file:org.commoncrawl.io.internal.NIODNSCache.java
void dumpNode(PrintWriter printWriter, Node node, NodeDumpFilter filter) throws IOException { if (node.isTerminalNode()) { if (filter == null || filter.dumpTerminalNode(node)) { printWriter.append(node.getFullName()); printWriter.append(","); try { printWriter.append((IPAddressUtils.IntegerToInetAddress(node.getIPAddress()).toString())); } catch (UnknownHostException e) { LOG.error(CCStringUtils.stringifyException(e)); }/*from w w w .j a v a 2 s . co m*/ printWriter.append(","); printWriter.append(Long.toString(node.getTimeToLive())); printWriter.append(","); if (node._cannonicalName != null) { printWriter.append(node._cannonicalName); } else { printWriter.append("null"); } printWriter.append(","); printWriter.append(Long.toString(node.getLastTouchedTime())); printWriter.append("\n"); } } for (int i = 0; i < node.getChildCount(); ++i) { dumpNode(printWriter, node.getChildAt(i), filter); } }