Example usage for org.apache.commons.lang3 StringUtils splitPreserveAllTokens

List of usage examples for org.apache.commons.lang3 StringUtils splitPreserveAllTokens

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils splitPreserveAllTokens.

Prototype

public static String[] splitPreserveAllTokens(final String str, final String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

Usage

From source file:com.khartec.waltz.jobs.sample.OrgUnitGenerator.java

public static void main(String[] args) throws IOException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/org-units.csv"));

    System.out.println("Deleting existing OU's");
    dsl.deleteFrom(ORGANISATIONAL_UNIT).execute();

    List<OrganisationalUnitRecord> records = lines.stream().skip(1)
            .map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> cells.length == 4)
            .map(cells -> {//from   w w  w. j  ava  2  s .c  om
                OrganisationalUnitRecord record = new OrganisationalUnitRecord();
                record.setId(longVal(cells[0]));
                record.setParentId(longVal(cells[1]));
                record.setName(cells[2]);
                record.setDescription(cells[3]);
                record.setUpdatedAt(new Timestamp(System.currentTimeMillis()));

                System.out.println(record);
                return record;
            }).collect(Collectors.toList());

    System.out.println("Inserting new OU's");
    dsl.batchInsert(records).execute();

    System.out.println("Done");

}

From source file:be.dnsbelgium.core.DomainName.java

public static DomainName of(String domainName) {
    String[] labels = StringUtils.splitPreserveAllTokens(domainName, '.');
    ImmutableList.Builder<Label> builder = new ImmutableList.Builder<Label>();
    for (String label : labels) {
        builder.add(Label.of(label));
    }/*from   ww  w  .  java  2s.c  o m*/
    return new DomainName(builder.build());
}

From source file:cc.pinel.mangue.util.MangaSearch.java

/**
 * Searches mangas remotely using the query.
 * /*from   w w  w  .j a  v a2  s  . c  o  m*/
 * @param query the query to be searched
 * @return the list of mangas filtered
 * @throws MalformedURLException
 * @throws IOException
 */
public static Collection search(String query) throws MalformedURLException, IOException {
    Collection mangas = new ArrayList();

    InputStream is = new URL("http://www.mangapanda.com/actions/search/?q=" + query + "&limit=20").openStream();

    String lines[] = StringUtils.split(IOUtils.toString(is), '\n');

    for (int i = 0, length = lines.length; i < length && i < 20; i++) {
        String tokens[] = StringUtils.splitPreserveAllTokens(lines[i], '|');

        if (tokens.length >= MIN_TOKEN_LENGHT)
            mangas.add(new Manga(tokens[5], tokens[2], convertOldPath(tokens[4])));
    }

    return mangas;
}

From source file:com.daraf.projectdarafprotocol.clienteapp.ingresos.IngresoClienteRQ.java

@Override
public void build(String input) {

    if (validate(input)) {
        try {/*from   ww  w.  j  ava 2  s . c o  m*/
            String values[] = StringUtils.splitPreserveAllTokens(input, Cuerpo.FIELD_SEPARATOR_CHAR);
            this.cliente = new Cliente();
            this.cliente.setIdentificacion(values[0]);
            this.cliente.setNombre(values[1]);
            this.cliente.setTelefono(values[2]);
            this.cliente.setDireccion(values[3]);
        } catch (Exception e) {
            System.out.println(" " + e);
        }
    }
}

From source file:com.daraf.projectdarafprotocol.appdb.ingresos.IngresoClienteRQ.java

@Override
public void build(String input) {
    if (validate(input)) {
        try {/*from w  w w .j  a  v a2s  . com*/
            this.cliente = new Cliente();
            String values[] = StringUtils.splitPreserveAllTokens(input, Cuerpo.FIELD_SEPARATOR_CHAR);
            this.getCliente().setIdentificacion(values[0]);
            this.getCliente().setNombre(values[1]);
            this.getCliente().setTelefono(values[2]);
            this.getCliente().setDireccion(values[3]);

        } catch (Exception e) {
            System.out.println(" " + e);
        }
    }
}

From source file:io.wcm.config.core.management.util.TypeConversion.java

/**
 * Converts a string value to an object with the given parameter type.
 * @param value String value//ww w. ja v  a2 s .  c o  m
 * @param type Parameter type
 * @return Converted value
 * @throws IllegalArgumentException If type is not supported
 */
@SuppressWarnings("unchecked")
public static <T> T stringToObject(String value, Class<T> type) {
    if (value == null) {
        return null;
    }
    if (type == String.class) {
        return (T) value;
    } else if (type == String[].class) {
        return (T) StringUtils.splitPreserveAllTokens(value, ARRAY_DELIMITER);
    }
    if (type == Integer.class) {
        return (T) (Integer) NumberUtils.toInt(value, 0);
    }
    if (type == Long.class) {
        return (T) (Long) NumberUtils.toLong(value, 0L);
    }
    if (type == Double.class) {
        return (T) (Double) NumberUtils.toDouble(value, 0d);
    }
    if (type == Boolean.class) {
        return (T) (Boolean) BooleanUtils.toBoolean(value);
    }
    if (type == Map.class) {
        String[] rows = StringUtils.splitPreserveAllTokens(value, ARRAY_DELIMITER);
        Map<String, String> map = new LinkedHashMap<>();
        for (int i = 0; i < rows.length; i++) {
            String[] keyValue = StringUtils.splitPreserveAllTokens(rows[i], KEY_VALUE_DELIMITER);
            if (keyValue.length == 2 && StringUtils.isNotEmpty(keyValue[0])) {
                map.put(keyValue[0], StringUtils.isEmpty(keyValue[1]) ? null : keyValue[1]);
            }
        }
        return (T) map;
    }
    throw new IllegalArgumentException("Unsupported type: " + type.getName());
}

From source file:ch.cyberduck.core.irods.IRODSHomeFinderService.java

@Override
public Path find() throws BackgroundException {
    final Path home = super.find();
    if (home == DEFAULT_HOME) {
        final String user;
        final Credentials credentials = session.getHost().getCredentials();
        if (StringUtils.contains(credentials.getUsername(), ':')) {
            user = StringUtils.splitPreserveAllTokens(credentials.getUsername(), ':')[1];
        } else {//  www. j a  v  a2s  .co m
            user = credentials.getUsername();
        }
        return new Path(
                new StringBuilder().append(Path.DELIMITER).append(session.getRegion()).append(Path.DELIMITER)
                        .append("home").append(Path.DELIMITER).append(user).toString(),
                EnumSet.of(Path.Type.directory, Path.Type.volume));
    }
    return home;
}

From source file:com.daraf.projectdarafprotocol.appdb.seguridades.AutenticacionEmpresaRS.java

@Override
public void build(String input) {
    if (validate(input)) {
        if (input.length() < maxLength) {
            input = StringUtils.rightPad(input, maxLength, " ");
        }/*from   w  w w .  j a  v a 2 s .  c o  m*/
        try {
            String values[] = MyStringUtil.splitByFixedLengths(input, new int[] { 1, 400 });
            this.resultado = values[0];
            if (this.resultado.equals("1")) {
                String empresaValues[] = StringUtils.splitPreserveAllTokens(values[1],
                        Cuerpo.FIELD_SEPARATOR_CHAR);
                this.empresa = new Empresa();
                this.empresa.setRuc(empresaValues[0]);
                this.empresa.setNombre(empresaValues[1]);
                this.empresa.setTelefono(empresaValues[2]);
                this.empresa.setDireccion(empresaValues[3]);
                this.empresa.setUsuario(empresaValues[4]);
                this.empresa.setPassword(empresaValues[5]);
            }
        } catch (Exception ex) {
            Logger.getLogger(AutenticacionEmpresaRS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.daraf.projectdarafprotocol.clienteapp.seguridades.AutenticacionEmpresaRS.java

@Override
public void build(String input) {
    if (validate(input)) {
        if (input.length() < 401) {
            input = StringUtils.rightPad(input, 401, " ");
        }/*from w w  w  .  j a  va 2  s  . co  m*/
        try {
            String values[] = MyStringUtil.splitByFixedLengths(input, new int[] { 1, 400 });
            this.resultado = values[0];
            if (resultado.equals("1")) {
                String empresaValues[] = StringUtils.splitPreserveAllTokens(values[1],
                        Cuerpo.FIELD_SEPARATOR_CHAR);
                this.empresa = new Empresa();
                this.empresa.setRuc(empresaValues[0]);
                this.empresa.setNombre(empresaValues[1]);
                this.empresa.setTelefono(empresaValues[2]);
                this.empresa.setDireccion(empresaValues[3]);
                this.empresa.setUsuario(empresaValues[4]);
                this.empresa.setPassword(empresaValues[5]);
            }
        } catch (Exception ex) {
            Logger.getLogger(AutenticacionEmpresaRS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.daraf.projectdarafprotocol.appdb.consultas.ConsultaClienteRS.java

@Override
public void build(String input) {
    if (validate(input)) {
        if (input.length() < 201) {
            input = StringUtils.rightPad(input, 201, " ");
        }//w ww . j  ava2  s  . c o  m
        try {
            String values[] = MyStringUtil.splitByFixedLengths(input, new int[] { 1, 200 });
            this.resultado = values[0];
            if (resultado.equals("1")) {
                String CliValues[] = StringUtils.splitPreserveAllTokens(values[1], Cuerpo.FIELD_SEPARATOR_CHAR);
                this.cliente = new Cliente();
                this.cliente.setIdentificacion(CliValues[0]);
                this.cliente.setNombre(CliValues[1]);
                this.cliente.setTelefono(CliValues[2]);
                this.cliente.setDireccion(CliValues[3]);
            }
        } catch (Exception ex) {
            Logger.getLogger(ConsultaClienteRS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}