private void writeTransactionsToFile(String transaction) { try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output, true), "utf-8")); writer.append(transaction); writer.append(newLine); } catch (IOException e) { System.out.println("DEBUG: -----Start-----\n" + e + "DEBUG: ------End------\n"); } try { if (writer != null) writer.close(); } catch (IOException e) { System.out.println("DEBUG: -----Start-----\n" + e + "DEBUG: ------End------\n"); } }
public void buildDict(Set<String> dict) throws IOException { int c = 0; for (String key : dict) { if (++c % 1000 == 0) { writer.flush(); System.err.println(c + "/" + dict.size() + " items processed."); } IdTouple touple = getIdTouple(key); // touple.oid = guessOther(key); writer .append(key) .append("\t") .append(touple.gid) .append("\t") .append(touple.pname) /*.append("\t").append(touple.oid)*/ .append("\n"); writer.flush(); } writer.close(); if (file != null) { FileWriter fw = new FileWriter(file); fw.write(new Date().toString()); fw.close(); } }
private void println(String s) { if (logger != null) { try { logger.append(s).append("\n"); logger.flush(); } catch (IOException e) { e.printStackTrace(); } } }
public void createExcel(String file) { String filename = createPath(file); System.out.println(filename); /* try { WorkbookSettings ws = new WorkbookSettings(); ws.setLocale(new Locale("sv", "SE")); WritableWorkbook workbook = Workbook.createWorkbook(new File(filename), ws); WritableSheet s = workbook.createSheet("Sheet1", 0); //writeDataSheet(s); workbook.write(); workbook.close(); } catch (IOException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); }**/ try { File newFile = new File(filename); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), "UTF8")); // BufferedWrite output = new BufferedWriter(new OutputStreamReader(new // FileInputS§tream(filename), "iso-8859-1")); // FileWriter fw = new FileWriter(newFile.getAbsoluteFile()); // BufferedWriter bw = new BufferedWriter(fw); // bw.write("Artikel;Antal/st;Pris/st;Total\n"); out.append("Artikel;Antal/st;Pris/st;Total\n"); for (Data d : dataList) { out.append(d.toString()); out.append("\n"); // bw.write(d.toString()); // bw.write("\n"); } // bw.close(); out.flush(); out.close(); } catch (UnsupportedEncodingException unsuppEn) { unsuppEn.printStackTrace(); } catch (IOException ioE) { ioE.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
private void func_27328_a(JsonNode p_27328_1_, Writer p_27328_2_) throws IOException { boolean flag = true; switch (CompactJsonFormatter_JsonNodeType.field_27341_a[p_27328_1_.func_27218_a().ordinal()]) { case 1: // '\001' p_27328_2_.append('['); JsonNode jsonnode; for (Iterator iterator = p_27328_1_.func_27215_d().iterator(); iterator.hasNext(); func_27328_a(jsonnode, p_27328_2_)) { jsonnode = (JsonNode) iterator.next(); if (!flag) { p_27328_2_.append(','); } flag = false; } p_27328_2_.append(']'); break; case 2: // '\002' p_27328_2_.append('{'); JsonStringNode jsonstringnode; for (Iterator iterator1 = (new TreeSet(p_27328_1_.func_27214_c().keySet())).iterator(); iterator1.hasNext(); func_27328_a((JsonNode) p_27328_1_.func_27214_c().get(jsonstringnode), p_27328_2_)) { jsonstringnode = (JsonStringNode) iterator1.next(); if (!flag) { p_27328_2_.append(','); } flag = false; func_27328_a(((JsonNode) (jsonstringnode)), p_27328_2_); p_27328_2_.append(':'); } p_27328_2_.append('}'); break; case 3: // '\003' p_27328_2_ .append('"') .append((new JsonEscapedString(p_27328_1_.func_27216_b())).toString()) .append('"'); break; case 4: // '\004' p_27328_2_.append(p_27328_1_.func_27216_b()); break; case 5: // '\005' p_27328_2_.append("false"); break; case 6: // '\006' p_27328_2_.append("true"); break; case 7: // '\007' p_27328_2_.append("null"); break; default: throw new RuntimeException( (new StringBuilder()) .append("Coding failure in Argo: Attempt to format a JsonNode of unknown type [") .append(p_27328_1_.func_27218_a()) .append("];") .toString()); } }
public Writer getErrorReport( Writer to, final HttpServletRequest request, CharTransformer escape) throws IOException { final Writer logMsg = new StringWriter(); final Writer tee = new org.mmbase.util.ChainedWriter(to, logMsg); Writer msg = tee; LinkedList<Throwable> stack = getStack(); String ticket = new Date().toString(); Map<String, String> props; try { props = org.mmbase.util.ApplicationContextReader.getProperties("mmbase_errorpage"); } catch (javax.naming.NamingException ne) { props = Collections.emptyMap(); log.info(ne); } if (request != null) { { msg.append("Headers\n----------\n"); // request properties for (Object name : Collections.list(request.getHeaderNames())) { msg.append( escape.transform( name + ": " + escape.transform(request.getHeader((String) name)) + "\n")); } } { msg.append("\nAttributes\n----------\n"); Pattern p = requestIgnore; if (p == null && props.get("request_ignore") != null) { p = Pattern.compile(props.get("request_ignore")); } for (Object name : Collections.list(request.getAttributeNames())) { if (p == null || !p.matcher((String) name).matches()) { msg.append( escape.transform(name + ": " + request.getAttribute((String) name) + "\n")); } } } if (Boolean.TRUE.equals(showSession) || (showSession == null && !"false".equals(props.get("show_session")))) { HttpSession ses = request.getSession(false); if (ses != null) { msg.append("\nSession\n----------\n"); Pattern p = sessionIgnore; if (p == null && props.get("session_ignore") != null) { p = Pattern.compile(props.get("session_ignore")); } for (Object name : Collections.list(ses.getAttributeNames())) { if (p == null || !p.matcher((String) name).matches()) { msg.append(escape.transform(name + ": " + ses.getAttribute((String) name) + "\n")); } } } } } msg.append("\n"); msg.append("Misc. properties\n----------\n"); if (request != null) { msg.append("method: ").append(escape.transform(request.getMethod())).append("\n"); msg.append("querystring: ").append(escape.transform(request.getQueryString())).append("\n"); msg.append("requesturl: ") .append(escape.transform(request.getRequestURL().toString())) .append("\n"); } if (Boolean.TRUE.equals(showMMBaseVersion) || (showMMBaseVersion == null && !"false".equals(props.get("show_mmbase_version")))) { msg.append("mmbase version: ").append(org.mmbase.Version.get()).append("\n"); } msg.append("status: ").append("").append(String.valueOf(status)).append("\n\n"); if (request != null) { msg.append("Parameters\n----------\n"); // request parameters Enumeration en = request.getParameterNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); msg.append(name) .append(": ") .append(escape.transform(request.getParameter(name))) .append("\n"); } } msg.append("\nException ") .append(ticket) .append("\n----------\n\n") .append( exception != null ? (escape.transform(exception.getClass().getName())) : "NO EXCEPTION") .append(": "); int wroteCauses = 0; while (!stack.isEmpty()) { Throwable t = stack.removeFirst(); // add stack stacktraces if (t != null) { if (stack.isEmpty()) { // write last message always msg = tee; } String message = t.getMessage(); if (msg != tee) { to.append("\n=== skipped(see log) : ") .append(escape.transform(t.getClass().getName())) .append(": ") .append(message) .append("\n"); } msg.append("\n\n").append(escape.transform(t.getClass().getName() + ": " + message)); StackTraceElement[] stackTrace = t.getStackTrace(); for (StackTraceElement e : stackTrace) { msg.append("\n at ").append(escape.transform(e.toString())); } if (!stack.isEmpty()) { msg.append("\n-------caused:\n"); } wroteCauses++; if (wroteCauses >= MAX_CAUSES) { msg = logMsg; } } } // write errors to log if (status == 500) { try { if (props.get("to") != null && props.get("to").length() > 0) { javax.naming.Context initCtx = new javax.naming.InitialContext(); javax.naming.Context envCtx = (javax.naming.Context) initCtx.lookup("java:comp/env"); Object mailSession = envCtx.lookup("mail/Session"); Class sessionClass = Class.forName("javax.mail.Session"); Class recipientTypeClass = Class.forName("javax.mail.Message$RecipientType"); Class messageClass = Class.forName("javax.mail.internet.MimeMessage"); Object mail = messageClass.getConstructor(sessionClass).newInstance(mailSession); messageClass .getMethod("addRecipients", recipientTypeClass, String.class) .invoke(mail, recipientTypeClass.getDeclaredField("TO").get(null), props.get("to")); messageClass.getMethod("setSubject", String.class).invoke(mail, ticket); mail.getClass().getMethod("setText", String.class).invoke(mail, logMsg.toString()); Class.forName("javax.mail.Transport") .getMethod("send", Class.forName("javax.mail.Message")) .invoke(null, mail); tee.append("\nmailed to (").append(String.valueOf(props)).append(")"); } } catch (Exception nnfe) { tee.append("\nnot mailed (").append(String.valueOf(nnfe)).append(")"); if (log.isDebugEnabled()) { log.debug(nnfe.getMessage(), nnfe); } } log.error("TICKET " + ticket + ":\n" + logMsg); } return to; }