List of usage examples for org.apache.commons.lang3 StringUtils LF
String LF
To view the source code for org.apache.commons.lang3 StringUtils LF.
Click Source Link
From source file:com.cognifide.aet.validation.impl.ValidationUtils.java
public static String validationResultToString(ValidationResultBuilder validationResultBuilder) { StringBuilder stringBuilder = new StringBuilder(); if (validationResultBuilder != null && validationResultBuilder.hasErrors()) { stringBuilder.append("Validation failed. "); stringBuilder.append(validationResultBuilder.getErrorMessages().size()); stringBuilder.append(" errors were found:" + StringUtils.LF); int counter = 1; for (ErrorMessage errorMessage : validationResultBuilder.getErrorMessages()) { stringBuilder.append("Error " + counter + StringUtils.LF); stringBuilder.append("\tMessage: "); stringBuilder.append(errorMessage.getMessage()); stringBuilder.append(StringUtils.LF); if (errorMessage.getThrowable() != null) { stringBuilder.append("\tCaused by: "); stringBuilder.append(errorMessage.getThrowable()); stringBuilder.append(StringUtils.LF); }/*from ww w . ja va2 s . c o m*/ counter++; } } return stringBuilder.toString(); }
From source file:ch.cyberduck.cli.TerminalHelpPrinter.java
public static void print(final Options options, final HelpFormatter formatter) { formatter.setSyntaxPrefix("Usage:"); final StringBuilder protocols = new StringBuilder(StringUtils.LF); protocols.append("Supported protocols"); protocols.append(StringUtils.LF);// w w w. ja v a 2 s. co m for (Protocol p : ProtocolFactory.get().find()) { protocols.append(p.getDescription()); protocols.append(StringUtils.LF); switch (p.getType()) { case s3: case googlestorage: case swift: protocols.append("\t").append(String.format("%s://<container>/<key>", p.isBundled() ? p.getIdentifier() : p.getProvider())); break; default: protocols.append("\t").append(String.format("%s://<hostname>/<folder>/<file>", p.isBundled() ? p.getIdentifier() : p.getProvider())); break; } protocols.append(StringUtils.LF); } final StringBuilder header = new StringBuilder(StringUtils.LF); header.append("\t"); header.append("URLs must be fully qualified. Paths can either denote " + "a remote file (ftps://user@example.net/resource) or folder (ftps://user@example.net/directory/) " + "with a trailing slash. You can reference files relative to your home directory with /~ (ftps://user@example.net/~/)."); header.append(protocols.toString()); final Preferences preferences = PreferencesFactory.get(); final Local profiles = LocalFactory.get(preferences.getProperty("application.support.path"), PreferencesFactory.get().getProperty("profiles.folder.name")); header.append(StringUtils.LF); header.append(String.format("You can install additional connection profiles in %s", profiles.getAbbreviatedPath())); header.append(StringUtils.LF); final StringBuilder footer = new StringBuilder(StringUtils.LF); footer.append(String.format( "Cyberduck is libre software licenced under the GPL. For general help about using Cyberduck, please refer to %s and the wiki at %s. For bug reports or feature requests open a ticket at %s.", preferences.getProperty("website.cli"), preferences.getProperty("website.help"), MessageFormat.format(preferences.getProperty("website.bug"), preferences.getProperty("application.version")))); final License l = LicenseFactory.find(); footer.append(StringUtils.LF); if (l.verify(new DisabledLicenseVerifierCallback())) { footer.append(l.toString()); } else { footer.append("Not registered. Purchase a donation key to support the development of this software."); } formatter.printHelp("duck [options...]", header.toString(), options, footer.toString()); }
From source file:ch.cyberduck.cli.TerminalTransferPrompt.java
@Override public TransferAction prompt(final TransferItem item) { final StringBuilder actions = new StringBuilder().append(StringUtils.LF); final Set<TransferAction> options = new HashSet<TransferAction>(TransferAction.forTransfer(transfer)); options.add(TransferAction.cancel);/*from w w w. j av a 2 s .co m*/ for (TransferAction a : options) { actions.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()) .append(String.format(" (%s)", a.name())).append(StringUtils.LF); } final String input; try { switch (transfer) { case download: input = console.readLine( "%nThe local file %s already exists. Choose what action to take:%n%s%nAction %s: ", item.local.getAbsolute(), actions, Arrays.toString(options.toArray())); break; case upload: case move: case copy: input = console.readLine( "%nThe remote file %s already exists. Choose what action to take:%n%s%nAction %s: ", item.remote.getAbsolute(), actions, Arrays.toString(options.toArray())); break; case sync: input = console.readLine("%nChoose what action to take:%n%s%nAction %s: ", actions, Arrays.toString(options.toArray())); break; default: return TransferAction.cancel; } } catch (ConnectionCanceledException e) { return TransferAction.cancel; } final TransferAction action = TransferAction.forName(input); if (null == action) { return this.prompt(item); } return action; }
From source file:de.vandermeer.asciiparagraph.Test_CodeForDocs.java
@Test public void test_WsBehavior() { this.output("whitespace behavior"); AsciiParagraph ap = new AsciiParagraph(); ap.addText("c2 c2"); ap.addText("c3 c3"); ap.addText("c4 c4"); ap.addText("c5 c5"); ap.addText("c6 c6"); ap.addText("c7 c7"); ap.addText("t2 t2"); ap.addText("t3 t3"); ap.addText("t4 t4"); ap.addText("t5 t5"); ap.addText("t6 t6"); ap.addText("t7 t7"); ap.addText("word followed by " + StringUtils.CR + " followed by" + StringUtils.LF + " followed by \n"); ap.getContext().setWidth(60);/*from w w w . ja v a 2 s .c o m*/ ap.getContext().setAlignment(TextAlign.LEFT); System.out.println(ap.render()); this.output(); }
From source file:com.joyent.manta.client.UriSigner.java
/** * Signs an arbitrary URL using the Manta-compatible HTTP signature * method.//from w w w . j ava 2s . c o m * * @param uri URI with no query pointing to a downloadable resource * @param method HTTP request method to be used in the signature * @param expires epoch time in seconds when the resource will no longer * be available * @return a signed version of the input URI * @throws IOException thrown when we can't sign or read char data */ public URI signURI(final URI uri, final String method, final long expires) throws IOException { Validate.notNull(method, "Method must not be null"); Validate.notNull(uri, "URI must not be null"); Validate.isTrue(StringUtils.isEmpty(uri.getQuery()), "Query must be null or empty. URI: %s", uri); final ThreadLocalSigner signer = authConfig.getSigner(); final String charset = "UTF-8"; final String algorithm = signer.get().getHttpHeaderAlgorithm().toUpperCase(); final String keyId = String.format("/%s/keys/%s", authConfig.getMantaUser(), KeyFingerprinter.md5Fingerprint(authConfig.getKeyPair())); final String keyIdEncoded = URLEncoder.encode(keyId, charset); StringBuilder sigText = new StringBuilder(); sigText.append(method).append(StringUtils.LF).append(uri.getHost()).append(StringUtils.LF) .append(uri.getRawPath()).append(StringUtils.LF).append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&").append("keyId=").append(keyIdEncoded); StringBuilder request = new StringBuilder(); final byte[] sigBytes = sigText.toString().getBytes(StandardCharsets.UTF_8); // first parameter isn't actually used for anything, just checked for nullness final byte[] signed = signer.get().sign("", authConfig.getKeyPair(), sigBytes); final String encoded = new String(Base64.encode(signed), charset); final String urlEncoded = URLEncoder.encode(encoded, charset); request.append(uri).append("?").append("algorithm=").append(algorithm).append("&").append("expires=") .append(expires).append("&").append("keyId=").append(keyIdEncoded).append("&").append("signature=") .append(urlEncoded); return URI.create(request.toString()); }
From source file:com.joyent.manta.client.StringIteratorHttpContent.java
/** * Write all of the strings in the stored iterator to the passed * {@link OutputStream}./*from w w w .j av a 2 s . c o m*/ * * @param out output to write to * @throws IOException thrown when we can't write */ protected void writeIterator(final OutputStream out) throws IOException { Validate.notNull(iterator, "Iterator must not be null"); // Start length at zero because it is set to -1 by default length.set(0L); while (iterator.hasNext()) { String next = iterator.next(); if (next == null) { continue; } // We use Unix new lines intentionally for the Manta service final String formatted = String.format("%s%s", next, StringUtils.LF); byte[] bytes = formatted.getBytes(StandardCharsets.UTF_8); length.addAndGet(bytes.length); out.write(bytes); } }
From source file:ch.cyberduck.cli.TerminalOptionsBuilder.java
public static Options options() { final Options options = new Options(); options.addOption(OptionBuilder.withDescription("Username").withLongOpt(Params.username.name()).hasArg(true) .withArgName("username or access key").isRequired(false).create('u')); options.addOption(OptionBuilder.withDescription("Password").withLongOpt(Params.password.name()).hasArg(true) .withArgName("password or secret key").isRequired(false).create('p')); options.addOption(OptionBuilder.withDescription( "Selects a file from which the identity (private key) for public key authentication is read") .withLongOpt(Params.identity.name()).hasArg(true).withArgName("private key file").isRequired(false) .create('i')); options.addOption(/*from w w w.j a v a 2 s.com*/ OptionBuilder.withDescription("Download file or folder. Denote a folder with a trailing '/'") .withLongOpt(TerminalAction.download.name()).hasArgs(2).withArgName("url> <[file]") .withValueSeparator(' ').isRequired(false).create('d')); options.addOption(OptionBuilder.withDescription("Upload file or folder recursively") .withLongOpt(TerminalAction.upload.name()).hasArgs(2).withArgName("url> <file") .withValueSeparator(' ').isRequired(false).create()); options.addOption( OptionBuilder.withDescription("Set explicit permission from octal mode value for uploaded file") .withLongOpt(Params.chmod.name()).hasArgs(1).withArgName("<mode>").withValueSeparator(' ') .isRequired(false).create()); options.addOption( OptionBuilder.withDescription("Copy between servers").withLongOpt(TerminalAction.copy.name()) .hasArgs(2).withArgName("url> <url").withValueSeparator(' ').isRequired(false).create()); options.addOption(OptionBuilder.withDescription("Synchronize folders") .withLongOpt(TerminalAction.synchronize.name()).hasArgs(2).withArgName("url> <directory") .withValueSeparator(' ').isRequired(false).create()); options.addOption(OptionBuilder.withDescription("Edit file in external editor") .withLongOpt(TerminalAction.edit.name()).hasArgs(1).withArgName("url").isRequired(false).create()); options.addOption(OptionBuilder.withDescription("External editor application") .withLongOpt(Params.application.name()).hasArgs(1).withArgName("path").isRequired(false).create()); options.addOption( OptionBuilder.withDescription("List files in remote folder").withLongOpt(TerminalAction.list.name()) .hasArg(true).withArgName("url").isRequired(false).create("l")); options.addOption(OptionBuilder.withDescription("Delete").withLongOpt(TerminalAction.delete.name()) .hasArg(true).withArgName("url").isRequired(false).create("D")); options.addOption(OptionBuilder .withDescription("Long list format with modification date and permission mask") .withLongOpt(Params.longlist.name()).hasArg(true).withArgName("url").isRequired(false).create('L')); options.addOption(OptionBuilder.withDescription("Location of bucket or container") .withLongOpt(Params.region.name()).hasArg(true).withArgName("location").isRequired(false).create()); options.addOption( OptionBuilder.withDescription("Preserve permissions and modification date for transferred files") .withLongOpt(Params.preserve.name()).hasArg(false).isRequired(false).create('P')); options.addOption( OptionBuilder.withDescription("Retry failed connection attempts").withLongOpt(Params.retry.name()) .hasOptionalArg().withArgName("count").isRequired(false).create('r')); options.addOption(OptionBuilder.withDescription("Use UDT protocol if applicable") .withLongOpt(Params.udt.name()).isRequired(false).create()); options.addOption(OptionBuilder.withDescription("Number of concurrent connections to use for transfers") .withLongOpt(Params.parallel.name()).hasOptionalArg().withArgName("connections").isRequired(false) .create()); options.addOption(OptionBuilder.withDescription("Throttle bandwidth").withLongOpt(Params.throttle.name()) .hasArg(true).withArgName("bytes per second").isRequired(false).create()); options.addOption(OptionBuilder.withDescription("Do not save passwords in keychain") .withLongOpt(Params.nokeychain.name()).isRequired(false).create()); final StringBuilder b = new StringBuilder().append(StringUtils.LF); b.append("Options for downloads and uploads:").append(StringUtils.LF); for (TransferAction a : TransferAction.forTransfer(Transfer.Type.download)) { b.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()) .append(String.format(" (%s)", a.name())).append(StringUtils.LF); } for (TransferAction a : Collections.singletonList(TransferAction.cancel)) { b.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()) .append(String.format(" (%s)", a.name())).append(StringUtils.LF); } b.append("Options for synchronize:").append(StringUtils.LF); for (TransferAction a : TransferAction.forTransfer(Transfer.Type.sync)) { b.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()) .append(String.format(" (%s)", a.name())).append(StringUtils.LF); } for (TransferAction a : Collections.singletonList(TransferAction.cancel)) { b.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()) .append(String.format(" (%s)", a.name())).append(StringUtils.LF); } options.addOption( OptionBuilder.withDescription(String.format("Transfer action for existing files%s", b.toString())) .withLongOpt(Params.existing.name()).hasArg(true).withArgName("action").isRequired(false) .create('e')); options.addOption(OptionBuilder.withDescription("Print transcript").withLongOpt(Params.verbose.name()) .hasArg(false).isRequired(false).create('v')); options.addOption(OptionBuilder.withDescription("Suppress progress messages") .withLongOpt(Params.quiet.name()).hasArg(false).isRequired(false).create('q')); options.addOption(OptionBuilder.withDescription("Assume yes for all prompts") .withLongOpt(Params.assumeyes.name()).hasArg(false).isRequired(false).create('y')); options.addOption(OptionBuilder.withDescription("Show version number and quit") .withLongOpt(TerminalAction.version.name()).hasArg(false).isRequired(false).create('V')); options.addOption(OptionBuilder.withDescription("Print this help").withLongOpt(TerminalAction.help.name()) .hasArg(false).isRequired(false).create("h")); return options; }
From source file:com.jaeksoft.searchlib.crawler.database.DatabaseCrawlMongoDb.java
@Override public String test() throws Exception { URI uri = new URI(getUrl()); StringBuilder sb = new StringBuilder(); if (!"mongodb".equals(uri.getScheme())) throw new SearchLibException( "Wrong scheme: " + uri.getScheme() + ". The URL should start with: mongodb://"); MongoClient mongoClient = null;/*from w w w . j a v a2s. c o m*/ try { mongoClient = getMongoClient(); sb.append("Connection established."); sb.append(StringUtils.LF); if (!StringUtils.isEmpty(databaseName)) { MongoDatabase db = mongoClient.getDatabase(databaseName); if (db == null) throw new SearchLibException("Database not found: " + databaseName); MongoIterable<String> collections = db.listCollectionNames(); if (collections == null) throw new SearchLibException("No collection found."); sb.append("Collections found:"); sb.append(StringUtils.LF); for (String collection : collections) { sb.append(collection); sb.append(StringUtils.LF); } if (!StringUtils.isEmpty(collectionName)) { MongoCollection<?> dbCollection = db.getCollection(collectionName); if (dbCollection == null) throw new SearchLibException("Collection " + collectionName + " not found."); sb.append( "Collection " + collectionName + " contains " + dbCollection.count() + " document(s)."); sb.append(StringUtils.LF); if (!StringUtils.isEmpty(criteria)) { long count = dbCollection.count(getCriteriaObject()); sb.append("Query returns " + count + " document(s)."); sb.append(StringUtils.LF); } } } } finally { if (mongoClient != null) mongoClient.close(); } return sb.toString(); }
From source file:com.feilong.taglib.display.httpconcat.HttpConcatUtil.java
/** * items array.// ww w . ja v a2s . c o m * * @param blockContent * ,? \n * @return the items array */ public static List<String> toItemSrcList(String blockContent) { String[] items = StringUtil.split(blockContent.trim(), StringUtils.LF); int length = items.length; List<String> list = new ArrayList<String>(length); for (int i = 0; i < length; ++i) { String item = items[i]; // if (isNotNullOrEmpty(item)) { // list.add(item.trim()); } } return list; }
From source file:net.sourceforge.pmd.docs.RuleDocGenerator.java
private static String stripIndentation(String description) { if (description == null || description.isEmpty()) { return ""; }//from w ww . j av a 2 s . c o m String stripped = StringUtils.stripStart(description, "\n\r"); stripped = StringUtils.stripEnd(stripped, "\n\r "); int indentation = 0; int strLen = stripped.length(); while (Character.isWhitespace(stripped.charAt(indentation)) && indentation < strLen) { indentation++; } String[] lines = stripped.split("\\n"); String prefix = StringUtils.repeat(' ', indentation); StringBuilder result = new StringBuilder(stripped.length()); if (StringUtils.isNotEmpty(prefix)) { for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (i > 0) { result.append(StringUtils.LF); } result.append(StringUtils.removeStart(line, prefix)); } } else { result.append(stripped); } return result.toString(); }