List of usage examples for org.apache.commons.lang.text StrBuilder appendln
public StrBuilder appendln(double value)
String.valueOf. From source file:mitm.common.fetchmail.FetchmailConfigBuilder.java
/** * Writes the new config to targetConfig. Lines between START_TOKEN and END_TOKEN are replaced with the * new config from FetchmailConfig.// w w w . ja va 2 s . c om */ public static void createConfig(FetchmailConfig config, InputStream sourceConfig, OutputStream targetConfig) throws IOException { LineNumberReader reader = new LineNumberReader(new InputStreamReader(sourceConfig, "US-ASCII")); StrBuilder outputBuilder = new StrBuilder(); boolean inBlock = false; boolean blockInjected = false; String line; do { line = reader.readLine(); if (line != null) { if (inBlock) { if (line.startsWith(END_TOKEN)) { inBlock = false; blockInjected = true; injectConfig(config, outputBuilder); outputBuilder.appendln(line); } } else { if (!blockInjected && line.startsWith(START_TOKEN)) { inBlock = true; } outputBuilder.appendln(line); } } } while (line != null); targetConfig.write(MiscStringUtils.toAsciiBytes(outputBuilder.toString())); }
From source file:me.taylorkelly.mywarp.bukkit.util.FormattingUtils.java
/** * Joins the given parts, separated by blanks. The resulting string will be wrapped into multiple lines so that each * line is at most as wide as the given width. Each new line will start with the given prefix. *//from w w w. j a v a 2 s . c om * @param parts the parts * @param newLinePrefix the prefix for created new lines * @param wrappedWidth the width of each line * @return the wrapped string */ private static String wrappedJoin(Iterable<String> parts, String newLinePrefix, int wrappedWidth) { StrBuilder ret = new StrBuilder(); StrBuilder line = new StrBuilder(); for (String part : parts) { // if the word is longer than the maximum length, add chars as long // as possible than make a new line if (getWidth(part) > wrappedWidth) { for (char c : part.toCharArray()) { // if the maximum width is reached, make a new line if (getWidth(line.toString()) + getWidth(c) > wrappedWidth) { ret.appendln(line.toString()); line.clear(); line.append(newLinePrefix); } line.append(c); } // if the world AND the needed black is longer than the maximum // width make a new line and insert the word there } else { // if the maximum width is reached, make a new line if (getWidth(line.toString()) + getWidth(part) + getWidth(' ') > wrappedWidth) { ret.appendln(line.toString()); line.clear(); line.append(newLinePrefix); } // a blank is only needed if the line is not empty AND the last // char is not a a blank (e.g. from prefix) if (!line.isEmpty() && !line.rightString(1).equals(" ")) { line.append(' '); } line.append(part); } } // commit the line if (!line.isEmpty()) { ret.append(line); } return ret.toString(); }
From source file:immf.ImodeMail.java
public String toLoggingString() { StrBuilder buf = new StrBuilder(); buf.appendln("FolderID " + this.folderId); buf.appendln("MailID " + this.mailId); buf.appendln("Subject " + this.subject); buf.appendln("Time " + this.mailId); buf.appendln("Decome " + this.decomeFlg); buf.appendln("RecvType " + this.recvType); buf.appendln("MyAddr " + this.myAddr); buf.appendln("From " + this.fromAddr.toUnicodeString()); for (InternetAddress to : this.toAddrList) { buf.appendln("To " + to.toUnicodeString()); }//w ww . ja v a 2s .c om for (InternetAddress cc : this.ccAddrList) { buf.appendln("Cc " + cc.toUnicodeString()); } for (AttachedFile f : this.attachFileList) { buf.appendln("AttachFile ---- " + f.getFilename()); buf.appendln(" ID " + f.getId()); buf.appendln(" ContentType " + f.getContentType()); buf.appendln(" Size " + f.getData().length); } for (AttachedFile f : this.attachFileList) { buf.appendln("InlineFile ---- " + f.getFilename()); buf.appendln(" ID " + f.getId()); buf.appendln(" ContentType " + f.getContentType()); buf.appendln(" Size " + f.getData().length); } buf.appendln("Body -----"); buf.appendln(this.body); buf.appendln("----------"); return buf.toString(); }
From source file:com.collective.celos.ci.testing.fixtures.compare.FixObjectCompareResult.java
public String generateDescription() throws IOException { StrBuilder strBuilder = new StrBuilder(); PathToMessageProcessor pathToMessage = new PathToMessageProcessor(); TreeObjectProcessor.process(this, pathToMessage); for (Map.Entry<Path, String> pathMessage : pathToMessage.messages.entrySet()) { String keyText = StringUtils.isEmpty(pathMessage.getKey().toString()) ? "" : pathMessage.getKey() + " : "; strBuilder.appendln(keyText + pathMessage.getValue()); }// w w w .j ava 2s . co m return strBuilder.toString(); }
From source file:mitm.djigzo.web.grid.PostfixLogGridDataSource.java
@Override public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints) { try {//from w w w . j a v a 2 s .co m if (logType == PostfixLogType.GROUPED) { List<PostfixLogItem> logItems = logManager.getLogLines(startIndex, endIndex - startIndex + 1, searchPattern != null ? searchPattern.pattern() : null); if (logItems == null) { /* * Can happen because of a race condition where getAvailableRows said that * there are rows available but the items were already removed when prepare * was called. */ logItems = Collections.emptyList(); } logLines = new LinkedList<String>(); for (PostfixLogItem logItem : logItems) { StrBuilder sb = new StrBuilder(256); List<String> itemLines = logItem.getLines(); /* * We will combine the lines of one LogItem into one String */ if (itemLines != null) { for (String line : itemLines) { sb.appendln(line); } } logLines.add(sb.toString()); } } else { /* * Assume it's RAW */ logLines = logManager.getRawLogLines(startIndex, endIndex - startIndex + 1, searchPattern != null ? searchPattern.pattern() : null); } } catch (WebServiceCheckedException e) { throw new DjigzoRuntimeException(e); } this.startIndex = startIndex; }
From source file:mitm.application.djigzo.james.mailets.Log.java
@Override public void serviceMail(Mail mail) { StrBuilder strBuilder = new StrBuilder(256); strBuilder.setNewLineText("; "); strBuilder.append(comment);//from w w w . j av a 2 s . co m DjigzoMailAttributes mailAttributes = new DjigzoMailAttributesImpl(mail); if (logDetail.compareTo(LogDetail.BASIC) >= 0) { strBuilder.append(" | "); String mailID = mailAttributes.getMailID(); strBuilder.append("MailID: "); strBuilder.appendln(mailID); strBuilder.append("Originator: "); strBuilder.appendln(getOriginator(mail)); strBuilder.append("Sender: "); strBuilder.appendln(toString(mail.getSender())); } if (logDetail.compareTo(LogDetail.MIDDLE) >= 0) { strBuilder.append("Remote address: "); strBuilder.appendln(mail.getRemoteAddr()); strBuilder.append("Recipients: "); strBuilder.appendln(mail.getRecipients()); try { if (mail.getMessage() != null) { String subject = mail.getMessage().getSubject(); strBuilder.append("Subject: "); strBuilder.appendln(subject); } } catch (MessagingException e) { getLogger().error("Error getting subject.", e); } try { if (mail.getMessage() != null) { String messageID = mail.getMessage().getMessageID(); strBuilder.append("Message-ID: "); strBuilder.appendln(messageID); } } catch (MessagingException e) { getLogger().error("Error getting messageID.", e); } } if (logDetail.compareTo(LogDetail.FULL) >= 0) { strBuilder.append("Last updated: "); strBuilder.appendln(mail.getLastUpdated()); strBuilder.append("Attribute names: "); strBuilder.appendAll(mail.getAttributeNames()); } logMessage(strBuilder.toString()); }
From source file:mitm.common.dlp.impl.MimeMessageTextExtractorImpl.java
private void extractMimeMessageMetaInfo(MimeMessage message, PartContext context) throws MessagingException { TextExtractorContext extractorContext = new TextExtractorContextImpl(); extractorContext.setEncoding(CharEncoding.US_ASCII); extractorContext.setName("headers"); StrBuilder sb = new StrBuilder(4096); try {// w ww .j a v a2 s. c o m for (Enumeration<?> headerEnum = message.getAllHeaders(); headerEnum.hasMoreElements();) { Header header = (Header) headerEnum.nextElement(); if (header == null) { continue; } if (skipHeaders != null && skipHeaders.contains(StringUtils.lowerCase(header.getName()))) { continue; } sb.append(header.getName()).append(": ").appendln(HeaderUtils.decodeTextQuietly(header.getValue())); } } catch (MessagingException e) { /* * Fallback to raw headers */ for (Enumeration<?> headerEnum = message.getAllHeaderLines(); headerEnum.hasMoreElements();) { sb.appendln(headerEnum.nextElement()); } } byte[] headerBytes = MiscStringUtils.toUTF8Bytes(sb.toString()); RewindableInputStream input = new RewindableInputStream(new ByteArrayInputStream(headerBytes), MEM_THRESHOLD); ExtractedPart part = new ExtractedPartImpl(extractorContext, input, headerBytes.length); try { context.update(part, true /* add */); } catch (IOException e) { throw new MessagingException("Error adding part to context.", e); } }
From source file:org.apache.hadoop.hdfs.server.diskbalancer.command.Command.java
/** * Put output line to log and string buffer. * *//*ww w. j a v a 2 s. c o m*/ protected void recordOutput(final StrBuilder result, final String outputLine) { LOG.info(outputLine); result.appendln(outputLine); }
From source file:org.apache.hadoop.hdfs.server.diskbalancer.command.Command.java
/** * Parse top number of nodes to be processed. * @return top number of nodes to be processed. *//*from w w w . j av a2s .co m*/ protected int parseTopNodes(final CommandLine cmd, final StrBuilder result) { String outputLine = ""; int nodes = 0; final String topVal = cmd.getOptionValue(DiskBalancer.TOP); if (StringUtils.isBlank(topVal)) { outputLine = String.format("No top limit specified, using default top value %d.", getDefaultTop()); LOG.info(outputLine); result.appendln(outputLine); nodes = getDefaultTop(); } else { try { nodes = Integer.parseInt(topVal); } catch (NumberFormatException nfe) { outputLine = String.format("Top limit input is not numeric, using default top value %d.", getDefaultTop()); LOG.info(outputLine); result.appendln(outputLine); nodes = getDefaultTop(); } } return Math.min(nodes, cluster.getNodes().size()); }
From source file:org.apache.hadoop.hdfs.server.diskbalancer.command.ReportCommand.java
private void handleTopReport(final CommandLine cmd, final StrBuilder result, final String nodeFormat) { Collections.sort(getCluster().getNodes(), Collections.reverseOrder()); /* extract value that identifies top X DataNode(s) */ setTopNodes(parseTopNodes(cmd, result)); /*//from w w w . j a v a2s. c o m * Reporting volume information of top X DataNode(s) in summary */ final String outputLine = String .format("Reporting top %d DataNode(s) benefiting from running DiskBalancer.", getTopNodes()); recordOutput(result, outputLine); ListIterator<DiskBalancerDataNode> li = getCluster().getNodes().listIterator(); for (int i = 0; i < getTopNodes() && li.hasNext(); i++) { DiskBalancerDataNode dbdn = li.next(); result.appendln(String.format(nodeFormat, i + 1, getTopNodes(), dbdn.getDataNodeName(), dbdn.getDataNodeIP(), dbdn.getDataNodePort(), dbdn.getDataNodeUUID(), dbdn.getVolumeCount(), dbdn.getNodeDataDensity())); } }