List of usage examples for java.lang Appendable append
Appendable append(char c) throws IOException;
From source file:com.github.xbn.text.StringUtil.java
/** <p>Append one str_obj (with a prefix and postfix) if a condition is met, or another if it's not.</p> //from w ww . jav a 2 s.co m * @exception RTIOException If an {@link java.io.IOException IOException} is thrown */ public static final Appendable appendPreTruePostOrFalse(Appendable to_appendTo, String prefix_ifTrue, Object true_oString, String postfix_ifTrue, boolean condition, Object oString_ifFalse) { try { if (condition) { if (prefix_ifTrue != null) { to_appendTo.append(prefix_ifTrue); } if (true_oString != null) { to_appendTo.append(true_oString.toString()); } if (postfix_ifTrue != null) { to_appendTo.append(postfix_ifTrue); } } else if (oString_ifFalse != null) { to_appendTo.append(oString_ifFalse.toString()); } } catch (IOException iox) { throw new RTIOException("appendPreTruePostOrFalse", iox); } catch (RuntimeException rx) { throw CrashIfObject.nullOrReturnCause(to_appendTo, "to_appendTo", null, rx); } return to_appendTo; }
From source file:org.apache.shindig.gadgets.parse.CompactHtmlSerializer.java
/** * Collapse any consecutive HTML whitespace characters inside a string into * one space character (0x20). This method will not output any characters when * the given string is entirely composed of whitespaces. * * References:// ww w. j a v a 2 s .c o m * <ul> * <li>http://www.w3.org/TR/html401/struct/text.html#h-9.1</li> * <li>http://java.sun.com/javase/6/docs/api/java/lang/Character.html#isWhitespace(char)</li> * </ul> */ static void collapseWhitespace(String str, Appendable output) throws IOException { str = StringUtils.stripStart(str, HTML_WHITESPACE); // Whitespaces between a sequence of non-whitespace characters boolean seenWhitespace = false; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (HTML_WHITESPACE.indexOf(c) != -1) { seenWhitespace = true; } else { if (seenWhitespace) { output.append(' '); } output.append(c); seenWhitespace = false; } } }
From source file:org.diorite.cfg.system.Template.java
/** * Append indent (2 spaces per level)/*from w w w .j a v a 2s.c om*/ * * @param writer {@link Appendable} to use, all data will be added here. * @param level current indent level. * * @throws IOException from {@link Appendable} */ static void spaces(final Appendable writer, final int level) throws IOException { if (level <= 0) { return; } for (int i = 0; i < level; i++) { writer.append(" "); } }
From source file:org.ensembl.healthcheck.util.StreamGobbler.java
public static void streamToBuffer(InputStream is, Appendable out) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = null;/* w ww . j a v a 2 s . c o m*/ while ((line = reader.readLine()) != null) { out.append(line); out.append('\n'); } reader.close(); }
From source file:org.opensingular.form.util.diff.DiffInfo.java
private static void pad(Appendable appendable, int level) throws IOException { for (int i = level * 3; i > 0; i--) { appendable.append(' '); }/*from w w w.j av a2 s . com*/ }
From source file:org.briljantframework.array.ArrayPrinter.java
/** * Format the {@link ArrayPrinter.ToStringArray} * * @param out write resulting string representation to * @param arr the ToStringMatrix//from ww w. j av a 2 s . c o m * @throws java.io.IOException if an IO error occurs */ public static void print(Appendable out, ToStringArray arr, String startChar, String endChar) throws IOException { out.append("array("); if (arr.size() == 0) { out.append(startChar).append(endChar); } else if (arr.size() == 1) { out.append(startChar).append(arr.get(0)).append(endChar); } else { boolean truncate = minTruncateSize < arr.size() && arr.dims() != 1; IntArray maxWidth = computeMaxWidth(arr, truncate); print(out, arr, startChar, endChar, truncate, arr.dims() + 1 + "array(".length(), maxWidth); } out.append(")"); }
From source file:org.apache.ofbiz.widget.WidgetWorker.java
public static void appendContentUrl(Appendable writer, String location, HttpServletRequest request) throws IOException { StringBuilder buffer = new StringBuilder(); ContentUrlTag.appendContentPrefix(request, buffer); writer.append(buffer.toString()); writer.append(location);/*from w w w . j a va 2s . com*/ }
From source file:de.schildbach.wallet.util.CrashReporter.java
public static 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(/*from w ww . j a v a 2 s . c o m*/ "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 = application.getWallet(); 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); final File logDir = application.getDir("log", Context.MODE_PRIVATE); report.append("\nContents of LogDir " + logDir + ":\n"); appendDir(report, logDir, 0); }
From source file:org.briljantframework.array.ArrayPrinter.java
/** * Format the {@link org.briljantframework.array.ArrayPrinter.ToStringArray} * * @param sb write resulting string representation to * @param arr the ToStringMatrix//w ww. j a v a 2s . co m * @throws java.io.IOException if an IO error occurs */ public static void print(Appendable sb, ToStringArray arr, String startChar, String endChar, boolean truncate, int dims, IntArray maxWidth) throws IOException { if (arr.size() == 0) { sb.append(startChar).append(arr.get(0)).append(endChar); return; } if (arr.dims() == 1) { StringJoiner joiner = new StringJoiner(", ", startChar, endChar); int max = arr.size(); if (truncate) { max = visiblePerSlice < 0 ? arr.size() : visiblePerSlice; } for (int i = 0; i < arr.size(); i++) { String value = pad(arr.get(i), maxWidth.get(i % max)); joiner.add(value); if (i >= max) { int left = arr.size() - i - 1; if (left > max) { i += left - max - 1; joiner.add("..."); } } } sb.append(joiner.toString()); } else { int len = arr.size(0); sb.append("["); print(sb, arr.select(0), startChar, endChar, truncate, dims, maxWidth); for (int i = 1; i < len; i++) { if (arr.dims() > 2) { sb.append(",\n\n"); } else { sb.append(",\n"); } for (int j = 0; j < dims - arr.dims(); j++) { sb.append(" "); } print(sb, arr.select(i), startChar, endChar, truncate, dims, maxWidth); int max = len; if (truncate) { max = printSlices < 0 ? len : printSlices; } if (i >= max) { int left = len - i - 1; if (left > max) { i += left - max - 1; sb.append(",\n"); for (int j = 0; j < dims - arr.dims(); j++) { sb.append(" "); } sb.append("..."); } } } sb.append("]"); } }
From source file:org.apache.ofbiz.widget.WidgetWorker.java
public static void makeHiddenFormLinkForm(Appendable writer, String target, String targetType, String targetWindow, Map<String, String> parameterMap, ModelFormField modelFormField, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException { writer.append("<form method=\"post\""); writer.append(" action=\""); // note that this passes null for the parameterList on purpose so they won't be put into the URL WidgetWorker.buildHyperlinkUrl(writer, target, targetType, null, null, false, false, true, request, response, context);/*from w ww.ja v a 2s. com*/ writer.append("\""); if (UtilValidate.isNotEmpty(targetWindow)) { writer.append(" target=\""); writer.append(targetWindow); writer.append("\""); } writer.append(" onsubmit=\"javascript:submitFormDisableSubmits(this)\""); writer.append(" name=\""); writer.append(makeLinkHiddenFormName(context, modelFormField)); writer.append("\">"); for (Map.Entry<String, String> parameter : parameterMap.entrySet()) { if (parameter.getValue() != null) { writer.append("<input name=\""); writer.append(parameter.getKey()); writer.append("\" value=\""); writer.append(UtilCodec.getEncoder("html").encode(parameter.getValue())); writer.append("\" type=\"hidden\"/>"); } } writer.append("</form>"); }