List of usage examples for org.apache.commons.lang3 StringUtils stripStart
public static String stripStart(final String str, final String stripChars)
Strips any of a set of characters from the start of a String.
A null input String returns null .
From source file:com.sangupta.clitools.file.LeftTrim.java
@Override protected boolean processFile(File file) throws IOException { // read entire file in memory List<String> contents = FileUtils.readLines(file); final long initial = file.length(); // now for each string - trim from end for (int index = 0; index < contents.size(); index++) { String line = contents.get(index); line = StringUtils.stripStart(line, null); contents.set(index, line);//w w w.java2 s .c o m } // write back contents of file FileUtils.writeLines(file, contents); long current = file.length(); this.bytesSaved.addAndGet(initial - current); System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " left-trimmed and saved " + (initial - current) + " bytes."); return true; }
From source file:ch.devmine.javaparser.utils.ParserUtils.java
public static List<String> prepareComments(String comment) { List<String> javadoc = new ArrayList<>(Arrays.asList(comment.split("\n"))); if (javadoc.get(0).trim().isEmpty()) { javadoc.remove(0);/*from ww w .j a v a2s .c o m*/ } if (!javadoc.isEmpty() && javadoc.get(javadoc.size() - 1).trim().isEmpty()) { javadoc.remove(javadoc.size() - 1); } for (int i = 0; i < javadoc.size() - 1; i++) { String line = javadoc.get(i); line = StringUtils.stripStart(line, "\t *"); javadoc.set(i, line); if (!line.isEmpty()) { break; } else { javadoc.remove(line); i--; } } for (int j = javadoc.size() - 1; j >= 0; j--) { String line = javadoc.get(j); line = StringUtils.stripStart(line, "\t *"); javadoc.set(j, line); if (!line.isEmpty()) { break; } else { javadoc.remove(line); } } for (int k = 0; k < javadoc.size() - 1; k++) { String line = javadoc.get(k); line = StringUtils.stripStart(line, "\t *"); javadoc.set(k, line); } return javadoc; }
From source file:com.sangupta.codefix.FixCopyright.java
protected String processEachFile(File file) throws IOException { // read contents String contents = FileUtils.readFileToString(file).trim(); // check if file contains comments or not boolean hasCopyright = CopyrightHelper.checkCopyrightExists(contents); if (!hasCopyright) { // append the copyright and move on contents = this.copyrightNotice + SYSTEM_NEW_LINE + contents; FileUtils.writeStringToFile(file, contents); return "adding copyright"; }//from ww w .j a v a 2s .c om // remove comment int index = CopyrightHelper.findCopyrightEnd(contents); if (index == -1) { System.out.println("No proper ending of comment detected, skipping!"); } contents = contents.substring(index + 1); contents = this.copyrightNotice + SYSTEM_NEW_LINE + StringUtils.stripStart(contents, null); FileUtils.writeStringToFile(file, contents); return "copyright updated!"; }
From source file:io.hakbot.controller.servlet.ConsoleControllerServlet.java
private void doRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { final String pathInfo = request.getPathInfo(); final String uuid; // Check to make sure path info was specified if (StringUtils.isEmpty(pathInfo)) { response.sendError(400);// w w w .ja v a 2 s .com return; } else { // Path info was specified so strip off the leading / character uuid = StringUtils.stripStart(pathInfo, "/"); } // Check to make sure the uuid is a valid format if (!UuidUtil.isValidUUID(uuid)) { response.sendError(400); return; } final QueryManager qm = new QueryManager(); final Job job = qm.getJob(uuid, new SystemAccount()); qm.close(); if (job == null) { response.sendError(404); return; } final ExpectedClassResolver resolver = new ExpectedClassResolver(); try { final Class pluginClass = resolver.resolveProvider(job); request.setAttribute("job", job); final String pluginPage = "/WEB-INF/plugins/" + pluginClass.getName() + "/index.jsp?uuid=" + uuid; response.setContentType("text/html;charset=UTF-8"); request.getRequestDispatcher(pluginPage).include(request, response); return; } catch (ClassNotFoundException | ExpectedClassResolverException e) { LOGGER.error(e.getMessage()); } response.sendError(404); }
From source file:com.devbliss.risotto.RisottoParser.java
private void getItemsUntilItemEnd(RisottoRISContentService content, RisottoItem myItem) throws IOException { while (content.hasNextLine()) { String currentLine = content.peekNextLine(); if (currentLine.trim().length() < 4) { content.skipNextLine();/*www.ja va 2 s .c om*/ continue; } if (PATTERN_ITEMEND.matcher(StringUtils.stripStart(currentLine, null)).matches()) { content.skipNextLine(); break; } else if (PATTERN_ITEM.matcher(StringUtils.stripStart(currentLine, null)).matches()) { extractDataFromField(content, myItem); continue; } content.skipNextLine(); } }
From source file:com.technophobia.substeps.model.Arguments.java
public static String substituteValues(String src, Config cfg) { ParameterSubstitution parameterSubstituionConfig = NewSubstepsExecutionConfig .getParameterSubstituionConfig(); if (src != null && parameterSubstituionConfig.substituteParameters() && src.startsWith(parameterSubstituionConfig.startDelimiter())) { String key = StringUtils.stripStart( StringUtils.stripEnd(src, parameterSubstituionConfig.endDelimiter()), parameterSubstituionConfig.startDelimiter()); String normalizedValue = src; if (cfg.hasPath(key)) { String substitute = cfg.getString(key); if (substitute == null) { throw new SubstepsRuntimeException("Failed to resolve property " + src + " to be substituted "); }/* w w w . j a v a 2s .co m*/ normalizedValue = substitute; if (parameterSubstituionConfig.normalizeValues()) { // This part will support the conversion of properties files containing accented characters try { normalizedValue = new String( substitute.getBytes(parameterSubstituionConfig.normalizeFrom()), parameterSubstituionConfig.normalizeTo()); } catch (UnsupportedEncodingException e) { log.error("error substituting accented characters", e); } } } return normalizedValue; } return src; }
From source file:edu.usu.sdl.openstorefront.service.io.parser.SvcAttributeParser.java
@Override protected void internalParse(CSVReader reader) throws IOException { AttributeType attributeType = new AttributeType(); attributeType.setAttributeType(AttributeType.DI2E_SVCV4); attributeType.setDescription("DI2E SvcV-4 Alignment"); //Default to true....Later an admin would need to determine which ones should only allow one. attributeType.setAllowMultipleFlg(Boolean.TRUE); attributeType.setArchitectureFlg(Boolean.TRUE); attributeType.setVisibleFlg(Boolean.TRUE); attributeType.setImportantFlg(Boolean.TRUE); attributeType.setRequiredFlg(Boolean.FALSE); attributeMap.put(attributeType, new ArrayList<>()); int lineNumber; List<String[]> allLines = reader.readAll(); for (int i = 1; i < allLines.size(); i++) { lineNumber = i;//from w w w.ja v a 2 s. co m String data[] = allLines.get(i); if (data.length > DESCRIPTION) { String code = data[UID].trim().toUpperCase(); if ("0".equals(code) == false) { code = StringUtils.stripStart(code, "0"); } if (StringUtils.isNotBlank(code)) { AttributeCode attributeCode = new AttributeCode(); AttributeCodePk attributeCodePk = new AttributeCodePk(); attributeCodePk.setAttributeCode(code); attributeCodePk.setAttributeType(attributeType.getAttributeType()); attributeCode.setAttributeCodePk(attributeCodePk); StringBuilder desc = new StringBuilder(); desc.append("<b>Definition:</b>") .append(StringProcessor .stripeExtendedChars(data[DEFINITION].trim().replace("\n", "<br>"))) .append("<br>"); desc.append("<b>Description:</b>") .append(StringProcessor .stripeExtendedChars(data[DESCRIPTION].trim().replace("\n", "<br>"))) .append("<br>"); desc.append("<b>JCA Alignment:</b>") .append(StringProcessor .stripeExtendedChars(data[JCA_ALIGNMENT].trim().replace("\n", "<br>"))) .append("<br>"); desc.append("<b>JCSFL Alignment:</b>") .append(StringProcessor .stripeExtendedChars(data[JCSFL_ALIGNMENT].trim().replace("\n", "<br>"))) .append("<br>"); desc.append("<b>JARM/ESL Alignment:</b>") .append(StringProcessor .stripeExtendedChars(data[JARM_ALIGNMENT].trim().replace("\n", "<br>"))) .append("<br>"); attributeCode.setDescription(desc.toString()); attributeCode.setArchitectureCode(data[CODE].trim().toUpperCase()); attributeCode.setLabel(data[CODE].toUpperCase().trim() + " " + data[LABEL].trim()); attributeMap.get(attributeType).add(attributeCode); } else { log.log(Level.WARNING, MessageFormat.format( "Skipping line: {0} + line is mssing UID or UID doesn't resolve. (0 padding is removed)", lineNumber)); } } else { log.log(Level.WARNING, MessageFormat.format("Skipping line: {0} + line is mssing required fields.", lineNumber)); } } }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileObject.java
/** * Convenience method that returns the container ( i.e. "bucket ) and path from the current URL. * /*from w w w.j a va 2 s.co m*/ * @return A tuple containing the bucket name and the path. */ private Pair<String, String> getContainerAndPath() { Pair<String, String> res = null; try { URLFileName currName = (URLFileName) getName(); String currPathStr = currName.getPath(); currPathStr = StringUtils.stripStart(currPathStr, "/"); if (StringUtils.isBlank(currPathStr)) { log.warn(String.format("getContainerAndPath() : Path '%s' does not appear to be valid", currPathStr)); return null; } // Deal with the special case of the container root. if (StringUtils.contains(currPathStr, "/") == false) { // Container and root return new ImmutablePair<>(currPathStr, "/"); } String[] resArray = StringUtils.split(currPathStr, "/", 2); res = new ImmutablePair<>(resArray[0], resArray[1]); } catch (Exception ex) { log.error(String.format("getContainerAndPath() : Path does not appear to be valid"), ex); } return res; }
From source file:com.devbliss.risotto.RisottoParser.java
private void getNextItemStart(RisottoRISContentService content, RisottoItem myItem) throws IOException { while (content.hasNextLine()) { String currentLine = content.peekNextLine(); if (currentLine.trim().length() < 4) { content.skipNextLine();// ww w . jav a2s . c o m continue; } if (PATTERN_ITEMSTART.matcher(StringUtils.stripStart(currentLine, null)).matches()) { extractDataFromField(content, myItem); break; } content.skipNextLine(); } }
From source file:io.nosorog.core.ScriptLoader.java
private Node parseHeader(String line) throws ParseException { String l = StringUtils.stripStart(line, " *"); if (l.startsWith("import")) { return JavaParser.parseImport(l + ";"); } else if (StringUtils.startsWithAny(l, "@Name", "@Description", "@Startup", "@Schedule")) { return JavaParser.parseAnnotation(l); } else if (l.startsWith("@")) { return JavaParser.parseBodyDeclaration(l + ";"); }/*from w w w . j a va2s . co m*/ return null; }