List of usage examples for com.google.common.base Splitter fixedLength
@CheckReturnValue public static Splitter fixedLength(final int length)
From source file:org.books.web.presentation.CreditCardNumberConverter.java
private String addBlanks(String string) { StringBuilder builder = new StringBuilder(); String blank = ""; for (String part : Splitter.fixedLength(PARTITION_SIZE).split(string)) { builder.append(blank);/*from w w w .j a v a 2 s .co m*/ blank = " "; builder.append(part); } return builder.toString(); }
From source file:org.jclouds.virtualbox.functions.StringToKeyCode.java
private List<Integer> transformStandardCharacterIntoKeycodes(String s) { List<Integer> values = Lists.newArrayList(); for (String digit : Splitter.fixedLength(1).split(s)) { Collection<Integer> hex = KeyboardScancodes.NORMAL_KEYBOARD_BUTTON_MAP_LIST.get(digit); if (hex != null) values.addAll(hex);/*from ww w .j av a 2s .c o m*/ } values.addAll(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP_LIST.get("<Spacebar>")); return values; }
From source file:org.jclouds.virtualbox.domain.GetIPAddressFromMAC.java
public GetIPAddressFromMAC(String macAddress) { this(Joiner.on(":").join(Splitter.fixedLength(2).split(macAddress)).toLowerCase(), MacAddressToBSD.INSTANCE .apply(Joiner.on(":").join(Splitter.fixedLength(2).split(macAddress)).toLowerCase())); }
From source file:me.emily.irc.protocol.parser.ChannelModeParser.java
@Override public boolean recieve(String message, ServerConnection connection) { Matcher matcher = pattern.matcher(message); if (matcher.matches()) { Channel channel = connection.getChannel(matcher.group(2)); User user = User.parse(matcher.group(1)); ModeState state = null;//from www .j a va 2 s . com String params = matcher.group(4); Iterator<String> iterator; if (params == null || "".equals(params.trim())) { iterator = Lists.<String>newArrayList().iterator(); } iterator = splitter.split(params).iterator(); for (String c : Splitter.fixedLength(1).split(matcher.group(3))) { if (c.equals("+")) { state = ModeState.added; continue; } if (c.equals("-")) { state = ModeState.removed; continue; } if (iterator.hasNext()) { String next = iterator.next(); log.info(state + " " + c + " " + next); connection.post(new ChannelModeEvent(user, channel, connection, state, c, next)); } else { log.info(state + " " + c); connection.post(new ChannelModeEvent(user, channel, connection, state, c, "")); } } return true; } return false; }
From source file:com.mikehoffert.easyappend.view.TextWrapper.java
/** * Wraps the desired text./*from ww w .ja v a 2 s. c o m*/ * @param text The text to wrap. * @return The wrapped text. */ public String wrap(final String text) { String indent = new String(new char[indentLevel]).replace("\0", " "); return indent + Joiner.on("\n" + indent).join(Splitter.fixedLength(width - indentLevel) .split(Joiner.on(' ').join(Splitter.on(this.delimiter).split(text)))); }
From source file:co.cask.cdap.cli.util.AbstractCommand.java
/** * Creates a string representing the body in the output. It only prints up to {@code maxBodySize}, with line * wrap at each {@code lineWrapLimit} character. *///from w w w.j ava 2 s . c om protected String getBody(ByteBuffer body, int maxBodySize, int lineWrapLimit, String lineSeparator) { ByteBuffer bodySlice = body.slice(); boolean hasMore = false; if (bodySlice.remaining() > maxBodySize) { bodySlice.limit(maxBodySize); hasMore = true; } String str = Bytes.toStringBinary(bodySlice) + (hasMore ? "..." : ""); if (str.length() <= lineWrapLimit) { return str; } return Joiner.on(lineSeparator).join(Splitter.fixedLength(lineWrapLimit).split(str)); }
From source file:org.openqa.selenium.android.intents.IntentSender.java
public synchronized void broadcast(String action, Object... args) { Logger.log(Log.DEBUG, LOG_TAG, String.format("Context: %s, Sending Intent: %s, Args: %s", sender.toString(), action, args.length)); received = false;/*w w w . j a v a 2 s .c om*/ this.action = action; Intent intent = new Intent(action); boolean isParcelable = false; if (args != null) { for (int i = 0; i < args.length; i++) { if (args[i] instanceof Parcelable) { intent.putExtra("arg_" + i, (Parcelable) args[i]); isParcelable = true; } else { if (args[i] instanceof String && args[i].toString().length() > MAX_INTENT_STRING_ARG_LENGTH) { intent.putExtra("arg_" + i, (Serializable) Splitter.fixedLength(MAX_INTENT_STRING_ARG_LENGTH) .split(args[i].toString()).iterator().next()); } else { intent.putExtra("arg_" + i, (Serializable) args[i]); } } } intent.putExtra(IS_PARCELABLE, isParcelable); } // We supply this as the final receiver at the end of the broadcast. The onReceive // method will be the last one to handle the intent. sender.sendOrderedBroadcast(intent, null, this, null, Activity.RESULT_OK, null, null); }
From source file:tech.mcprison.prison.util.Scoreboard.java
private Map.Entry<Team, String> createTeam(String text) { String result;// ww w.j ava 2 s. c om if (text.length() <= 16) { return new AbstractMap.SimpleEntry<>(null, text); } Team team = scoreboard.registerNewTeam("text-" + scoreboard.getTeams().size()); Iterator<String> iterator = Splitter.fixedLength(16).split(text).iterator(); team.setPrefix(iterator.next()); result = iterator.next(); if (text.length() > 32) { team.setSuffix(iterator.next()); } teams.add(team); return new AbstractMap.SimpleEntry<>(team, result); }
From source file:utils.security.SSHKey.java
public String getSSHPrivateKey() { StringBuilder sb = new StringBuilder(); byte[] privateKeyBytes = new PKCS8EncodedKeySpec(encodePrivateKey(this.keyPair)).getEncoded(); String privateKey = new String(Base64.getEncoder().encode(privateKeyBytes)); String ls = System.getProperty("line.separator"); sb.append(PRIVATE_PKCS8_MARKER).append(ls); sb.append(Joiner.on(ls).join(Splitter.fixedLength(64).split(privateKey))).append(ls); sb.append(PRIVATE_PKCS8_MARKER.replace("BEGIN", "END")).append(ls); return sb.toString(); }
From source file:uk.bl.wa.analyser.payload.FirstBytesAnalyser.java
@Override public void analyse(String source, ArchiveRecordHeader header, InputStream tikainput, SolrRecord solr) { final long firstBytesStart = System.nanoTime(); // Pull out the first few bytes, to hunt for new format by magic: try {/* w ww. j a v a 2s. co m*/ byte[] ffb = new byte[this.firstBytesLength]; int read = tikainput.read(ffb); if (read >= 4) { String hexBytes = Hex.encodeHexString(ffb); solr.addField(SolrFields.CONTENT_FFB, hexBytes.substring(0, 2 * 4)); StringBuilder separatedHexBytes = new StringBuilder(); for (String hexByte : Splitter.fixedLength(2).split(hexBytes)) { separatedHexBytes.append(hexByte); separatedHexBytes.append(" "); } if (this.extractContentFirstBytes) { solr.addField(SolrFields.CONTENT_FIRST_BYTES, separatedHexBytes.toString().trim()); } } } catch (Exception i) { log.error(i + ": " + i.getMessage() + ";ffb; " + source + "@" + header.getOffset()); } Instrument.timeRel("WARCPayloadAnalyzers.analyze#total", "WARCPayloadAnalyzers.analyze#firstbytes", firstBytesStart); }