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

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

Introduction

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

Prototype

public static String chomp(final String str) 

Source Link

Document

Removes one newline from end of a String if it's there, otherwise leave it alone.

Usage

From source file:ubic.gemma.core.loader.entrez.pubmed.PubMedSearch.java

/**
 * Search based on terms/*from ww  w .  j a v  a  2  s . c  om*/
 *
 * @param  searchTerms                  search terms
 * @return                              BibliographicReference representing the publication
 * @throws IOException                  IO problems
 * @throws SAXException                 sax exception
 * @throws ParserConfigurationException parser config exception
 */
public Collection<BibliographicReference> searchAndRetrieveByHTTP(Collection<String> searchTerms)
        throws IOException, SAXException, ParserConfigurationException {
    StringBuilder builder = new StringBuilder();
    builder.append(uri);
    builder.append("&term=");
    for (String string : searchTerms) {
        builder.append(string);
        builder.append("+");
    }
    URL toBeGotten = new URL(StringUtils.chomp(builder.toString()));
    log.info("Fetching " + toBeGotten);

    ESearchXMLParser parser = new ESearchXMLParser();
    Collection<String> ids = null;
    int numTries = 0;
    while (ids == null && numTries < MAX_TRIES) {
        try {
            numTries++;
            ids = parser.parse(toBeGotten.openStream());
        } catch (IOException e) {
            if (numTries == MAX_TRIES)
                throw e;
            log.warn("Failed attempt (" + numTries + "/" + MAX_TRIES + ") " + e.getMessage());
            try {
                // be nice
                Thread.sleep(200);
            } catch (InterruptedException e1) {
            }
        }
    }

    Collection<BibliographicReference> results = fetchById(ids);

    log.info("Fetched " + results.size() + " references");

    return results;
}

From source file:ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher.java

public Collection<BibliographicReference> retrieveByHTTP(Collection<Integer> pubMedIds) throws IOException {
    StringBuilder buf = new StringBuilder();
    for (Integer integer : pubMedIds) {
        buf.append(integer).append(",");
    }//w  w w.j  av a2s  . c om
    URL toBeGotten = new URL(uri + StringUtils.chomp(buf.toString()));
    log.debug("Fetching " + toBeGotten);
    PubMedXMLParser pmxp = new PubMedXMLParser();
    return pmxp.parse(toBeGotten.openStream());
}