List of usage examples for com.google.common.base Splitter on
@CheckReturnValue @GwtIncompatible("java.util.regex") public static Splitter on(final Pattern separatorPattern)
From source file:google.registry.tmch.SmdrlCsvParser.java
/** Converts the lines from the DNL CSV file into a data structure. */ public static SignedMarkRevocationList parse(List<String> lines) { ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>(); // First line: <version>,<SMD Revocation List creation datetime> List<String> firstLine = Splitter.on(',').splitToList(lines.get(0)); checkArgument(firstLine.size() == 2, String.format("Line 1: Expected 2 elements, found %d", firstLine.size())); Integer version = Integer.valueOf(firstLine.get(0)); checkArgument(version == 1, String.format("Line 1: Expected version 1, found %d", version)); DateTime creationTime = DateTime.parse(firstLine.get(1)).withZone(UTC); // Second line contains headers: smd-id,insertion-datetime List<String> secondLine = Splitter.on(',').splitToList(lines.get(1)); checkArgument(secondLine.size() == 2, String.format("Line 2: Expected 2 elements, found %d", secondLine.size())); checkArgument("smd-id".equals(secondLine.get(0)), String.format("Line 2: Expected header \"smd-id\", found \"%s\"", secondLine.get(0))); checkArgument("insertion-datetime".equals(secondLine.get(1)), String.format("Line 2: Expected header \"insertion-datetime\", found \"%s\"", secondLine.get(1))); // Subsequent lines: <smd-id>,<revoked SMD datetime> for (int i = 2; i < lines.size(); i++) { List<String> currentLine = Splitter.on(',').splitToList(lines.get(i)); checkArgument(currentLine.size() == 2, String.format("Line %d: Expected 2 elements, found %d", i + 1, currentLine.size())); String smdId = currentLine.get(0); DateTime revokedTime = DateTime.parse(currentLine.get(1)); revokes.put(smdId, revokedTime); }/*from w ww .j a v a 2 s. c o m*/ return SignedMarkRevocationList.create(creationTime, revokes.build()); }
From source file:org.apache.phoenix.hive.util.ColumnMappingUtils.java
public static Map<String, String> getColumnMappingMap(String columnMappings) { if (LOG.isDebugEnabled()) { LOG.debug("Column mappings : " + columnMappings); }/* w w w . j a va 2s . c o m*/ if (columnMappings == null || columnMappings.length() == 0) { if (LOG.isInfoEnabled()) { LOG.info("phoenix.column.mapping not set. using field definition"); } return Collections.emptyMap(); } Map<String, String> columnMappingMap = Splitter.on(PhoenixStorageHandlerConstants.COMMA).trimResults() .withKeyValueSeparator(PhoenixStorageHandlerConstants.COLON).split(columnMappings); if (LOG.isDebugEnabled()) { LOG.debug("Column mapping map : " + columnMappingMap); } return columnMappingMap; }
From source file:org.jclouds.docker.compute.features.internal.Archives.java
public static File tar(File baseDir, String archivePath) throws IOException { // Check that the directory is a directory, and get its contents checkArgument(baseDir.isDirectory(), "%s is not a directory", baseDir); File[] files = baseDir.listFiles(); File tarFile = new File(archivePath); String token = getLast(Splitter.on("/").split(archivePath.substring(0, archivePath.lastIndexOf("/")))); byte[] buf = new byte[1024]; int len;// ww w . j a v a 2s.co m TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile)); tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (File file : files) { TarArchiveEntry tarEntry = new TarArchiveEntry(file); tarEntry.setName("/" + getLast(Splitter.on(token).split(file.toString()))); tos.putArchiveEntry(tarEntry); if (!file.isDirectory()) { FileInputStream fin = new FileInputStream(file); BufferedInputStream in = new BufferedInputStream(fin); while ((len = in.read(buf)) != -1) { tos.write(buf, 0, len); } in.close(); } tos.closeArchiveEntry(); } tos.close(); return tarFile; }
From source file:com.palantir.typescript.services.language.ScriptElementKindModifier.java
public static ImmutableList<ScriptElementKindModifier> parseList(String kindModifiers) { ImmutableList.Builder<ScriptElementKindModifier> kindModifiersBuilder = ImmutableList.builder(); if (kindModifiers.length() > 0) { for (String kindModifier : Splitter.on(',').split(kindModifiers)) { kindModifiersBuilder.add(fromString(kindModifier)); }//from w w w . ja v a2 s .c o m } return kindModifiersBuilder.build(); }
From source file:org.apache.james.utils.SMTPSendingException.java
private static String sanitizeString(String lastServerMessage) { List<String> lines = Splitter.on("\r\n").trimResults().omitEmptyStrings().splitToList(lastServerMessage); return Joiner.on("\n").skipNulls().join(lines); }
From source file:com.ebay.pulsar.analytics.datasource.loader.DynamicDataSourceConfigurationManager.java
public static void activateDataSource(DBDataSource datasource) { String databaseName = datasource.getName(); String endPoints = datasource.getEndpoint(); DataSourceTypeEnum dataSourceTypeEnum = DataSourceTypeEnum.fromType(datasource.getType()); if (dataSourceTypeEnum == null) { throw new DataSourceConfigurationException("Unsupported dataSourceType:" + datasource.getType()); }/*from ww w . j a v a 2 s. c o m*/ DataSourceConfiguration configuration = new DataSourceConfiguration(dataSourceTypeEnum, databaseName); Properties clientProperties = datasource.getClientProperties(Properties.class); if (clientProperties != null) { configuration.setProperties(clientProperties); } configuration.setEndPoint(Lists.newArrayList(Splitter.on(',').trimResults().split(endPoints))); long refreshTime = getDBRefreshTime(datasource); configuration.setRefreshTime(refreshTime); DataSourceMetaRepo.getInstance().addDbConf(databaseName, configuration); DataSourceMetaRepo.getInstance().getDBMetaFromCache(databaseName); }
From source file:eu.artist.reusevol.repo.common.util.ArtefactId.java
public static ArtefactId of(String fullId) { PackageName pack;/* w w w. ja v a 2 s . c o m*/ ArtefactName prj; Version v; Iterator<String> segments = Splitter.on("!").split(fullId).iterator(); if (segments.hasNext()) { pack = PackageName.of(segments.next()); } else { throw new IllegalArgumentException("Invalid or missing package id in '" + fullId + "'."); } if (segments.hasNext()) { prj = ArtefactName.of(segments.next()); } else { throw new IllegalArgumentException("Invalid or missing artefactPart id in '" + fullId + "'."); } if (segments.hasNext()) { v = Version.of(segments.next()); } else { return ArtefactId.of(pack, prj); } return ArtefactId.of(pack, prj, v); }
From source file:org.sonar.server.util.RubyUtils.java
@CheckForNull public static List<String> toStrings(@Nullable Object o) { List<String> result = null; if (o != null) { if (o instanceof List) { // assume that it contains only strings result = (List) o;//from ww w . j ava 2 s .co m } else if (o instanceof CharSequence) { result = Lists.newArrayList(Splitter.on(',').omitEmptyStrings().split((CharSequence) o)); } } return result; }
From source file:com.google.javascript.jscomp.newtypes.QualifiedName.java
public static QualifiedName fromNode(Node qnameNode) { if (qnameNode == null || !qnameNode.isQualifiedName()) { return null; }//from ww w . j ava 2 s. com return qnameNode.isName() ? new QualifiedName(qnameNode.getString()) : new QualifiedName(ImmutableList.copyOf(Splitter.on('.').split(qnameNode.getQualifiedName()))); }
From source file:google.registry.tmch.ClaimsListParser.java
/** * Converts the lines from the DNL CSV file into a {@link ClaimsListShard} object. * * <p>Please note that this does <b>not</b> insert the object into the datastore. *///from w w w . ja va 2s. c o m public static ClaimsListShard parse(List<String> lines) { ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>(); // First line: <version>,<DNL List creation datetime> List<String> firstLine = Splitter.on(',').splitToList(lines.get(0)); checkArgument(firstLine.size() == 2, String.format("Line 1: Expected 2 elements, found %d", firstLine.size())); Integer version = Integer.valueOf(firstLine.get(0)); DateTime creationTime = DateTime.parse(firstLine.get(1)); checkArgument(version == 1, String.format("Line 1: Expected version 1, found %d", version)); // Second line contains headers: DNL,lookup-key,insertion-datetime List<String> secondLine = Splitter.on(',').splitToList(lines.get(1)); checkArgument(secondLine.size() == 3, String.format("Line 2: Expected 3 elements, found %d", secondLine.size())); checkArgument("DNL".equals(secondLine.get(0)), String.format("Line 2: Expected header \"DNL\", found \"%s\"", secondLine.get(0))); checkArgument("lookup-key".equals(secondLine.get(1)), String.format("Line 2: Expected header \"lookup-key\", found \"%s\"", secondLine.get(1))); checkArgument("insertion-datetime".equals(secondLine.get(2)), String.format("Line 2: Expected header \"insertion-datetime\", found \"%s\"", secondLine.get(2))); // Subsequent lines: <DNL>,<lookup key>,<DNL insertion datetime> for (int i = 2; i < lines.size(); i++) { List<String> currentLine = Splitter.on(',').splitToList(lines.get(i)); checkArgument(currentLine.size() == 3, String.format("Line %d: Expected 3 elements, found %d", i + 1, currentLine.size())); String label = currentLine.get(0); String lookupKey = currentLine.get(1); DateTime.parse(currentLine.get(2)); // This is the insertion time, currently unused. builder.put(label, lookupKey); } return ClaimsListShard.create(creationTime, builder.build()); }