List of usage examples for java.lang StringBuilder length
int length();
From source file:com.khepry.utilities.GenericUtilities.java
public static String joinString(String[] values, String delimiter) { StringBuilder sb = new StringBuilder(); for (String value : values) { sb.append(value);/*w w w . j a v a2 s.c o m*/ sb.append(delimiter); } if (sb.length() >= delimiter.length()) { sb.setLength(sb.length() - delimiter.length()); } return sb.toString(); }
From source file:com.arthackday.killerapp.util.Util.java
public static CharSequence readFile(YouTubeService youTubeService, int id) { BufferedReader in = null;// w ww .j a va 2 s . co m try { in = new BufferedReader(new InputStreamReader(youTubeService.getResources().openRawResource(id))); String line; StringBuilder buffer = new StringBuilder(); while ((line = in.readLine()) != null) { buffer.append(line).append('\n'); } // Chomp the last newline buffer.deleteCharAt(buffer.length() - 1); return buffer; } catch (IOException e) { return ""; } finally { closeStream(in); } }
From source file:com.intuit.elves.network.mock.MockRequest.java
public static String getResponsePayloadAsString(HttpEntity entity) { InputStream is = null;//w ww .j a v a 2 s .c om String responseString = ""; try { is = entity.getContent(); if (is != null) { final StringBuilder sb = new StringBuilder(); String line; final BufferedReader reader = new BufferedReader(new InputStreamReader(is, HTTP.UTF_8)); while ((line = reader.readLine()) != null) { if (sb.length() > 0) { sb.append('\n'); } sb.append(line); } responseString = sb.toString(); } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return responseString; }
From source file:com.cinchapi.concourse.lang.Parser.java
/** * This is a helper method for {@link #toPostfixNotation(String)} that * contains the logic to create a ValueSymbol from a buffered value. * //from w w w . j a va 2 s .co m * @param buffer * @param symbols */ private static void addBufferedValue(StringBuilder buffer, List<Symbol> symbols) { if (buffer != null && buffer.length() > 0) { buffer.delete(buffer.length() - 1, buffer.length()); symbols.add(ValueSymbol.parse(buffer.toString())); buffer.delete(0, buffer.length()); } }
From source file:com.cinchapi.concourse.lang.Parser.java
private static void addBufferedTime(StringBuilder buffer, List<Symbol> symbols) { if (buffer != null && buffer.length() > 0) { buffer.delete(buffer.length() - 1, buffer.length()); long ts = NaturalLanguage.parseMicros(buffer.toString()); symbols.add(TimestampSymbol.create(ts)); buffer.delete(0, buffer.length()); }/*from w w w. ja v a2s . co m*/ }
From source file:com.google.android.mms.transaction.HttpUtils.java
/** * Return the Accept-Language header. Use the current locale plus * US if we are in a different locale than US. *//* w w w . j av a2 s.co m*/ private static String getHttpAcceptLanguage() { Locale locale = Locale.getDefault(); StringBuilder builder = new StringBuilder(); addLocaleToHttpAcceptLanguage(builder, locale); if (!locale.equals(Locale.US)) { if (builder.length() > 0) { builder.append(", "); } addLocaleToHttpAcceptLanguage(builder, Locale.US); } return builder.toString(); }
From source file:com.jaeksoft.searchlib.util.ActiveDirectory.java
final public static String getDisplayString(String domain, String user) { StringBuilder sb = new StringBuilder(); String domainName = getDomainName(domain); if (domainName != null) sb.append(domainName);/* w w w.j a va 2 s . co m*/ if (user != null) { if (sb.length() > 0) sb.append('\\'); sb.append(user); } return sb.toString(); }
From source file:com.tamingtext.classifier.mlt.TrainMoreLikeThis.java
protected static Map<String, String> generateUserData(Collection<String> categories) { StringBuilder b = new StringBuilder(); for (String cat : categories) { b.append(cat).append('|'); }/* w w w . java 2 s . c o m*/ b.setLength(b.length() - 1); Map<String, String> userData = new HashMap<String, String>(); userData.put(CATEGORY_KEY, b.toString()); return userData; }
From source file:com.github.rolecraftdev.command.CommandHelper.java
/** * Sends the {@link CommandSender} a basic overview of the {@link GuildRank} * within the specified {@link Guild}.//w ww.jav a2 s . c o m * * @param sender whom to send the overview * @param guild the applicable {@link Guild} * @param rank the {@link GuildRank} information should be gathered about * @since 0.0.5 */ public static void sendRankInfo(final CommandSender sender, final Guild guild, final GuildRank rank) { sender.sendMessage(ChatColor.GOLD + "Rank " + rank.getName() + " in guild " + guild.getName()); sender.sendMessage(ChatColor.GRAY + "Members: " + rank.getMembers().size()); // Create a human readable version of the permitted actions Set final String separator = ", "; final StringBuilder permitted = new StringBuilder(); for (final GuildAction action : rank.getPermittedActions()) { permitted.append(action.getHumanReadableName()).append(separator); } permitted.setLength(permitted.length() - separator.length()); sender.sendMessage(ChatColor.GRAY + "Permitted Actions: " + permitted.toString()); }
From source file:com.asakusafw.lang.inspection.cli.Cli.java
private static InspectionNode find(InspectionNode node, String path) { InspectionNode current = node;/*from w ww . j ava2 s.com*/ StringBuilder history = new StringBuilder(); for (String segment : path.split(PATH_SEPARATOR)) { if (segment.isEmpty()) { continue; } if (history.length() >= 1) { history.append(PATH_SEPARATOR); } history.append(segment); InspectionNode next = current.getElements().get(segment); if (next == null) { throw new NoSuchElementException(history.toString()); } current = next; } return current; }