List of usage examples for org.apache.commons.lang3.text StrBuilder appendln
public StrBuilder appendln(final double value)
String.valueOf. From source file:com.mgmtp.jfunk.core.mail.MessageUtils.java
/** * Returns the specified message as text. * // www . ja v a2s .c om * @param message * the message * @param includeHeaders * specifies whether message headers are to be included in the returned text * @return the message text */ public static String messageAsText(final Message message, final boolean includeHeaders) { try { StrBuilder sb = new StrBuilder(300); if (includeHeaders) { @SuppressWarnings("unchecked") Enumeration<Header> headers = message.getAllHeaders(); while (headers.hasMoreElements()) { Header header = headers.nextElement(); sb.append(header.getName()).append('=').appendln(header.getValue()); } sb.appendln(""); } Object content = message.getContent(); if (content instanceof String) { String body = (String) content; sb.appendln(body); sb.appendln(""); } else if (content instanceof Multipart) { parseMultipart(sb, (Multipart) content); } return sb.toString(); } catch (MessagingException ex) { throw new MailException("Error getting mail content.", ex); } catch (IOException ex) { throw new MailException("Error getting mail content.", ex); } }
From source file:de.vandermeer.asciitable.commons.ArrayTransformations.java
/** * Takes a 2 dimensional array and returns a string representation in table form. * @param <T> type of the input array * @param ar the array to be transformed * @return a string representation of the array *//*from ww w. j a v a2s . co m*/ public static final <T> StrBuilder ARRAY_TO_STRING(T[][] ar) { StrBuilder ret = new StrBuilder(50); for (int row = 0; row < ar.length; row++) { //TODO not null save if (ar[row] == null) { ret.append("[").append(row).appendln("]: null"); } else if (ar[row].length == 0) { ret.append("[").append(row).appendln("]: 0"); } else { for (int col = 0; col < ar[row].length; col++) { ret.append("[").append(row).append("][").append(col).append("]: "); if (ar[row][col] == null) { ret.appendln("null"); } else if ("".equals(ar[row][col])) { ret.appendln("0"); } else { ret.appendln(ar[row][col]); } } } } return ret; }
From source file:com.mgmtp.jfunk.core.mail.MessageUtils.java
private static void parseMultipart(final StrBuilder sb, final Multipart multipart) throws MessagingException, IOException { for (int i = 0; i < multipart.getCount(); i++) { BodyPart bodyPart = multipart.getBodyPart(i); String disposition = bodyPart.getDisposition(); if (disposition == null && bodyPart instanceof MimeBodyPart) { // not an attachment MimeBodyPart mimeBodyPart = (MimeBodyPart) bodyPart; if (mimeBodyPart.getContent() instanceof Multipart) { parseMultipart(sb, (Multipart) mimeBodyPart.getContent()); } else { String body = (String) mimeBodyPart.getContent(); sb.appendln(body); sb.appendln(""); }/* w w w . j a v a 2 s . co m*/ } } }
From source file:de.vandermeer.skb.base.utils.Skb_TextUtils.java
/** * Returns a transformer that takes a 2 dimensional array and transforms it into a textual representation, for instance for debug output. * @param <T> type of the input array * @return transformer for textual representation of the 2 dimensional array *//*from w w w .j a v a2 s . com*/ public static final <T> Skb_Transformer<T[][], StrBuilder> ARRAY_TO_TEXT() { return new Skb_Transformer<T[][], StrBuilder>() { @Override public StrBuilder transform(T[][] ar) { StrBuilder ret = new StrBuilder(50); for (int row = 0; row < ar.length; row++) { //TODO not null save if (ar[row] == null) { ret.append("[").append(row).appendln("]: null"); } else if (ar[row].length == 0) { ret.append("[").append(row).appendln("]: 0"); } else { for (int col = 0; col < ar[row].length; col++) { ret.append("[").append(row).append("][").append(col).append("]: "); if (ar[row][col] == null) { ret.appendln("null"); } else if ("".equals(ar[row][col])) { ret.appendln("0"); } else { ret.appendln(ar[row][col]); } } } } return ret; } }; }
From source file:de.vandermeer.skb.composite.specialobject.SOObject.java
/** * Renders the list of errors./* w w w .j a v a 2 s .co m*/ * @return string with rendered errors */ public String render() { StrBuilder ret = new StrBuilder(50); for (Message5WH err : this.msglist) { ret.appendln(err.render()); } return ret.toString(); }
From source file:com.alta189.userscript.maven.plugin.UserscriptBuilder.java
private String assemble() throws UserscriptBuilderException { StrBuilder builder = new StrBuilder(); builder.appendln("// ==UserScript=="); appendValid(builder, "// @name ", userscript.getMetadata().getName()); appendValid(builder, "// @namespace ", userscript.getMetadata().getNamespace()); appendValid(builder, "// @description ", userscript.getMetadata().getDescription()); appendValid(builder, "// @version ", userscript.getMetadata().getVersion()); appendValid(builder, "// @author ", userscript.getMetadata().getAuthor()); appendValid(builder, "// @include ", userscript.getMetadata().getIncludes()); appendValid(builder, "// @exclude ", userscript.getMetadata().getExcludes()); appendValid(builder, "// @match ", userscript.getMetadata().getMatches()); appendValid(builder, "// @require ", userscript.getMetadata().getRequires()); appendValid(builder, "// @resource ", userscript.getMetadata().getResources()); appendValid(builder, "// @grant ", userscript.getMetadata().getGrants()); appendValid(builder, "// @noframes ", userscript.getMetadata().isNoFrames()); appendValid(builder, "// @run-at ", userscript.getMetadata().getRunAt()); appendValid(builder, "// @icon ", userscript.getMetadata().getIcon()); appendValid(builder, "// @downloadURL ", userscript.getMetadata().getDownloadURL()); appendValid(builder, "// @updateURL ", userscript.getMetadata().getUpdateURL()); builder.appendln("// ==/UserScript=="); builder.appendNewLine();//from w w w. j a va 2 s. c om File sourceFile = new File(mojo.getSourceDirectory(), userscript.getSource()); String source; try { source = FileUtils.readFileToString(sourceFile); } catch (IOException e) { throw new UserscriptBuilderException("Could not read sourceFile: " + sourceFile.getPath(), e); } builder.append(filterSource(source)); return builder.build(); }
From source file:com.alta189.userscript.maven.plugin.UserscriptBuilder.java
private void appendValid(StrBuilder builder, String input, boolean condition) { if (condition) { builder.appendln(input); }//from w ww. j a v a2s . c o m }
From source file:com.mgmtp.jfunk.core.mail.MailArchiver.java
/** * Saves a message's test content (including headers) in the current module archive in the specified sub-directory relative to * the archive root. File names are prefixed with a left-padded four-digit integer counter (format: {@code %04d_%s.txt}). * /* w w w .j a va2 s . c o m*/ * @param message * the message * @return the file the e-mail was written to */ public File archiveMessage(final MailMessage message) { try { String subject = message.getSubject(); String fileName = subject == null ? "no_subject" : INVALID_FILE_NAME_CHARS.matcher(subject).replaceAll("_"); MutableInt counter = counterProvider.get(); File dir = new File("e-mails", "unread"); File file = new File(dir, String.format(FILE_NAME_FORMAT, counter.intValue(), fileName)); file = new File(moduleArchiveDirProvider.get(), file.getPath()); createParentDirs(file); log.debug("Archiving e-mail: {}", file); StrBuilder sb = new StrBuilder(500); for (Entry<String, String> header : message.getHeaders().entries()) { sb.append(header.getKey()).append('=').appendln(header.getValue()); } sb.appendln(""); sb.append(message.getText()); write(sb.toString(), file, Charsets.UTF_8); counter.increment(); return file; } catch (IOException ex) { throw new MailException("Error archiving mail.", ex); } }
From source file:candr.yoclip.DefaultParserHelpFactoryTest.java
@Test public void testWrap() { final ParserHelpFactory<TestCase> testCase = new DefaultParserHelpFactory<TestCase>(); final int width = 30; assertThat("empty", StringUtils.isEmpty(testCase.wrap("", width)), is(true)); assertThat("null", StringUtils.isEmpty(testCase.wrap(null, width)), is(true)); StrBuilder builder = new StrBuilder(); builder.appendln(StringUtils.repeat("abc", 10)).append(StringUtils.repeat("abc", 5)); assertThat("!whitespace", testCase.wrap(StringUtils.repeat("abc", 15), width), is(builder.toString())); final String pangram = "The quick brown fox jumps over the lazy dog"; builder.clear();/*from w ww . j a v a2 s. c om*/ builder.appendln("The quick brown fox jumps over").append("the lazy dog"); assertThat("pangram", testCase.wrap(pangram, width), is(builder.toString())); final String newLines = "\nExpected first line without indent.\n\nFollowed by more that are not indented.\n"; builder.clear(); builder.appendNewLine().appendln("Expected first line without").appendln("indent.").appendNewLine() .appendln("Followed by more that are not").appendln("indented."); assertThat("new lines", testCase.wrap(newLines, width), is(builder.toString())); }
From source file:candr.yoclip.DefaultParserHelpFactoryTest.java
@Test public void testHangingIndentWrap() { final ParserHelpFactory<TestCase> testCase = new DefaultParserHelpFactory<TestCase>(); final int width = 30; final int indent = 10; assertThat("empty", StringUtils.isEmpty(testCase.hangingIndentWrap("", indent, width)), is(true)); assertThat("null", StringUtils.isEmpty(testCase.hangingIndentWrap(null, indent, width)), is(true)); StrBuilder builder = new StrBuilder(); builder.appendln(StringUtils.repeat("abc", 10)).appendPadding(indent, ' ') .append(StringUtils.repeat("abc", 5)); assertThat("!whitespace", testCase.hangingIndentWrap(StringUtils.repeat("abc", 15), indent, width), is(builder.toString()));// ww w. jav a 2 s . c om final String pangram = "The quick brown fox jumps over the lazy dog"; builder.clear(); builder.appendln("The quick brown fox jumps over").appendPadding(indent, ' ').append("the lazy dog"); assertThat("pangram", testCase.hangingIndentWrap(pangram, indent, width), is(builder.toString())); final String newLines = "\nExpected text without indent.\n\nFollowed by more that is indented.\n"; builder.clear(); builder.appendNewLine().appendln("Expected text without indent.").appendNewLine().appendPadding(indent, ' ') .appendln("Followed by more").appendPadding(indent, ' ').appendln("that is indented."); assertThat("new lines", testCase.hangingIndentWrap(newLines, indent, width), is(builder.toString())); }