List of usage examples for com.google.common.base Splitter fixedLength
@CheckReturnValue public static Splitter fixedLength(final int length)
From source file:com.addthis.hydra.data.filter.value.ValueFilterSplit.java
protected String[] splitFixedLength(String line, int length) { Iterable<String> splitIter = Splitter.fixedLength(length).split(line); List<String> tok = new ArrayList<>(); Iterables.addAll(tok, splitIter);// w w w .ja va2s .co m return Iterables.toArray(tok, String.class); }
From source file:co.cask.cdap.shell.command.GetStreamEventsCommand.java
/** * Creates a string representing the body in the output. It only prints up to {@link #MAX_BODY_SIZE}, with line * wrap at each {@link #LINE_WRAP_LIMIT} character. *///from ww w. j a v a2 s . c o m private String getBody(ByteBuffer body) { ByteBuffer bodySlice = body.slice(); boolean hasMore = false; if (bodySlice.remaining() > MAX_BODY_SIZE) { bodySlice.limit(MAX_BODY_SIZE); hasMore = true; } String str = Bytes.toStringBinary(bodySlice) + (hasMore ? "..." : ""); if (str.length() <= LINE_WRAP_LIMIT) { return str; } return Joiner.on(LINE_SEPARATOR).join(Splitter.fixedLength(LINE_WRAP_LIMIT).split(str)); }
From source file:com.optimaize.langdetect.profiles.util.LanguageProfileValidator.java
private List<TextObject> partition() { List<TextObject> result = new ArrayList<>(this.k); if (!breakWords) { int maxLength = this.inputSample.length() / (this.k - 1); Pattern p = Pattern.compile("\\G\\s*(.{1," + maxLength + "})(?=\\s|$)", Pattern.DOTALL); Matcher m = p.matcher(this.inputSample); while (m.find()) result.add(textObjectFactory.create().append(m.group(1))); } else {//from w ww . java 2 s . co m Splitter splitter = Splitter.fixedLength(this.k); for (String token : splitter.split(this.inputSample.toString())) { result.add(textObjectFactory.create().append(token)); } } return result; }
From source file:org.opendaylight.ovsdb.openstack.netvirt.it.SouthboundMapper.java
public static DatapathId createDatapathId(String dpid) { Preconditions.checkNotNull(dpid);//from ww w. ja v a 2 s. c o m DatapathId datapath; if (dpid.matches("^[0-9a-fA-F]{16}")) { Splitter splitter = Splitter.fixedLength(2); Joiner joiner = Joiner.on(":"); datapath = new DatapathId(joiner.join(splitter.split(dpid))); } else { datapath = new DatapathId(dpid); } return datapath; }
From source file:ru.codeinside.gses.webui.executor.ArchiveFactory.java
public static String toBase64HumanString(byte[] bytes) { return Joiner.on('\n').join(Splitter.fixedLength(64).split(DatatypeConverter.printBase64Binary(bytes))); }
From source file:ai.grakn.engine.session.GraqlSession.java
/** * Send a single query result back to the client *///www .jav a 2 s . c om private void sendQueryResult(String result) { // Split result into chunks Iterable<String> splitResult = Splitter.fixedLength(QUERY_CHUNK_SIZE).split(result + "\n"); for (String resultChunk : splitResult) { sendJson(Json.object(ACTION, ACTION_QUERY, QUERY_RESULT, resultChunk)); } }
From source file:ai.grakn.engine.session.GraqlSession.java
/** * Tell the client about an error in their query *//*from w w w . j av a2 s.c o m*/ private void sendError(String errorMessage) { // Split error into chunks Iterable<String> splitError = Splitter.fixedLength(QUERY_CHUNK_SIZE).split(errorMessage + "\n"); for (String errorChunk : splitError) { sendJson(Json.object(ACTION, ACTION_ERROR, ERROR, errorChunk)); } }
From source file:com.facebook.presto.metadata.DatabaseLocalStorageManager.java
/** * Generate a file system path for a shard id. This creates a four level deep, two digit directory * where the least significant digits are the first level, the next significant digits are the second * and so on. Numbers that have more than eight digits are lumped together in the last level. * <p/>/*from ww w . j ava 2 s. c o m*/ * <pre> * 1 --> 01/00/00/00 * 1000 -> 00/10/00/00 * 123456 -> 56/34/12/00 * 4815162342 -> 42/23/16/4815 * </pre> * <p/> * This ensures that files are spread out evenly through the tree while a path can still be easily navigated * by a human being. */ @VisibleForTesting static File getShardPath(File baseDir, long shardId) { Preconditions.checkArgument(shardId >= 0, "shardId must be >= 0"); String value = format("%08d", shardId); int split = value.length() - 6; List<String> pathElements = ImmutableList .copyOf(Splitter.fixedLength(2).limit(3).split(value.substring(split))); String path = Joiner.on('/').join(Lists.reverse(pathElements)) + "/" + value.substring(0, split); return new File(baseDir, path); }
From source file:org.grycap.gpf4med.ext.GraphConnectorManager.java
private String formatVersion(final String version) { String formatted = ""; try {//from w w w .ja va 2s.c o m // check that version is a valid integer if (Integer.parseInt(version) < 0) { throw new IllegalStateException("Version must be a positive integer"); } // parse version String release = "", major = "", minor = ""; final String reverseVersion = new StringBuffer(version).reverse().toString(); final Iterable<String> chunks = Splitter.fixedLength(2).split(reverseVersion); final Iterator<String> iterator = chunks.iterator(); int i = 0; while (iterator.hasNext()) { switch (i) { case 0: minor = Integer.valueOf(new StringBuffer(iterator.next()).reverse().toString()).toString(); break; case 1: major = Integer.valueOf(new StringBuffer(iterator.next()).reverse().toString()).toString(); break; default: release = new StringBuffer(iterator.next()).reverse().toString() + release; break; } i++; } formatted = release + "." + major + "." + minor; } catch (Exception e) { throw new IllegalStateException("Invalid version found: " + version); } return formatted; }
From source file:com.mycelium.wallet.Utils.java
/** * Chop a string into an array of strings no longer then the specified chop * length/*from w w w . ja va 2s . co m*/ */ public static String[] stringChopper(String string, int chopLength) { return Iterables.toArray(Splitter.fixedLength(chopLength).split(string), String.class); }