List of usage examples for com.google.common.base Splitter fixedLength
@CheckReturnValue public static Splitter fixedLength(final int length)
From source file:c5db.log.CatOLog.java
private static String toHex(long address) { return String.join(" ", Splitter.fixedLength(4).split(String.format("%0" + HEX_ADDRESS_DIGITS + "x", address))); }
From source file:me.boomboompower.deathwalls.maker.SimpleScoreboard.java
private Map.Entry<Team, String> createTeam(String text) { String result;//from w w w .java2s . c o m if (text.length() <= 16) return new AbstractMap.SimpleEntry(null, text); Team team = this.scoreboard.registerNewTeam("text-" + this.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()); this.teams.add(team); return new AbstractMap.SimpleEntry(team, result); }
From source file:com.sky8the2flies.KOTH.util.board.SkyEntry.java
private void create(String name) { this.name = name; remove();//from ww w. j a v a 2 s. co m if (name.length() <= 16) { int value = getValue(); score = skyboard.getObjective().getScore(name); score.setScore(value); return; } team = skyboard.getScoreboard().registerNewTeam("skyboard-" + skyboard.getTeamId()); Iterator<String> iterator = Splitter.fixedLength(16).split(name).iterator(); if (name.length() > 16) team.setPrefix(iterator.next()); String entry = iterator.next(); score = skyboard.getObjective().getScore(entry); if (name.length() > 32) team.setSuffix(iterator.next()); team.addEntry(entry); }
From source file:com.exorath.exoHUD.libs.scoreboard.ScoreboardEntry.java
private void create(String name) { this.name = name; remove();/*from w w w . j a v a 2s . c om*/ if (name.length() <= 16) { int value = getValue(); score = scoreboard.getObjective().getScore(name); score.setScore(value); return; } team = scoreboard.getScoreboard().registerNewTeam("scoreboard-" + scoreboard.getTeamId()); Iterator<String> iterator = Splitter.fixedLength(16).split(name).iterator(); if (name.length() > 16) team.setPrefix(iterator.next()); String entry = iterator.next(); score = scoreboard.getObjective().getScore(entry); if (name.length() > 32) team.setSuffix(iterator.next()); team.addEntry(entry); }
From source file:fi.johannes.kata.ocr.cells.CellRow.java
/** * Reads from list of lines//from w w w. ja v a 2s . c o m * * @param ls * @return */ private List<Cell> readFromList(List<String> ls) { List<Cell> tCell = new ArrayList<>(); Splitter rowSplitter; if (cellsOnRow != -1) { rowSplitter = Splitter.fixedLength(cellsOnRow * celllength); } else { rowSplitter = Splitter.fixedLength(ls.get(0).length()); } Splitter cellSplitter = Splitter.fixedLength(celllength); ; for (String line : ls) { String fixedWidthLine = rowSplitter.splitToList(line).get(0); List<String> parts = cellSplitter.splitToList(fixedWidthLine); for (int i = 0; i < parts.size(); i++) { // if cell doesn't exist yet create try { tCell.get(i).append(parts.get(i)); } catch (IndexOutOfBoundsException e) { Cell newCell = new Cell(); newCell.append(parts.get(i)); tCell.add(i, newCell); } } // otherwise append } return tCell; }
From source file:com.evilco.license.server.encoder.CompressedLicenseEncoder.java
/** * {@inheritDoc}//from www .j av a2s . c om */ @Override public String encode(@Nonnull ILicense license) throws LicenseEncoderException { // define streams ByteArrayOutputStream outputStream = null; GZIPOutputStream gzipOutputStream = null; DataOutputStream dataOutputStream = null; // encode data try { // create stream instances outputStream = new ByteArrayOutputStream(); gzipOutputStream = new GZIPOutputStream(outputStream); dataOutputStream = new DataOutputStream(gzipOutputStream); // encode data this.childEncoder.encode(license, dataOutputStream); // flush buffers gzipOutputStream.flush(); outputStream.flush(); } catch (IOException ex) { throw new LicenseEncoderException(ex); } finally { IOUtils.closeQuietly(dataOutputStream); IOUtils.closeQuietly(gzipOutputStream); IOUtils.closeQuietly(outputStream); } // Encode Base64 String licenseText = BaseEncoding.base64().encode(outputStream.toByteArray()); // split text into chunks Joiner joiner = Joiner.on("\n").skipNulls(); return joiner.join(Splitter.fixedLength(LICENSE_CHUNK_WIDTH).split(licenseText)); }
From source file:org.opendaylight.protocol.bgp.evpn.impl.attributes.tunnel.identifier.OpaqueUtil.java
private static HexString buildOpaqueValue(final ByteBuf buffer) { final int length = buffer.readUnsignedShort(); final byte[] value = ByteArray.readBytes(buffer, length); final String hexDump = ByteBufUtil.hexDump(value); final Iterable<String> splitted = Splitter.fixedLength(2).split(hexDump); return new HexString(Joiner.on(SEPARATOR).join(splitted)); }
From source file:org.knight.examples.guava.strings.StringsExamples.java
private void split() { //result is ["foo ", " bar ", "", ""] String s3 = "foo , bar ,,"; Iterable<String> it1 = Splitter.on(',').split(s3); StringBuilder sb1 = new StringBuilder(); sb1.append("s3 split size=" + Iterables.size(it1)); sb1.append("||"); for (String s : it1) { sb1.append(s);/*from w ww. jav a 2 s . co m*/ sb1.append("||"); } log(sb1.toString()); //result is ["hello", "java,guava", "world"] String s4 = "hello; java,guava ; world;"; //if no omitEmptyStrings(), the result is ["hello", "java,guava", "world", ""] List<String> list = Splitter.on(';').trimResults().omitEmptyStrings().splitToList(s4); log("split list size=" + list.size() + ": " + list.toString()); String s5 = "guava,learning,best;foo"; //split by fixed length Iterable<String> it2 = Splitter.fixedLength(5).split(s5); StringBuilder sb2 = new StringBuilder(); sb2.append("s5 split size=" + Iterables.size(it2)); sb2.append("||"); for (String s : it2) { sb2.append(s); sb2.append("||"); } log(it2.toString()); Iterable<String> it3 = Splitter.on(',').limit(2).omitEmptyStrings().split(s5); StringBuilder sb3 = new StringBuilder(); sb3.append("s5 limit split size=" + Iterables.size(it3)); sb3.append("||"); for (String s : it3) { sb3.append(s); sb3.append("||"); } log("s5 limit size=" + Iterables.size(it3) + ": " + it3.toString()); }
From source file:org.slf4j.impl.CloudLogger.java
private Iterable<String> getChunks(String text) { return Splitter.fixedLength(MAX_LOG_SIZE_IN_CHARS).omitEmptyStrings().split(text); }
From source file:org.eclipse.hawkbit.artifact.repository.ArtifactFilesystemRepository.java
private Path getSha1DirectoryPath(final String tenant, final String sha1) { final int length = sha1.length(); final List<String> folders = Splitter.fixedLength(2).splitToList(sha1.substring(length - 4, length)); final String folder1 = folders.get(0); final String folder2 = folders.get(1); return Paths.get(artifactResourceProperties.getPath(), sanitizeTenant(tenant), folder1, folder2); }