use of java.util.ArrayList in project camel by apache.
the class ElasticsearchComponent method parseTransportAddresses.
private List<InetSocketTransportAddress> parseTransportAddresses(String ipsString, ElasticsearchConfiguration config) throws UnknownHostException {
if (ipsString == null || ipsString.isEmpty()) {
return null;
}
List<String> addressesStr = Arrays.asList(ipsString.split(ElasticsearchConstants.TRANSPORT_ADDRESSES_SEPARATOR_REGEX));
List<InetSocketTransportAddress> addressesTrAd = new ArrayList<InetSocketTransportAddress>(addressesStr.size());
for (String address : addressesStr) {
String[] split = address.split(ElasticsearchConstants.IP_PORT_SEPARATOR_REGEX);
String hostname;
if (split.length > 0) {
hostname = split[0];
} else {
throw new IllegalArgumentException();
}
Integer port = split.length > 1 ? Integer.parseInt(split[1]) : ElasticsearchConstants.DEFAULT_PORT;
addressesTrAd.add(new InetSocketTransportAddress(InetAddress.getByName(hostname), port));
}
return addressesTrAd;
}
use of java.util.ArrayList in project camel by apache.
the class ExecParseUtils method splitToWhiteSpaceSeparatedTokens.
/**
* Splits the input line string by {@link #WHITESPACE}. Supports quoting the
* white-spaces with a {@link #QUOTE_CHAR}. A quote itself can also be
* enclosed within #{@link #QUOTE_CHAR}#{@link #QUOTE_CHAR}. More than two
* double-quotes in a sequence is not allowed. Nested quotes are not
* allowed.<br>
* E.g. The string
* <code>"arg 1" arg2<code> will return the tokens <code>arg 1</code>,
* <code>arg2</code><br>
* The string
* <code>""arg 1"" "arg2" arg 3<code> will return the tokens <code>"arg 1"</code>
* , <code>arg2</code>,<code>arg</code> and <code>3</code> <br>
*
* @param input the input to split.
* @return a not-null list of tokens
*/
public static List<String> splitToWhiteSpaceSeparatedTokens(String input) {
if (input == null) {
return new ArrayList<String>();
}
StringTokenizer tokenizer = new StringTokenizer(input.trim(), QUOTE_CHAR + WHITESPACE, true);
List<String> tokens = new ArrayList<String>();
StringBuilder quotedText = new StringBuilder();
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (QUOTE_CHAR.equals(token)) {
// if we have a quote, add the next tokens to the quoted text
// until the quoting has finished
quotedText.append(QUOTE_CHAR);
String buffer = quotedText.toString();
if (isSingleQuoted(buffer) || isDoubleQuoted(buffer)) {
tokens.add(buffer.substring(1, buffer.length() - 1));
quotedText = new StringBuilder();
}
} else if (WHITESPACE.equals(token)) {
// skip it
if (quotedText.length() > 0) {
quotedText.append(WHITESPACE);
}
} else {
if (quotedText.length() > 0) {
quotedText.append(token);
} else {
tokens.add(token);
}
}
}
if (quotedText.length() > 0) {
throw new IllegalArgumentException("Invalid quoting found in args " + quotedText);
}
return tokens;
}
use of java.util.ArrayList in project camel by apache.
the class SftpOperations method listFiles.
public synchronized List<ChannelSftp.LsEntry> listFiles(String path) throws GenericFileOperationFailedException {
LOG.trace("listFiles({})", path);
if (ObjectHelper.isEmpty(path)) {
// list current directory if file path is not given
path = ".";
}
try {
final List<ChannelSftp.LsEntry> list = new ArrayList<ChannelSftp.LsEntry>();
@SuppressWarnings("rawtypes") Vector files = channel.ls(path);
// can return either null or an empty list depending on FTP servers
if (files != null) {
for (Object file : files) {
list.add((ChannelSftp.LsEntry) file);
}
}
return list;
} catch (SftpException e) {
throw new GenericFileOperationFailedException("Cannot list directory: " + path, e);
}
}
use of java.util.ArrayList in project camel by apache.
the class FlatpackFixedLengthDataFormatTest method testMarshalWithDefinition.
@Test
public void testMarshalWithDefinition() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:marshal");
// by default we get on big message
mock.expectedMessageCount(1);
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
Map<String, Object> row = new LinkedHashMap<String, Object>();
row.put("FIRSTNAME", "JOHN");
row.put("LASTNAME", "DOE");
row.put("ADDRESS", "1234 CIRCLE CT");
row.put("CITY", "ELYRIA");
row.put("STATE", "OH");
row.put("ZIP", "44035");
data.add(row);
template.sendBody("direct:marshal", data);
assertMockEndpointsSatisfied();
String s = mock.getExchanges().get(0).getIn().getBody(String.class);
assertTrue(s.startsWith("JOHN DOE"));
}
use of java.util.ArrayList in project camel by apache.
the class FlatpackDelimitedDataFormatTest method testMarshalWithDefinition.
@Test
public void testMarshalWithDefinition() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:marshal");
// by default we get on big message
mock.expectedMessageCount(1);
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
Map<String, Object> row = new LinkedHashMap<String, Object>();
row.put("ITEM_DESC", "SOME VALVE");
row.put("IN_STOCK", "2");
row.put("PRICE", "5.00");
row.put("LAST_RECV_DT", "20050101");
data.add(row);
Map<String, Object> row2 = new LinkedHashMap<String, Object>();
row2.put("ITEM_DESC", "AN ENGINE");
row2.put("IN_STOCK", "100");
row2.put("PRICE", "1000.00");
row2.put("LAST_RECV_DT", "20040601");
data.add(row2);
template.sendBody("direct:marshal", data);
assertMockEndpointsSatisfied();
}
Aggregations