List of usage examples for java.lang Appendable append
Appendable append(char c) throws IOException;
From source file:org.opensingular.form.util.diff.DiffInfo.java
private void appendType(Appendable appendable) throws IOException { switch (type) { case UNCHANGED_WITH_VALUE: appendable.append('1'); break;/*from ww w.ja va 2 s . c om*/ case UNCHANGED_EMPTY: appendable.append('0'); break; case CHANGED_NEW: appendable.append('+'); break; case CHANGED_DELETED: appendable.append('-'); break; case CHANGED_CONTENT: appendable.append('~'); break; default: appendable.append('?'); } }
From source file:de.schildbach.wallet.ui.ReportIssueDialogFragment.java
private void appendApplicationInfo(final Appendable report, final WalletApplication application) throws IOException { final PackageInfo pi = application.packageInfo(); final Configuration configuration = application.getConfiguration(); final Calendar calendar = new GregorianCalendar(UTC); report.append("Version: " + pi.versionName + " (" + pi.versionCode + ")\n"); report.append("Package: " + pi.packageName + "\n"); report.append(// w ww . j a v a 2 s. com "Installer: " + application.getPackageManager().getInstallerPackageName(pi.packageName) + "\n"); report.append("Test/Prod: " + (Constants.TEST ? "test" : "prod") + "\n"); report.append("Timezone: " + TimeZone.getDefault().getID() + "\n"); calendar.setTimeInMillis(System.currentTimeMillis()); report.append("Time: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n"); calendar.setTimeInMillis(WalletApplication.TIME_CREATE_APPLICATION); report.append( "Time of launch: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n"); calendar.setTimeInMillis(pi.lastUpdateTime); report.append("Time of last update: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n"); calendar.setTimeInMillis(pi.firstInstallTime); report.append("Time of first install: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n"); final long lastBackupTime = configuration.getLastBackupTime(); calendar.setTimeInMillis(lastBackupTime); report.append("Time of backup: " + (lastBackupTime > 0 ? String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) : "none") + "\n"); report.append("Network: " + Constants.NETWORK_PARAMETERS.getId() + "\n"); final Wallet wallet = viewModel.wallet.getValue(); report.append("Encrypted: " + wallet.isEncrypted() + "\n"); report.append("Keychain size: " + wallet.getKeyChainGroupSize() + "\n"); final Set<Transaction> transactions = wallet.getTransactions(true); int numInputs = 0; int numOutputs = 0; int numSpentOutputs = 0; for (final Transaction tx : transactions) { numInputs += tx.getInputs().size(); final List<TransactionOutput> outputs = tx.getOutputs(); numOutputs += outputs.size(); for (final TransactionOutput txout : outputs) { if (!txout.isAvailableForSpending()) numSpentOutputs++; } } report.append("Transactions: " + transactions.size() + "\n"); report.append("Inputs: " + numInputs + "\n"); report.append("Outputs: " + numOutputs + " (spent: " + numSpentOutputs + ")\n"); report.append("Last block seen: " + wallet.getLastBlockSeenHeight() + " (" + wallet.getLastBlockSeenHash() + ")\n"); report.append("Databases:"); for (final String db : application.databaseList()) report.append(" " + db); report.append("\n"); final File filesDir = application.getFilesDir(); report.append("\nContents of FilesDir " + filesDir + ":\n"); appendDir(report, filesDir, 0); }
From source file:com.github.xbn.testdev.ReplaceAllIndentTabsWithSpaces.java
/** <p>Replace all indentation tabs in a single file.</p> //from w w w .j a v a 2 s . c o m * @param line_itr May not be {@code null}. * @param to_appendTo Where output should be written. May not be {@code null}. * @return A three-tuple containing, in order, the total number of lines in the file, the total lines containing at least one tab, and the total tabs replaced. * @see #appendForFile(Iterator, Appendable) appendForFile * @see #overwriteDirectoryX(Iterator) */ public ThreeTuple<Long, Long, Long> appendForFileX(Iterator<String> line_itr, Appendable to_appendTo) throws IOException { long totalLines = 0; long tabLines = 0; long tabsReplaced = 0; try { while (line_itr.hasNext()) { totalLines++; String line = line_itr.next(); if (line.length() == 0) { to_appendTo.append(line).append(LINE_SEP); continue; } int charIdx = 0; while (charIdx < line.length() && line.charAt(charIdx) == '\t') { charIdx++; to_appendTo.append(getSpaces()); //getDebugAptr().pauseIfUseable("[" + totalLines + "." + charIdx + "]: \"" + getSpaces() + "\""); } tabsReplaced += charIdx; tabLines++; if (charIdx > 0 && getDebugAptr().isUseable() && getDebugLevel().isLineCounts()) { getDebugAptr().appent(NumberUtil.getCharForNumber0Through62(charIdx)); } to_appendTo.append(line.substring(charIdx)).append(LINE_SEP); } } catch (RuntimeException rx) { CrashIfObject.nnull(line_itr, "line_itr", null); throw CrashIfObject.nullOrReturnCause(to_appendTo, "to_appendTo", null, rx); } if (getDebugAptr().isUseable() && getDebugLevel().isOnAndAtLeast(TabToSpaceDebugLevel.FILE_SUMMARIES)) { getDebugAptr().appentln(); getDebugAptr().appent(" - " + getSummaryFromStats(-1, totalLines, tabLines, tabsReplaced)); } return new ThreeTuple<Long, Long, Long>(totalLines, tabLines, tabsReplaced); }
From source file:com.github.xbn.text.padchop.VzblPadChop.java
public Appendable appendlns(int new_lineCount, Appendable to_appendTo, String prefix, Object text, String postfix) {// w w w . j a v a 2s. c om try { to_appendTo.append(prefix); appendX(to_appendTo, text).append(postfix); IOUtil.appendNewLinesX(new_lineCount, to_appendTo); return to_appendTo; } catch (IOException iox) { throw new RuntimeException("appendln(i,apbl,s,O,s)", iox); } }
From source file:org.efaps.wikiutil.export.latex.WikiPage2Tex.java
/** * * @param _out appendable instance to the Latex file * @param _page Wiki page to convert * @throws IOException if write failed// ww w .j av a2 s. com */ public void convert(final Appendable _out, final WikiPage _page) throws IOException { // get title /*String title = null; for (final AbstractProperty prop : _page.getProperties()) { if (prop instanceof Summary) { title = ((Summary) prop).getValue(); } }*/ _out.append(WikiPage2Tex.STRUCTURE[this.structureLevel]).append("{").append(this.escape(this.title)) .append("}\n"); this.appendParagraph(_out, _page); for (final Section section : _page.getSubSections()) { this.appendSection(_out, section, 1); } }
From source file:com.bigml.histogram.ArrayCategoricalTarget.java
@Override protected void appendTo(final Appendable appendable, final DecimalFormat format) throws IOException { if (appendable == null) { throw new NullPointerException("appendable must not be null"); }/*from w w w. j a v a2 s .c o m*/ if (format == null) { throw new NullPointerException("format must not be null"); } for (Entry<Object, Integer> categoryIndex : _indexMap.entrySet()) { Object category = categoryIndex.getKey(); int index = categoryIndex.getValue(); double count = _target[index]; appendable.append(String.valueOf(category)); appendable.append("\t"); appendable.append(format.format(count)); } }
From source file:org.apache.cayenne.access.trans.JoinStack.java
protected void appendJoinSubtree(Appendable out, JoinTreeNode node) throws IOException { DbRelationship relationship = node.getRelationship(); DbEntity targetEntity = (DbEntity) relationship.getTargetEntity(); String srcAlias = node.getSourceTableAlias(); String targetAlias = node.getTargetTableAlias(); switch (node.getJoinType()) { case INNER:/*from w ww . ja v a 2s . c o m*/ out.append(" JOIN"); break; case LEFT_OUTER: out.append(" LEFT JOIN"); break; default: throw new IllegalArgumentException("Unsupported join type: " + node.getJoinType()); } out.append(' '); if (targetEntity.getSchema() != null) { out.append(strategy.quoteString(targetEntity.getSchema())); out.append("."); } out.append(strategy.quoteString(targetEntity.getName())); out.append(' '); out.append(strategy.quoteString(targetAlias)); out.append(" ON ("); List<DbJoin> joins = relationship.getJoins(); int len = joins.size(); for (int i = 0; i < len; i++) { DbJoin join = joins.get(i); if (i > 0) { out.append(" AND "); } out.append(strategy.quoteString(srcAlias)); out.append('.'); out.append(strategy.quoteString(join.getSourceName())); out.append(" = "); out.append(strategy.quoteString(targetAlias)); out.append('.'); out.append(strategy.quoteString(join.getTargetName())); } /** * Attaching root Db entity's qualifier */ Expression dbQualifier = targetEntity.getQualifier(); if (dbQualifier != null) { dbQualifier = dbQualifier.transform(new JoinedDbEntityQualifierTransformer(node)); if (len > 0) { out.append(" AND "); } qualifierTranslator.setOut(out); qualifierTranslator.doAppendPart(dbQualifier); } out.append(')'); for (JoinTreeNode child : node.getChildren()) { appendJoinSubtree(out, child); } }
From source file:com.github.xbn.text.padchop.VzblPadChop.java
public Appendable appendlns(int new_lineCount, Appendable to_appendTo, int goal_len, String prefix, Object text, String postfix) {//from w ww .ja v a 2 s.c o m try { to_appendTo.append(prefix); appendX(to_appendTo, goal_len, text).append(LINE_SEP); IOUtil.appendNewLinesX(new_lineCount, to_appendTo); return to_appendTo.append(postfix); } catch (IOException iox) { throw new RuntimeException("appendln(i,apbl,i,s,O,s)", iox); } }
From source file:net.dv8tion.jda.core.entities.impl.MessageImpl.java
@Override public void formatTo(Formatter formatter, int flags, int width, int precision) { boolean upper = (flags & FormattableFlags.UPPERCASE) == FormattableFlags.UPPERCASE; boolean leftJustified = (flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY; boolean alt = (flags & FormattableFlags.ALTERNATE) == FormattableFlags.ALTERNATE; String out = alt ? getRawContent() : getContent(); if (upper)//from w w w.j av a2s .c o m out = out.toUpperCase(formatter.locale()); try { Appendable appendable = formatter.out(); if (precision > -1 && out.length() > precision) { appendable.append(Helpers.truncate(out, precision - 3)).append("..."); return; } if (leftJustified) appendable.append(Helpers.rightPad(out, width)); else appendable.append(Helpers.leftPad(out, width)); } catch (IOException e) { throw new AssertionError(e); } }
From source file:org.apache.ofbiz.widget.WidgetWorker.java
public static void buildHyperlinkUrl(Appendable externalWriter, String target, String targetType, Map<String, String> parameterMap, String prefix, boolean fullPath, boolean secure, boolean encode, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException { // We may get an encoded request like: /projectmgr/control/EditTaskContents?workEffortId=10003 // Try to reducing a possibly encoded string down to its simplest form: /projectmgr/control/EditTaskContents?workEffortId=10003 // This step make sure the following appending externalLoginKey operation to work correctly String localRequestName = StringEscapeUtils.unescapeHtml(target); localRequestName = UtilHttp.encodeAmpersands(localRequestName); Appendable localWriter = new StringWriter(); if ("intra-app".equals(targetType)) { if (request != null && response != null) { ServletContext servletContext = request.getSession().getServletContext(); RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_"); externalWriter .append(rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode)); } else if (prefix != null) { externalWriter.append(prefix); externalWriter.append(localRequestName); } else {// ww w . j a v a 2s .c o m externalWriter.append(localRequestName); } } else if ("inter-app".equals(targetType)) { String fullTarget = localRequestName; localWriter.append(fullTarget); String externalLoginKey = (String) request.getAttribute("externalLoginKey"); if (UtilValidate.isNotEmpty(externalLoginKey)) { if (fullTarget.indexOf('?') == -1) { localWriter.append('?'); } else { localWriter.append("&"); } localWriter.append("externalLoginKey="); localWriter.append(externalLoginKey); } } else if ("content".equals(targetType)) { appendContentUrl(localWriter, localRequestName, request); } else if ("plain".equals(targetType)) { localWriter.append(localRequestName); } else { localWriter.append(localRequestName); } if (UtilValidate.isNotEmpty(parameterMap)) { String localUrl = localWriter.toString(); externalWriter.append(localUrl); boolean needsAmp = true; if (localUrl.indexOf('?') == -1) { externalWriter.append('?'); needsAmp = false; } for (Map.Entry<String, String> parameter : parameterMap.entrySet()) { String parameterValue = null; if (parameter.getValue() instanceof String) { parameterValue = parameter.getValue(); } else { Object parameterObject = parameter.getValue(); // skip null values if (parameterObject == null) continue; if (parameterObject instanceof String[]) { // it's probably a String[], just get the first value String[] parameterArray = (String[]) parameterObject; parameterValue = parameterArray[0]; Debug.logInfo("Found String array value for parameter [" + parameter.getKey() + "], using first value: " + parameterValue, module); } else { // not a String, and not a String[], just use toString parameterValue = parameterObject.toString(); } } if (needsAmp) { externalWriter.append("&"); } else { needsAmp = true; } externalWriter.append(parameter.getKey()); externalWriter.append('='); UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); if (simpleEncoder != null && parameterValue != null) { externalWriter.append(simpleEncoder .encode(URLEncoder.encode(parameterValue, Charset.forName("UTF-8").displayName()))); } else { externalWriter.append(parameterValue); } } } else { externalWriter.append(localWriter.toString()); } }