List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:org.callimachusproject.repository.CalliRepository.java
private static void print(Trace call, PrintWriter w) { if (call.getPreviousTrace() != null) { print(call.getPreviousTrace(), w); }/*from www. jav a 2 s . c om*/ for (String assign : call.getAssignments()) { w.println(assign); } w.println(call.toString()); }
From source file:io.warp10.worf.WorfInteractive.java
private static long getTTL(String line, PrintWriter out) { try {/* w w w .j a v a 2s . com*/ long ttl = Long.valueOf(line); long ttlMax = Long.MAX_VALUE - System.currentTimeMillis(); if (ttl >= ttlMax) { out.println("TTL can not be upper than " + ttlMax); return 0L; } return ttl; } catch (NumberFormatException exp) { out.println(line + " is not a long"); return 0L; } }
From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java
/** * Writes the data to <a href="http://databionic-esom.sourceforge.net/user.html#File_formats">ESOM lrn/cls * format</a>./*from www . ja v a 2 s . c o m*/ */ public static void writeAsESOM(InputData data, String fileName) throws IOException, SOMLibFileFormatException { String fileNameLrn = StringUtils.appendExtension(fileName, ".lrn"); // write the header, see http://databionic-esom.sourceforge.net/user.html#File_formats Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Writing input data as ESOM file to '" + fileNameLrn + "'."); PrintWriter writer = FileUtils.openFileForWriting("ESOM lrn", fileNameLrn, false); if (org.apache.commons.lang.StringUtils.isNotBlank(data.getDataSource())) { writer.println("# Converted from " + data.getDataSource() + "."); } writer.println("% " + data.numVectors()); writer.println("% " + (data.dim() + 1)); writer.println("% 9" + StringUtils.repeatString(data.dim(), "\t 1")); writer.println("% Key\t" + StringUtils.interleave(data.templateVector().getLabels(), "\t")); for (int i = 0; i < data.numVectors(); i++) { writer.print(String.valueOf(i + 1)); // index in the lrn file will start with 1, make sure this is in synch // with ESOMMapOutputter for (int j = 0; j < data.dim(); j++) { writer.print("\t" + data.getValue(i, j)); } writer.println(); } writer.close(); // write the names file String fileNameNames = StringUtils.appendOrReplaceExtension(fileName, ".lrn", ".names"); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Writing names as ESOM file to '" + fileNameNames + "'."); writer = FileUtils.openFileForWriting("ESOM names", fileNameNames, false); if (org.apache.commons.lang.StringUtils.isNotBlank(data.getDataSource())) { writer.println("# Converted from " + data.getDataSource() + "."); } writer.println("% " + data.numVectors()); for (int i = 0; i < data.numVectors(); i++) { // index in the names file starts at 1, make sure this is in synch with lrn file and ESOMMapOutputter writer.println(String.valueOf(i + 1) + "\t" + data.getLabel(i)); } writer.close(); if (data.classInformation() != null) { // guess a good filename String fileNameCls = StringUtils.appendOrReplaceExtension(fileName, ".lrn", ".cls"); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Writing class info as ESOM file to '" + fileNameCls + "'."); writeAsESOM(data.classInformation(), fileNameCls); } }
From source file:edu.umd.cs.submit.CommandLineSubmit.java
/** * @param submitUserFile//from ww w. j a v a 2 s.co m * @param courseKey * @param projectNumber * @param authenticationType * @param baseURL * @throws IOException * @throws UnsupportedEncodingException * @throws URISyntaxException * @throws HttpException */ public static void createSubmitUser(File submitUserFile, String courseKey, String projectNumber, String authenticationType, String baseURL) throws IOException, UnsupportedEncodingException, URISyntaxException, HttpException { PrintWriter newUserProjectFile; if (authenticationType.equals("openid")) { String[] result = getSubmitUserForOpenId(courseKey, projectNumber, baseURL); String classAccount = result[0]; String onetimePassword = result[1]; newUserProjectFile = new PrintWriter(new FileWriter(submitUserFile)); newUserProjectFile.println("classAccount=" + classAccount); newUserProjectFile.println("oneTimePassword=" + onetimePassword); } else { String loginName, password; Console console = System.console(); System.out.println("Please enter your LDAP username and password"); System.out.print("LDAP username: "); loginName = console.readLine(); System.out.println("Password: "); password = new String(console.readPassword()); System.out.println("Thanks!"); System.out.println("Preparing for submission. Please wait..."); String url = baseURL + "/eclipse/NegotiateOneTimePassword"; PostMethod post = new PostMethod(url); post.addParameter("loginName", loginName); post.addParameter("password", password); post.addParameter("courseKey", courseKey); post.addParameter("projectNumber", projectNumber); HttpClient client = new HttpClient(); client.setConnectionTimeout(HTTP_TIMEOUT); // System.out.println("Preparing to execute method"); int status = client.executeMethod(post); // System.out.println("Post finished with status: " +status); if (status != HttpStatus.SC_OK) { throw new HttpException( "Unable to negotiate one-time password with the server: " + post.getResponseBodyAsString()); } InputStream inputStream = post.getResponseBodyAsStream(); BufferedReader userStream = new BufferedReader(new InputStreamReader(inputStream)); newUserProjectFile = new PrintWriter(new FileWriter(submitUserFile)); while (true) { String line = userStream.readLine(); if (line == null) break; // System.out.println(line); newUserProjectFile.println(line); } userStream.close(); } newUserProjectFile.close(); if (!submitUserFile.canRead()) { System.out.println("Can't generate or access " + submitUserFile); System.exit(1); } }
From source file:eu.annocultor.tools.GeneratorOfXmlSchemaForConvertersDoclet.java
static void printConstructorSchema(ConstructorDoc constr, PrintWriter out) throws Exception { if (constr.modifierSpecifier() == Modifier.PUBLIC) { String affix = constr.annotations()[0].elementValues()[1].value().toString(); affix = StringUtils.stripEnd(StringUtils.stripStart(affix, "\""), "\""); out.println("<!-- " + constr.qualifiedName() + constr.signature() + " -->"); out.println(" <xs:element name=\"" + constr.qualifiedName() + "-" + affix + "\" substitutionGroup=\"ABSTRACT-RULE\" >"); out.println(" <xs:complexType> "); out.println(" <xs:sequence>"); findType(constr, new Formatter(out) { @Override/*from w ww.java2 s. c om*/ public void formatElementStart(String name, String type, boolean array) { writer.print(" <xs:element name=\"" + name + "\" type=\"" + type + "\"" + (array ? " minOccurs=\"0\" maxOccurs=\"unbounded\" " : "") + ">"); } @Override public void formatDocumentation(String doc) { writer.print("\n <xs:annotation><xs:documentation xml:lang=\"en\">" + StringEscapeUtils.escapeXml(doc) + "</xs:documentation></xs:annotation>"); } @Override public void formatElementEnd(String name) { writer.print(" \n </xs:element>"); } }); } out.println(ruleListenerDef); out.println(" </xs:sequence>"); out.println(" </xs:complexType> "); out.println(" </xs:element>"); }
From source file:eu.annocultor.tools.GeneratorOfXmlSchemaForConvertersDoclet.java
static void printConstructorDoc(ConstructorDoc constr, PrintWriter out) throws Exception { if (constr.modifierSpecifier() == Modifier.PUBLIC) { String affix = constr.annotations()[0].elementValues()[1].value().toString(); affix = StringUtils.stripEnd(StringUtils.stripStart(affix, "\""), "\""); out.println(" <h2 id=\"Constructor " + constr.name() + "-" + affix + "\">Constructor <code>" + affix + "</code></h2>"); out.println();/*from w ww .ja v a 2 s . c om*/ out.println(" <p>" + constr.commentText() + "</p>"); out.println(); out.println(" <p>Sample use:</p>"); out.println("<div class=\"source\"><pre>"); out.println(StringEscapeUtils.escapeHtml("<ac:" + constr.qualifiedName() + "-" + affix + ">")); findType(constr, new Formatter(out) { @Override public void formatElementStart(String name, String type, boolean array) { writer.print(StringEscapeUtils.escapeHtml(" <ac:" + name + " rdf:datatype=\"" + type + "\">")); } @Override public void formatDocumentation(String doc) { writer.print(" <i style=\"font-family: Times\">" + StringEscapeUtils.escapeHtml(doc) + "</i> "); } @Override public void formatElementEnd(String name) { writer.println(StringEscapeUtils.escapeHtml("</ac:" + name + ">")); } }); out.println(StringEscapeUtils.escapeHtml("</ac:" + constr.qualifiedName() + "-" + affix + ">")); out.println("</pre></div>"); } out.println(); out.flush(); }
From source file:io.warp10.worf.WorfInteractive.java
private static TokenType getTokenType(String line, PrintWriter out) { try {/*from w w w. ja v a 2 s . c o m*/ if (Strings.isNullOrEmpty(line)) { return null; } return TokenType.valueOf(line.toUpperCase()); } catch (Exception exp) { out.println("token type " + line + " unknown. (read|write) expected"); return null; } }
From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java
private static void writeToFile(String filename, String content) throws IOException { File newFile = new File(filename); if (!newFile.isFile()) { newFile.createNewFile();//w ww . j ava2s.co m } PrintWriter out = new PrintWriter(newFile.getAbsolutePath()); out.println(content); out.close(); }
From source file:de.zib.scalaris.examples.wikipedia.data.xml.Main.java
/** * Filters all pages in the Wikipedia XML2DB dump from the given file and * creates a list of page names belonging to certain categories. * //w ww . j a v a2s . c om * @param filename * @param args * * @throws RuntimeException * @throws IOException * @throws SAXException * @throws FileNotFoundException */ private static void doDumpdbFilter(String filename, String[] args) throws RuntimeException, IOException, SAXException, FileNotFoundException { int i = 0; int recursionLvl = 1; if (args.length > i) { try { recursionLvl = Integer.parseInt(args[i]); } catch (NumberFormatException e) { System.err.println("no number: " + args[i]); System.exit(-1); } } ++i; String pageListFileName = ""; if (args.length > i && !args[i].isEmpty()) { pageListFileName = args[i]; } else { System.err.println("need a pagelist file name for filter; arguments given: " + Arrays.toString(args)); System.exit(-1); } ++i; Set<String> allowedPages0 = new HashSet<String>(); allowedPages0.add("Main Page"); String allowedPagesFileName = ""; if (args.length > i && !args[i].isEmpty()) { allowedPagesFileName = args[i]; addFromFile(allowedPages0, allowedPagesFileName); } ++i; LinkedList<String> rootCategories = new LinkedList<String>(); if (args.length > i) { for (String rCat : Arrays.asList(args).subList(i, args.length)) { if (!rCat.isEmpty()) { rootCategories.add(rCat); } } } WikiDumpHandler.println(System.out, "filtering by categories " + rootCategories.toString() + " ..."); WikiDumpHandler.println(System.out, " wiki dump : " + filename); WikiDumpHandler.println(System.out, " allowed pages : " + allowedPagesFileName); WikiDumpHandler.println(System.out, " recursion lvl : " + recursionLvl); WikiDumpHandler.println(System.out, "creating list of pages to import (recursion level: " + recursionLvl + ") ..."); Set<String> allowedCats0 = new HashSet<String>(rootCategories); WikiDumpSQLiteLinkTables handler = new WikiDumpSQLiteLinkTables(filename); handler.setUp(); SortedSet<String> pages = handler.getPagesInCategories(allowedCats0, allowedPages0, recursionLvl, false); handler.tearDown(); do { FileWriter outFile = new FileWriter(pageListFileName); PrintWriter out = new PrintWriter(outFile); for (String page : pages) { out.println(page); } out.close(); } while (false); exitCheckHandler(handler); }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java
private static void writeProviders(Set<Source> sources, PrintWriter out) { final Set<AbstractContact> all = new HashSet<AbstractContact>(); for (final Source source : sources) { all.addAll(source.getProviders()); }// w w w . j a v a2 s. c om for (final AbstractContact c : all) { out.print("!Sample_biomaterial_provider="); out.println(((Organization) c).getName()); } }