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

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

Introduction

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

Prototype

public static String remove(final String str, final char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

A null source string will return null .

Usage

From source file:org.pepstock.jem.node.executors.jobs.GetOutputTree.java

/**
 * Reads file system and returns the tree of job log folder.
 * /*from  www  .jav a 2s .co  m*/
 * @return output tree
 * @throws if I/O error occurs 
 */
@Override
public OutputTree execute() throws ExecutorException {
    // gets the jcl file to extract the directory
    File jclFile;
    try {
        jclFile = Main.getOutputSystem().getJclFile(job);
    } catch (IOException e) {
        // messo il job ma il node file va messo
        throw new ExecutorException(NodeMessage.JEMC242E, e, job);
    }
    // checks if file exists otherwise exception occurs
    if (!jclFile.exists()) {
        throw new ExecutorException(NodeMessage.JEMC242E, jclFile);
    }

    // creates the empty result
    OutputTree tree = new OutputTree();

    // get the folder of JCL. is folder used for job output
    File jobOutputFolder = jclFile.getParentFile();
    // lists all files 
    File[] files = jobOutputFolder.listFiles();

    Arrays.sort(files, COMPARATOR);

    // scans all files of folder and load the result tree
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        // ignores JCL file because is already inside the job and
        // due to you need this data in UI, doesn't make sense to download it
        if (!file.getName().equalsIgnoreCase(OutputSystem.JCL_FILE)
                && !file.getName().equalsIgnoreCase(OutputSystem.JOB_FILE)) {
            // if is not the directory (means not syslog of step)
            // this is the first level of folder
            if (!file.isDirectory()) {
                if (file.getName().equalsIgnoreCase(OutputSystem.JOBLOG_FILE)
                        || file.getName().equalsIgnoreCase(OutputSystem.MESSAGESLOG_FILE)) {
                    // creates the items and sets label (to show on UI) and relative path of file
                    OutputListItem item = new OutputListItem();
                    String label = (file.getName().equalsIgnoreCase(OutputSystem.JOBLOG_FILE)) ? JEM_LOG_LABEL
                            : JOB_LOG_LABEL;
                    item.setLabel(label);
                    String fileRelativePath = StringUtils.remove(file.getAbsolutePath(),
                            Main.getOutputSystem().getOutputPath().getAbsolutePath());
                    item.setFileRelativePath(FilenameUtils.normalize(fileRelativePath, true));
                    // adds to first level
                    tree.getFirstLevelItems().add(item);
                }
            } else {
                // checks the folder which represents the folder for all syslog of step
                // loads all files in second level
                List<OutputListItem> secondLevelItems = new ArrayList<OutputListItem>();
                // gets all files of folder, scanning them
                File[] stepFiles = file.listFiles();

                for (int k = 0; k < stepFiles.length; k++) {
                    File stepFile = stepFiles[k];
                    // ignores directory. it shouldn't be present directory here
                    if (!stepFile.isDirectory()) {
                        // creates the items and sets label (to show on UI) and relative path of file                     
                        OutputListItem item = new OutputListItem();
                        item.setLabel(stepFile.getName());
                        item.setParent(file.getName());
                        String fileRelativePath = StringUtils.remove(stepFile.getAbsolutePath(),
                                Main.getOutputSystem().getOutputPath().getAbsolutePath());
                        item.setFileRelativePath(FilenameUtils.normalize(fileRelativePath, true));
                        secondLevelItems.add(item);
                    }
                }
                // adds to second level
                tree.getSecondLevelItems().add(secondLevelItems);
            }
        }
    }
    return tree;
}

From source file:org.pepstock.jem.node.StatisticsManager.java

/**
 * Writes a sample on file, define to collect all node stats
 * @param sample//from   w ww.  ja  v a2 s.  co  m
 * @throws FileNotFoundException
 */
public void write(Sample sample) {
    // it writes only if enable
    if (enable) {
        try {
            // every write it calculates the date
            // to write always the sample in a file with the date in the file name (extension)
            String currentDay = DateFormatter.getCurrentDate(DateFormatter.DEFAULT_DATE_FORMAT);
            if (!savedDay.equalsIgnoreCase(currentDay)) {
                savedDay = currentDay;
                // in this way, when you are after midnight, it writes automatically
                // in a new file with new date
                statsLog = new File(folderStatsLog, Main.getNode().getKey() + "." + savedDay);
                LogAppl.getInstance().emit(NodeMessage.JEMC082I, statsLog.getAbsolutePath());
            }
            // de-serializes the sample in XML by XStream
            String ee = xs.toXML(sample);
            // removes line.separator and blanks
            // in this way in the file, every record is a sample
            // easier to read and manage
            ee = StringUtils.remove(ee, '\n');
            ee = StringUtils.remove(ee, ' ');
            // writes always in append mode even if new
            PrintWriter ps = new PrintWriter(
                    new OutputStreamWriter(new FileOutputStream(statsLog, true), CharSet.DEFAULT));
            ps.println(ee);
            ps.flush();
            ps.close();
        } catch (Exception e) {
            LogAppl.getInstance().emit(NodeMessage.JEMC080E, e, statsLog.getAbsolutePath());
        }
    }
}

From source file:org.polymap.rhei.fulltext.BoundsFilterQueryDecorator.java

@Override
public Iterable<JSONObject> search(String query, int maxResults) throws Exception {
    String boundsJson = null;/*from  ww w. j  a  va 2 s  . com*/
    String searchQuery = query;

    // extract bounds:{...} param from query
    Matcher matcher = boundsPattern.matcher(query);
    if (matcher.find()) {
        String boundsParam = query.substring(matcher.start(), matcher.end());
        boundsJson = StringUtils.substringAfter(boundsParam, "bounds:");
        searchQuery = StringUtils.remove(searchQuery, boundsParam);
    }

    // next
    Iterable<JSONObject> results = next.search(searchQuery, maxResults);

    // filter bounds
    if (boundsJson != null) {
        final Geometry bounds = jsonDecoder.read(new StringReader(boundsJson));

        return Iterables.filter(results, new Predicate<JSONObject>() {
            public boolean apply(JSONObject feature) {
                try {
                    Geometry geom = (Geometry) feature.opt(FIELD_GEOM);
                    return geom != null ? bounds.contains(geom) : true;
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });
    } else {
        return results;
    }
}

From source file:org.red5.server.util.PropertyConverter.java

/**
 * Converts a string denoting an amount of time into milliseconds and adds it to the current date. Strings are expected to follow this form where # equals a digit: #M The following are permitted for denoting time: H = hours, M = minutes, S = seconds
 * /*  ww  w. jav a  2  s. co  m*/
 * @param time
 *            time
 * @return time in milliseconds
 */
public static long convertStringToFutureTimeMillis(String time) {
    Calendar exp = Calendar.getInstance();
    if (time.endsWith("H")) {
        exp.add(Calendar.HOUR, Integer.valueOf(StringUtils.remove(time, 'H')));
    } else if (time.endsWith("M")) {
        exp.add(Calendar.MINUTE, Integer.valueOf(StringUtils.remove(time, 'M')));
    } else if (time.endsWith("S")) {
        exp.add(Calendar.MILLISECOND, Integer.valueOf(StringUtils.remove(time, 'S')) * 1000);
    }
    return exp.getTimeInMillis();
}

From source file:org.red5.server.util.PropertyConverter.java

/**
 * Converts a string denoting an amount of time into seconds. Strings are expected to follow this form where # equals a digit: #M The following are permitted for denoting time: H = hours, M = minutes, S = seconds
 * //  w  ww . jav a2 s .  c o m
 * @param time
 *            time
 * @return time in seconds
 */
public static int convertStringToTimeSeconds(String time) {
    int result = 0;
    if (time.endsWith("H")) {
        int hoursToAdd = Integer.valueOf(StringUtils.remove(time, 'H'));
        result = (60 * 60) * hoursToAdd;
    } else if (time.endsWith("M")) {
        int minsToAdd = Integer.valueOf(StringUtils.remove(time, 'M'));
        result = 60 * minsToAdd;
    } else if (time.endsWith("S")) {
        int secsToAdd = Integer.valueOf(StringUtils.remove(time, 'S'));
        result = secsToAdd;
    }
    return result;
}

From source file:org.red5.server.util.PropertyConverter.java

/**
 * Converts a string denoting an amount of time into milliseconds. Strings are expected to follow this form where # equals a digit: #M The following are permitted for denoting time: H = hours, M = minutes, S = seconds
 * /*from   w  w  w.ja v  a 2 s  . c  o  m*/
 * @param time
 *            time
 * @return time in milliseconds
 */
public static long convertStringToTimeMillis(String time) {
    long result = 0;
    if (time.endsWith("H")) {
        long hoursToAdd = Integer.valueOf(StringUtils.remove(time, 'H'));
        result = ((1000 * 60) * 60) * hoursToAdd;
    } else if (time.endsWith("M")) {
        long minsToAdd = Integer.valueOf(StringUtils.remove(time, 'M'));
        result = (1000 * 60) * minsToAdd;
    } else if (time.endsWith("S")) {
        long secsToAdd = Integer.valueOf(StringUtils.remove(time, 'S'));
        result = 1000 * secsToAdd;
    }
    return result;
}

From source file:org.red5.server.util.PropertyConverter.java

/**
 * Converts a string denoting an amount of bytes into an integer value. Strings are expected to follow this form where # equals a digit: #M The following are permitted for denoting binary size: K = kilobytes, M = megabytes, G = gigabytes
 * //from  w  ww  .  j a v a  2 s  .  c  om
 * @param memSize
 *            memory
 * @return size as an integer
 */
public static int convertStringToMemorySizeInt(String memSize) {
    int result = 0;
    if (memSize.endsWith("K")) {
        result = Integer.valueOf(StringUtils.remove(memSize, 'K')) * 1000;
    } else if (memSize.endsWith("M")) {
        result = Integer.valueOf(StringUtils.remove(memSize, 'M')) * 1000 * 1000;
    } else if (memSize.endsWith("G")) {
        result = Integer.valueOf(StringUtils.remove(memSize, 'G')) * 1000 * 1000 * 1000;
    }
    return result;
}

From source file:org.red5.server.util.PropertyConverter.java

/**
 * Converts a string denoting an amount of bytes into an long value. Strings are expected to follow this form where # equals a digit: #M The following are permitted for denoting binary size: K = kilobytes, M = megabytes, G = gigabytes
 * //from www  .j  a va 2  s.  co  m
 * @param memSize
 *            memory size
 * @return size as an long
 */
public static long convertStringToMemorySizeLong(String memSize) {
    long result = 0;
    if (memSize.endsWith("K")) {
        result = Long.valueOf(StringUtils.remove(memSize, 'K')) * 1000;
    } else if (memSize.endsWith("M")) {
        result = Long.valueOf(StringUtils.remove(memSize, 'M')) * 1000 * 1000;
    } else if (memSize.endsWith("G")) {
        result = Long.valueOf(StringUtils.remove(memSize, 'G')) * 1000 * 1000 * 1000;
    }
    return result;
}

From source file:org.squashtest.tm.web.internal.helper.HyphenedStringHelper.java

/**
 * removes hyphens and camel cases the string
 * //from w ww  .j a  v  a2  s. c  o  m
 * @param hyphened
 * @return
 */
public static String hyphenedToCamelCase(String hyphened) {
    return StringUtils.remove(WordUtils.capitalize(hyphened, HYPHEN_ARRAY), '-');
}

From source file:org.starnub.starnubserver.connections.player.character.CharacterIP.java

/**
 * Constructor used in adding, removing or updating a object in the database table character_ip_log
 *
 * @param playerCharacter PlayerCharacter of the character that was seen with this ip
 * @param sessionIp InetAddress representing the IP Address
 *///from   w  w  w.  j a  va  2s .c  o m
public CharacterIP(PlayerCharacter playerCharacter, InetAddress sessionIp, boolean createEntry) {
    this.playerCharacter = playerCharacter;
    this.sessionIpString = StringUtils.remove(sessionIp.toString(), "/");
    if (createEntry) {
        CHARACTER_IP_LOG_DB.createOrUpdate(this);
    }
}