List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:net.metanotion.sqlc.SQLC.java
public static int makeMethod(final PrintWriter writer, final SQLMethod m, final AssignmentWrap qe, final int level, final int[] gensym, final int[] braces, final boolean retValue) { final int gi = gensym[0]; final int init = gensym[0] + 1; gensym[0] += 2;//from w ww. j a va 2 s . com writer.println("\t\t\tfinal net.metanotion.util.reflect.GetInitializer<" + qe.result + "> _" + gi + " = net.metanotion.util.reflect.ReflectiveFieldInitializer.getInitializer(" + qe.result + ".class, this.types);"); writer.println("\t\t\tfinal net.metanotion.util.reflect.Initializer<" + qe.result + "> _" + init + " = _" + gi + ".initializer();"); final Iterator<String> fields = qe.fields.iterator(); final Iterator<QueryExpr> qs = qe.exprs.iterator(); while (qs.hasNext()) { final QueryExpr q = qs.next(); final String field = fields.next(); int returnSymbol = makeMethod(writer, m, q, level, gensym, braces, false); writer.println("\t\t\t_" + init + ".put(\"" + field + "\", _" + (returnSymbol) + ");"); } writer.println("\t\t\treturn _" + init + ".instance();"); while (braces[0] > 0) { writer.println("}"); braces[0]--; } return -1; }
From source file:doclet.RefGuideDoclet.java
/** * Write a static file into the stream. Only write the BODY content. * @param pw//from w ww . j a va 2s . co m * @param file * @throws IOException */ private static void writeStaticFile(PrintWriter pw, String file) throws IOException { String st = FileUtils.readFileToString(new File(file)); int s_idx = st.indexOf("<BODY>"); if (s_idx == -1) { s_idx = st.indexOf("<body"); } int e_idx = st.indexOf("</BODY>"); if (e_idx == -1) { e_idx = st.indexOf("</body"); } if (s_idx != -1 && e_idx != -1) { st = st.substring(s_idx + 6, e_idx); } pw.println("<!-- Begin static file: " + file + " -->"); // Strip out pw.println(st); pw.println("<!-- End static file: " + file + " -->"); }
From source file:net.sf.firemox.tools.MSaveDeck.java
/** * Saves deck to ASCII file from specified staticTurnLists. This new file will * contain the card names sorted in alphabetical order with their quantity * with this format :<br>/*from w w w . j av a2s.co m*/ * <i>card's name </i> <b>; </b> <i>qty </i> <b>\n </b> <br> * * @param fileName * Name of new file. * @param names * ListModel of card names. * @param parent * the parent * @return true if the current deck has been correctly saved. false otherwise. */ public static boolean saveDeck(String fileName, MListModel<MCardCompare> names, JFrame parent) { PrintWriter outStream = null; try { // create the deckfile. If it was already existing, it would be scrathed. outStream = new PrintWriter(new FileOutputStream(fileName)); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(parent, "Cannot create/modify the specified deck file:" + fileName + "\n" + ex.getMessage(), "File creation problem", JOptionPane.ERROR_MESSAGE); return false; } Object[] namesArray = names.toArray(); MCardCompare[] cards = new MCardCompare[namesArray.length]; System.arraycopy(namesArray, 0, cards, 0, namesArray.length); // sorts names Arrays.sort(cards, new MCardCompare()); // writes lines corresponding to this format : "card;quantity\n" for (int i = 0; i < cards.length; i++) { outStream.println(cards[i].toString()); } IOUtils.closeQuietly(outStream); // successfull deck save JOptionPane.showMessageDialog(parent, "Saving file " + fileName.substring(fileName.lastIndexOf("/") + 1) + " was successfully completed.", "Save success", JOptionPane.INFORMATION_MESSAGE); return true; }
From source file:eu.pawelsz.apache.beam.coders.TupleCoderGenerator.java
private static void writeTupleCoderClass(PrintWriter w, int numFields) { final String tupleClass = "Tuple" + numFields; final String className = tupleClass + "Coder"; StringBuilder sb = new StringBuilder(); for (int i = 0; i < numFields; i++) { if (i > 0) { sb.append(", "); }/*from ww w.j a va 2s . c om*/ sb.append(GEN_TYPE_PREFIX + i); } final String types = sb.toString(); final int maxIdx = numFields - 1; // head w.print(HEADER); // package and imports w.println("package " + PACKAGE + ';'); w.println(); w.println("import com.fasterxml.jackson.annotation.JsonCreator;"); w.println("import com.fasterxml.jackson.annotation.JsonProperty;"); w.println("import com.google.common.base.Preconditions;"); w.println("import org.apache.beam.sdk.coders.Coder;"); w.println("import org.apache.beam.sdk.coders.CoderException;"); w.println("import org.apache.beam.sdk.coders.StandardCoder;"); w.println("import org.apache.beam.sdk.util.PropertyNames;"); w.println("import org.apache.beam.sdk.util.common.ElementByteSizeObserver;"); w.println("import org.apache.flink.api.java.tuple." + tupleClass + ";"); w.println(""); w.println("import java.io.IOException;"); w.println("import java.io.InputStream;"); w.println("import java.io.OutputStream;"); w.println("import java.util.Arrays;"); w.println("import java.util.List;"); w.println(""); w.println("public class " + className + "<" + types + "> extends StandardCoder<" + tupleClass + "<" + types + ">> {"); w.println(); w.println(""); w.println(" public static <" + types + "> " + className + "<" + types + "> of("); for (int i = 0; i < numFields - 1; i++) { w.println(" Coder<" + GEN_TYPE_PREFIX + i + "> t" + i + ","); } w.println(" Coder<" + GEN_TYPE_PREFIX + maxIdx + "> t" + maxIdx + ") {"); w.print(" return new " + className + "<>("); for (int i = 0; i < numFields; i++) { if (i > 0) { w.print(", "); } w.print("t" + i); } w.println(");"); w.println(" }"); w.println(""); w.println(" @JsonCreator"); w.print(" public static " + className + "<"); for (int i = 0; i < numFields; i++) { if (i > 0) { w.print(", "); } w.print("?"); } w.println("> of("); w.println(" @JsonProperty(PropertyNames.COMPONENT_ENCODINGS)"); w.println(" List<Coder<?>> components) {"); w.println(" Preconditions.checkArgument(components.size() == " + numFields + ","); w.println(" \"Expecting " + numFields + " components, got\" + components.size());"); w.println(" return of("); for (int i = 0; i < numFields; i++) { if (i > 0) { w.println(","); } w.print(" components.get(" + i + ")"); } w.println(");"); w.println(" }"); w.println(""); w.println(" public static <" + types + "> List<Object> getInstanceComponents("); w.println(" " + tupleClass + "<" + types + "> exampleValue) {"); w.println(" return Arrays.asList("); for (int i = 0; i < numFields; i++) { if (i > 0) { w.println(","); } w.print(" exampleValue.f" + i); } w.println(");"); w.println(" }"); for (int i = 0; i < numFields; i++) { w.println(""); w.println(" public Coder<" + GEN_TYPE_PREFIX + i + "> getF" + i + "Coder() {"); w.println(" return t" + i + "Coder;"); w.println(" }"); } w.println(""); for (int i = 0; i < numFields; i++) { w.println(" private final Coder<" + GEN_TYPE_PREFIX + i + "> t" + i + "Coder;"); } w.println(""); w.println(" private " + className + "("); for (int i = 0; i < numFields; i++) { if (i > 0) { w.println(","); } w.print(" Coder<" + GEN_TYPE_PREFIX + i + "> t" + i + "Coder"); } w.println(") {"); for (int i = 0; i < numFields; i++) { w.println(" this.t" + i + "Coder = t" + i + "Coder;"); } w.println(" }"); w.println(""); w.println(" @Override"); w.println(" public void encode(" + tupleClass + "<" + types + "> tuple, OutputStream outputStream, Context context)"); w.println(" throws CoderException, IOException {"); w.println(" if (tuple == null) {"); w.println(" throw new CoderException(\"cannot encode a null " + tupleClass + "\");"); w.println(" }"); w.println(" Context nestedContext = context.nested();"); for (int i = 0; i < numFields; i++) { w.println(" t" + i + "Coder.encode(tuple.f" + i + ", outputStream, nestedContext);"); } w.println(" }"); w.println(""); w.println(" @Override"); w.println(" public " + tupleClass + "<" + types + "> decode(InputStream inputStream, Context context)"); w.println(" throws CoderException, IOException {"); w.println(" Context nestedContext = context.nested();"); for (int i = 0; i < numFields; i++) { w.println(" " + GEN_TYPE_PREFIX + i + " f" + i + " = t" + i + "Coder.decode(inputStream, nestedContext);"); } w.print(" return " + tupleClass + ".of("); for (int i = 0; i < numFields; i++) { if (i > 0) { w.print(", "); } w.print("f" + i); } w.println(");"); w.println(" }"); w.println(""); w.println(" @Override"); w.println(" public List<? extends Coder<?>> getCoderArguments() {"); w.print(" return Arrays.asList("); for (int i = 0; i < numFields; i++) { if (i > 0) { w.print(", "); } w.print("t" + i + "Coder"); } w.print(");"); w.println(" }"); w.println(""); w.println(" @Override"); w.println(" public void verifyDeterministic() throws NonDeterministicException {"); for (int i = 0; i < numFields; i++) { w.println(" verifyDeterministic(\"Coder of T" + i + " must be deterministic\", t" + i + "Coder);"); } w.println(" }"); w.println(""); w.println(" @Override"); w.println(" public boolean consistentWithEquals() {"); w.print(" return"); for (int i = 0; i < numFields; i++) { if (i > 0) { w.print("\n &&"); } w.print(" t" + i + "Coder.consistentWithEquals()"); } w.println(";"); w.println(" }"); w.println(""); w.println(" @Override"); w.println(" public Object structuralValue(" + tupleClass + "<" + types + "> tuple) throws Exception {"); w.println(" if (consistentWithEquals()) {"); w.println(" return tuple;"); w.println(" } else {"); w.println(" return " + tupleClass + ".of("); for (int i = 0; i < numFields; i++) { if (i > 0) { w.println(","); } w.print(" t" + i + "Coder.structuralValue(tuple.f" + i + ")"); } w.println(");"); w.println(" }"); w.println(" }"); w.println(""); w.println(" @Override"); w.println(" public boolean isRegisterByteSizeObserverCheap(" + tupleClass + "<" + types + "> tuple, Context context) {"); w.print(" return"); for (int i = 0; i < numFields; i++) { if (i > 0) { w.print("\n &&"); } w.print(" t" + i + "Coder.isRegisterByteSizeObserverCheap(tuple.f" + i + ", context.nested())"); } w.println(";"); w.println(" }"); w.println(""); w.println(" @Override"); w.println(" public void registerByteSizeObserver(" + tupleClass + "<" + types + "> tuple,"); w.println(" ElementByteSizeObserver observer,"); w.println(" Context context) throws Exception {"); w.println(" if (tuple == null) {"); w.println(" throw new CoderException(\"cannot encode a null " + tupleClass + " \");"); w.println(" }"); w.println(" Context nestedContext = context.nested();"); for (int i = 0; i < numFields; i++) { w.println(" t" + i + "Coder.registerByteSizeObserver(tuple.f" + i + ", observer, nestedContext);"); } w.println(" }"); w.println("}"); }
From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java
/** Writes the data to <a href="http://www.cs.waikato.ac.nz/~ml/weka/arff.html">Weka ARFF format</a>. */ public static void writeAsWekaARFF(InputData data, String fileName, boolean writeInstanceNames, boolean skipInputsWithoutClass) throws IOException, SOMToolboxException { if (data.classInformation() == null) { throw new SOMToolboxException("Class Information File needed for WEKA ARFF writing"); }// w w w.j a v a 2s . c o m fileName = StringUtils.ensureExtension(fileName, ".arff"); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Writing input data as ARFF file to '" + fileName + "'."); PrintWriter writer = FileUtils.openFileForWriting("Weka ARFF", fileName, false); TemplateVector tv = data.templateVector(); if (tv == null) { Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Template vector not loaded - creating a generic one."); tv = new SOMLibTemplateVector(data.numVectors(), data.dim()); } String relation = fileName.substring(0, fileName.length() - 4); writer.println("@RELATION " + relation + "\n"); for (int i = 0; i < tv.dim(); i++) { writer.println("@ATTRIBUTE " + tv.getLabel(i) + " NUMERIC"); } if (writeInstanceNames) { writer.println("@ATTRIBUTE instanceName STRING"); } writer.println(getWekaClassHeader(data.classInformation().classNames())); writer.println("@DATA"); int skipCounter = 0; StdErrProgressWriter progress = new StdErrProgressWriter(data.numVectors(), "Writing vector ", data.numVectors() / 10); for (int i = 0; i < data.numVectors(); i++) { InputDatum inputDatum = data.getInputDatum(i); if (skipInputsWithoutClass && !data.classInformation().hasClassAssignmentForName(inputDatum.getLabel())) { skipCounter++; Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Skipping datum '" + inputDatum.getLabel() + "', as it has no class assigned; skipped " + skipCounter + " so far."); continue; } DoubleMatrix1D vector = inputDatum.getVector(); for (int j = 0; j < data.dim(); j++) { writer.print(vector.get(j) + ","); } if (writeInstanceNames) { writer.print("'" + StringUtils.escapeForWeka(inputDatum.getLabel()) + "',"); } writer.println("'" + data.classInformation().getClassName(inputDatum.getLabel()) + "'"); progress.progress(); } writer.flush(); writer.close(); }
From source file:net.metanotion.sqlc.SQLC.java
public static int makeMethod(final PrintWriter writer, final SQLMethod m, final StatementMacro qe, final int level, final int[] gensym, final int[] braces, final boolean retValue) { final int sb = gensym[0]; gensym[0]++;/*from w w w . j av a2 s .c o m*/ final int stmt = gensym[0]; gensym[0]++; writer.println("\t\t\tfinal StringBuilder _" + sb + " = new StringBuilder();"); for (final SQLElement e : qe.statement) { if (e instanceof SEConstant) { writer.println("\t\t\t_" + sb + ".append(\"" + StringEscapeUtils.escapeJava(((SEConstant) e).sql) + "\");"); } else { final String vName = ((SEMacro) e).name; for (int i = 0; i < m.pList.length; i++) { if (m.pList[i].equals(vName)) { writer.println("\t\t\t_" + sb + ".append(_" + (i + 1) + ".toString());"); } } } } writer.println("\t\t\ttry (final java.sql.PreparedStatement _" + stmt + " = _0.prepareStatement(_" + sb + ".toString())) {"); braces[0] = braces[0] + 1; for (final SQLSetter s : qe.setters) { int i = 0; for (int j = 0; j < m.pList.length; j++) { if (s.name.equals(m.pList[j])) { i = j + 1; break; } } writer.println("\t\t\t" + s.setStatic("_" + stmt, "_" + i) + ";"); } writer.println("\t\t\t_" + stmt + ".execute();"); return -1; }
From source file:net.metanotion.sqlc.SQLC.java
public static int makeMethod(final PrintWriter writer, final SQLMethod m, final CountWrap qe, final int level, final int[] gensym, final int[] braces, final boolean retValue) { makeMethod(writer, m, qe.expr, level + 1, gensym, braces, retValue); final int stmt = gensym[0] - 1; if (retValue) { writer.println("\t\t\treturn _" + stmt + ".getUpdateCount();"); while (braces[0] > 0) { writer.println("}"); braces[0]--;//from w w w . ja va2 s. c om } } else { gensym[0]++; writer.println("\t\t\tfinal int _" + (gensym[0] - 1) + " = _" + stmt + ".getUpdateCount();"); } return gensym[0] - 1; }
From source file:com.aurel.track.prop.LoginBL.java
public static String writeJSONResponse(StringBuilder sb) { try {/*from w ww .j a v a2s .com*/ ServletActionContext.getResponse().addHeader("Access-Control-Allow-Origin", "*"); JSONUtility.prepareServletResponseJSON(ServletActionContext.getResponse()); PrintWriter out = ServletActionContext.getResponse().getWriter(); out.println(sb); } catch (IOException e) { // can't do much here LOGGER.error(e); } return null; }
From source file:com.zimbra.cs.service.FileUploadServlet.java
public static void sendResponse(HttpServletResponse resp, int status, String fmt, String reqId, List<Upload> uploads, List<FileItem> items) throws IOException { boolean raw = false, extended = false; if (fmt != null && !fmt.trim().equals("")) { // parse out the comma-separated "fmt" options for (String foption : fmt.toLowerCase().split(",")) { raw |= ContentServlet.FORMAT_RAW.equals(foption); extended |= "extended".equals(foption); }//w ww . j av a2 s.co m } StringBuffer results = new StringBuffer(); results.append(status).append(",'").append(reqId != null ? StringUtil.jsEncode(reqId) : "null") .append('\''); if (status == HttpServletResponse.SC_OK) { boolean first = true; if (extended) { // serialize as a list of JSON objects, one per upload results.append(",["); for (Upload up : uploads) { Element.JSONElement elt = new Element.JSONElement("ignored"); elt.addAttribute(MailConstants.A_ATTACHMENT_ID, up.uuid); elt.addAttribute(MailConstants.A_CONTENT_TYPE, up.getContentType()); elt.addAttribute(MailConstants.A_CONTENT_FILENAME, up.name); elt.addAttribute(MailConstants.A_SIZE, up.getSize()); results.append(first ? "" : ",").append(elt.toString()); first = false; } results.append(']'); } else { // serialize as a string containing the comma-separated upload IDs results.append(",'"); for (Upload up : uploads) { results.append(first ? "" : UPLOAD_DELIMITER).append(up.uuid); first = false; } results.append('\''); } } resp.setContentType("text/html; charset=utf-8"); PrintWriter out = resp.getWriter(); if (raw) { out.println(results); } else { out.println("<html><head>" + "<script language='javascript'>\nfunction doit() { window.parent._uploadManager.loaded(" + results + "); }\n</script>" + "</head><body onload='doit()'></body></html>\n"); } out.close(); // handle failure by cleaning up the failed upload if (status != HttpServletResponse.SC_OK && items != null && items.size() > 0) { for (FileItem fi : items) { mLog.debug("sendResponse(): deleting %s", fi); fi.delete(); } } }
From source file:spring.DirectWriteController.java
@RequestMapping(value = "/write") public void write(PrintWriter writer) { writer.println("OK"); writer.flush(); }