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

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

Introduction

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

Prototype

public static String stripToNull(String str) 

Source Link

Document

Strips whitespace from the start and end of a String returning null if the String is empty ("") after the strip.

This is similar to #trimToNull(String) but removes whitespace.

Usage

From source file:com.thoughtworks.go.server.service.BackupService.java

private String postBackupScriptFile() {
    BackupConfig backupConfig = backupConfig();
    if (backupConfig != null) {
        String postBackupScript = backupConfig.getPostBackupScript();
        return StringUtils.stripToNull(postBackupScript);
    }//w  w  w  . java2s . c o m
    return null;
}

From source file:org.ala.hbase.ANBGDataLoader.java

/**
 * Load the publications for each concept.
 * /*from  w ww  .j av a 2 s.  c  om*/
 * @throws Exception
 */
private void loadPublicationsFile(String file) throws Exception {
    logger.info("Starting to load taxon publications");

    CSVReader reader = new CSVReader(new FileReader(file), ',', '"', '\\', 1);//Reader reader, char separator, char quotechar, char escape, int line
    LoadUtils loadUtils = new LoadUtils();
    String[] record = null;
    int i = 0;
    int j = 0;
    while ((record = reader.readNext()) != null) {
        i++;
        if (record.length < 10) {
            logger.warn("truncated at line " + i + " record: " + record);
            continue;
        }

        List<String> taxonConceptIds = loadUtils.getGuidsForPublicationGuid(record[0], 100);
        java.util.Set<String> preferredLsids = new java.util.HashSet<String>();

        Publication p = new Publication();
        p.setGuid(record[0]);
        p.setTitle(record[2]);
        //p.setAuthor(record[2]);
        p.setDatePublished(StringUtils.stripToNull(record[4]));
        p.setCitation(StringUtils.stripToNull(record[5]));
        p.setYear(StringUtils.stripToNull(record[3]));
        p.setPublisher(StringUtils.stripToNull(record[9]));
        p.setContainedInGuid(StringUtils.stripToNull(record[6]));
        p.setEdition(StringUtils.stripToNull(record[7]));
        //p.setPublicationType(record[4]);

        //add this taxon name to each taxon concept
        for (String tcId : taxonConceptIds) {
            String preferredGuid = loadUtils.getPreferredGuid(tcId);
            if (!preferredLsids.contains(preferredGuid)) {
                logger.debug("Adding publication to " + tcId + " record: " + p.getGuid());
                if (isValidToLoad(loadUtils, preferredGuid)) {
                    boolean success = taxonConceptDao.addPublication(preferredGuid, p);

                    if (success)
                        j++;
                }
                preferredLsids.add(preferredGuid);
            }

        }
    }
    logger.info(i + " lines read. " + j + " publications added to concept records.");
}

From source file:org.apache.marmotta.platform.core.services.config.DependenciesServiceImpl.java

@PostConstruct
public void populate() {
    InputStream deps;/* ww w.j av  a 2  s.c o  m*/

    // first try to get webapp dependencies
    deps = Thread.currentThread().getContextClassLoader().getResourceAsStream(DependenciesService.PATH);
    if (deps == null) {
        // fallback to the core dependencies only
        log.warn("Dependencies not found at the webapp, so falling back to core dependencies...");
        deps = DependenciesServiceImpl.class.getResourceAsStream(DependenciesService.PATH);
    }
    if (deps == null) {
        log.error("No suitable '{}' file found", DependenciesService.PATH);
    } else {
        DataInputStream in = new DataInputStream(deps);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String line;
        try {

            // first two line generated by maven are not actually dependencies,
            // anyway this code could be really buggy
            br.readLine();
            br.readLine();

            while ((line = br.readLine()) != null) {
                line = StringUtils.stripToNull(line);
                if (line != null) {
                    Map<String, String> dep = new HashMap<String, String>();
                    String[] split = StringUtils.split(line, ":");
                    if (split.length >= 4) {
                        dep.put(DependenciesService.GROUP, split[0]);
                        dep.put(DependenciesService.ARTIFACT, split[1]);
                        dep.put(DependenciesService.VERSION, split[3]);
                        this.dependencies.add(dep);
                        log.debug("Recovered dependency " + split[0] + ":" + split[2] + ":" + split[2]);
                    }
                }
            }

            br.close();

        } catch (IOException e) {
            log.error("Error reading dependencies: " + e.getMessage());
        } catch (NullPointerException e) {
            log.error("Error reading dependencies: " + e.getMessage());
        }
    }
}

From source file:org.apache.samza.operators.descriptors.base.system.SystemDescriptor.java

/**
 * Constructs a {@link SystemDescriptor} instance.
 *
 * @param systemName name of this system
 * @param factoryClassName name of the SystemFactory class for this system
 * @param transformer the {@link InputTransformer} for the system if any, else null
 * @param expander the {@link StreamExpander} for the system if any, else null
 */// w  ww  .  j  a va2  s. c o m
public SystemDescriptor(String systemName, String factoryClassName, InputTransformer transformer,
        StreamExpander expander) {
    Preconditions.checkArgument(isValidSystemName(systemName), String.format(
            "systemName: %s must be non-empty and must not contain spaces or special characters.", systemName));
    if (StringUtils.isBlank(factoryClassName)) {
        LOGGER.warn(
                "Blank SystemFactory class name for system: {}. A value must be provided in configuration using {}.",
                systemName, String.format(FACTORY_CONFIG_KEY, systemName));
    }
    this.systemName = systemName;
    this.factoryClassNameOptional = Optional.ofNullable(StringUtils.stripToNull(factoryClassName));
    this.transformerOptional = Optional.ofNullable(transformer);
    this.expanderOptional = Optional.ofNullable(expander);
}

From source file:org.apache.samza.system.eventhub.descriptors.EventHubsInputDescriptor.java

/**
 * Constructs an {@link InputDescriptor} instance.
 *
 * @param streamId id of the stream//from w  w w .java  2  s.  c om
 * @param namespace namespace for the Event Hubs entity to consume from, not null
 * @param entityPath entity path for the Event Hubs entity to consume from, not null
 * @param valueSerde serde the values in the messages in the stream
 * @param systemDescriptor system descriptor this stream descriptor was obtained from
 */
EventHubsInputDescriptor(String streamId, String namespace, String entityPath, Serde valueSerde,
        SystemDescriptor systemDescriptor) {
    super(streamId, KVSerde.of(new NoOpSerde<>(), valueSerde), systemDescriptor, null);
    this.namespace = StringUtils.stripToNull(namespace);
    this.entityPath = StringUtils.stripToNull(entityPath);
    if (this.namespace == null || this.entityPath == null) {
        throw new ConfigException(
                String.format("Missing namespace and entity path Event Hubs input descriptor in " //
                        + "system: {%s}, stream: {%s}", getSystemName(), streamId));
    }
}

From source file:org.apache.samza.system.eventhub.descriptors.EventHubsInputDescriptor.java

/**
 * SAS Key name of the associated input stream. Required to access the input Event Hubs entity per stream.
 *
 * @param sasKeyName the name of the SAS key required to access the Event Hubs entity
 * @return this input descriptor/*ww w  .  j  a  v  a2s  . co m*/
 */
public EventHubsInputDescriptor<StreamMessageType> withSasKeyName(String sasKeyName) {
    this.sasKeyName = Optional.ofNullable(StringUtils.stripToNull(sasKeyName));
    return this;
}

From source file:org.apache.samza.system.eventhub.descriptors.EventHubsInputDescriptor.java

/**
 * SAS Token of the associated input stream. Required to access the input Event Hubs per stream.
 *
 * @param sasToken the SAS token required to access the Event Hubs entity
 * @return this input descriptor/*  w w w  .  j a va2s.  c  o m*/
 */
public EventHubsInputDescriptor<StreamMessageType> withSasKey(String sasToken) {
    this.sasToken = Optional.ofNullable(StringUtils.stripToNull(sasToken));
    return this;
}

From source file:org.apache.samza.system.eventhub.descriptors.EventHubsInputDescriptor.java

/**
 * Set the consumer group from the upstream Event Hubs entity that the consumer is part of. Defaults to the
 * <code>$Default</code> group that is initially present in all Event Hubs entities (unless removed)
 *
 * @param consumerGroup the name of the consumer group upstream
 * @return this input descriptor//from   w  w w  .  ja va  2 s.  c  o  m
 */
public EventHubsInputDescriptor<StreamMessageType> withConsumerGroup(String consumerGroup) {
    this.consumerGroup = Optional.ofNullable(StringUtils.stripToNull(consumerGroup));
    return this;
}

From source file:org.apache.samza.system.eventhub.descriptors.EventHubsOutputDescriptor.java

/**
 * Constructs an {@link OutputDescriptor} instance.
 *
 * @param streamId id of the stream//w w w .  j a v a  2s  . c om
 * @param namespace namespace for the Event Hubs entity to produce to, not null
 * @param entityPath entity path for the Event Hubs entity to produce to, not null
 * @param valueSerde serde the values in the messages in the stream
 * @param systemDescriptor system descriptor this stream descriptor was obtained from
 */
EventHubsOutputDescriptor(String streamId, String namespace, String entityPath, Serde valueSerde,
        SystemDescriptor systemDescriptor) {
    super(streamId, KVSerde.of(new NoOpSerde<>(), valueSerde), systemDescriptor);
    this.namespace = StringUtils.stripToNull(namespace);
    this.entityPath = StringUtils.stripToNull(entityPath);
    if (this.namespace == null || this.entityPath == null) {
        throw new ConfigException(
                String.format("Missing namespace and entity path Event Hubs output descriptor in "
                        + "system: {%s}, stream: {%s}", getSystemName(), streamId));
    }
}

From source file:org.apache.samza.system.eventhub.descriptors.EventHubsOutputDescriptor.java

/**
 * SAS Key name of the associated output stream. Required to access the output Event Hubs entity per stream.
 *
 * @param sasKeyName the name of the SAS key required to access the Event Hubs entity
 * @return this output descriptor/*from   w  ww  . j a  v a2s .  c  o  m*/
 */
public EventHubsOutputDescriptor<StreamMessageType> withSasKeyName(String sasKeyName) {
    this.sasKeyName = Optional.ofNullable(StringUtils.stripToNull(sasKeyName));
    return this;
}