Search in sources :

Example 26 with ArrayList

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;
}
Also used : ArrayList(java.util.ArrayList) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 27 with ArrayList

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList)

Example 28 with ArrayList

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);
    }
}
Also used : ChannelSftp(com.jcraft.jsch.ChannelSftp) GenericFileOperationFailedException(org.apache.camel.component.file.GenericFileOperationFailedException) SftpException(com.jcraft.jsch.SftpException) ArrayList(java.util.ArrayList) Vector(java.util.Vector)

Example 29 with ArrayList

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"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 30 with ArrayList

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();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611