use of com.cinchapi.common.base.QuoteAwareStringSplitter in project concourse by cinchapi.
the class ExportCliTest method generateCliArgs.
/**
* Transform the {@code args} into a complete set arguments to use in a CLI
* test.
*
* @param args
* @return the CLI args
*/
private String[] generateCliArgs(String... args) {
args = AnyObjects.split(args, v -> new QuoteAwareStringSplitter(v, ' ', SplitOption.TRIM_WHITESPACE, SplitOption.DROP_QUOTES)).toArray(Array.containing());
ArrayBuilder<String> ab = ArrayBuilder.builder();
ab.add("--username");
ab.add("admin");
ab.add("--password");
ab.add("admin");
ab.add("--port");
ab.add(String.valueOf(server.getClientPort()));
ab.add("--file");
ab.add(output);
ab.add(args);
return ab.build();
}
use of com.cinchapi.common.base.QuoteAwareStringSplitter in project concourse by cinchapi.
the class DelimitedLineImporter method parseObject.
/**
* Transform the delimited line into an object where each field is mapped as
* a value from the analogous key in the {@link #header}. Each key/value
* mapping is subject to processing by the {@link #transformer}.
*
* @param line
* @return the parsed object
*/
protected Multimap<String, Object> parseObject(String line) {
StringSplitter it = new QuoteAwareStringSplitter(line, delimiter, SplitOption.TRIM_WHITESPACE);
Multimap<String, Object> object = LinkedHashMultimap.create();
Strainer strainer = new Strainer((key, value) -> object.put(key, value));
int col = 0;
while (it.hasNext()) {
String key = header.get(col++);
String value = it.next();
Map<String, Object> transformed = transformer.transform(key, (Object) value);
if (transformed != null) {
strainer.process(transformed);
} else {
strainer.process(key, value);
}
}
return object;
}
use of com.cinchapi.common.base.QuoteAwareStringSplitter in project concourse by cinchapi.
the class DelimitedLineImporter method parseHeader.
@Override
public final void parseHeader(String line) {
Preconditions.checkState(header.isEmpty(), "Header has been set already");
QuoteAwareStringSplitter it = new QuoteAwareStringSplitter(line, delimiter, SplitOption.TRIM_WHITESPACE);
while (it.hasNext()) {
header.add(it.next());
}
}
use of com.cinchapi.common.base.QuoteAwareStringSplitter in project concourse by cinchapi.
the class LineBasedImporter method parseLine.
/**
* Parse the data from {@code line} into a {@link JsonObject} that is
* appropriate for import. The subclass can customize the behaviour of this
* process by overriding the {@link #header()} and
* {@link #transformValue(String, String)} methods.
*
* @param line
* @param keys
* @return the line data encoded as a JsonObject
*/
private final JsonObject parseLine(String line, String... keys) {
line = line.trim();
JsonObject json = new JsonObject();
String[] toks = null;
if (useOptimizedSplitPath) {
QuoteAwareStringSplitter it = new QuoteAwareStringSplitter(line, delimiter().charAt(0));
List<String> toksList = Lists.newArrayList();
while (it.hasNext()) {
toksList.add(it.next());
}
toks = TLists.toArrayCasted(toksList, String.class);
} else {
toks = AnyStrings.splitStringByDelimiterButRespectQuotes(line, delimiter());
}
for (int i = 0; i < Math.min(keys.length, toks.length); ++i) {
if (StringUtils.isBlank(toks[i])) {
continue;
}
JsonElement value = transformValue(keys[i], toks[i]);
json.add(keys[i], value);
}
return json;
}
use of com.cinchapi.common.base.QuoteAwareStringSplitter in project concourse by cinchapi.
the class LineBasedImporter method parseKeys.
/**
* Parse the keys from the {@code line}. The delimiter can be specified by
* the subclass in the {@link #delimiter()} method.
*
* @param line
* @return an array of keys
*/
private final String[] parseKeys(String line) {
String[] keys = null;
if (useOptimizedSplitPath) {
QuoteAwareStringSplitter it = new QuoteAwareStringSplitter(line, delimiter().charAt(0));
List<String> keysList = Lists.newArrayList();
while (it.hasNext()) {
keysList.add(it.next().trim());
}
keys = TLists.toArrayCasted(keysList, String.class);
} else {
keys = AnyStrings.splitStringByDelimiterButRespectQuotes(line, delimiter());
for (int i = 0; i < keys.length; ++i) {
keys[i] = keys[i].trim();
}
}
return keys;
}
Aggregations