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

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

Introduction

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

Prototype

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

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:com.norconex.committer.core.FileAddOperation.java

/**
 * Constructor./* w  w  w.  j  av  a 2s.c o m*/
 * @param refFile the reference file to be added
 */
public FileAddOperation(File refFile) {
    super();
    this.hashCode = refFile.hashCode();
    this.refFile = refFile;

    String basePath = StringUtils.removeEnd(refFile.getAbsolutePath(), FileSystemCommitter.EXTENSION_REFERENCE);
    this.contentFile = new File(basePath + FileSystemCommitter.EXTENSION_CONTENT);
    this.metaFile = new File(basePath + FileSystemCommitter.EXTENSION_METADATA);
    try {
        this.reference = FileUtils.readFileToString(refFile, CharEncoding.UTF_8);
    } catch (IOException e) {
        throw new CommitterException("Could not load reference for " + refFile, e);
    }
    this.metadata = new Properties();
    synchronized (metadata) {
        if (metaFile.exists()) {
            FileInputStream is = null;
            try {
                is = new FileInputStream(metaFile);
                metadata.load(is);
            } catch (IOException e) {
                throw new CommitterException("Could not load metadata for " + metaFile, e);
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }

}

From source file:io.freeswitch.command.PlaybackCommand.java

@Override
public String argument() {
    String variables = "";
    if (_channelVariables.isEmpty()) {
        for (ChannelVariable channelVariable : _channelVariables) {
            variables += channelVariable.toString() + ",";
        }// w w  w.ja v  a  2s .com

        variables = "{" + StringUtils.removeEnd(variables, ",") + "}";
    }

    return String.format("%1s %2s", variables, _audioFile);
}

From source file:cc.recommenders.utils.Zips.java

public static ICoReTypeName type(ZipEntry entry, @Nullable String suffix) {
    String name = StringUtils.removeEnd(entry.getName(), suffix);
    return CoReTypeName.get("L" + name);
}

From source file:com.javacreed.examples.lang.DynamicClassLoader.java

public void loadJar(final InputStream in) throws IOException {
    try (BufferedInputStream bis = new BufferedInputStream(in); ZipInputStream zis = new ZipInputStream(bis)) {
        for (ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry()) {
            if (ze.isDirectory()) {
                continue;
            }//ww w.j  a v  a  2s.co  m

            final String name = ze.getName();
            final String canonicalName = StringUtils.removeEnd(name, ".class").replaceAll("[\\/]", ".");
            final byte[] classBytes = IOUtils.toByteArray(zis);
            if (loadedClasses.putIfAbsent(canonicalName, classBytes) == null) {
                DynamicClassLoader.LOGGER.debug("Loading class: {} of {} bytes", canonicalName,
                        classBytes.length);
            } else {
                DynamicClassLoader.LOGGER.debug("Skipping class: {} of {} bytes as onle already exists",
                        canonicalName, classBytes.length);
            }
        }
    }
}

From source file:com.kixeye.chassis.transport.swagger.SwaggerServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // figure out the real path
    String pathInfo = StringUtils.trimToEmpty(req.getPathInfo());

    while (pathInfo.endsWith("/")) {
        pathInfo = StringUtils.removeEnd(pathInfo, "/");
    }//w  ww  .j  av a 2  s. c  o  m

    while (pathInfo.startsWith("/")) {
        pathInfo = StringUtils.removeStart(pathInfo, "/");
    }

    if (StringUtils.isBlank(pathInfo)) {
        resp.sendRedirect(rootContextPath + "/" + WELCOME_PAGE);
    } else {
        // get the resource
        AbstractFileResolvingResource resource = (AbstractFileResolvingResource) resourceLoader
                .getResource(SWAGGER_DIRECTORY + "/" + pathInfo);

        // send it to the response
        if (resource.exists()) {
            StreamUtils.copy(resource.getInputStream(), resp.getOutputStream());
            resp.setStatus(HttpServletResponse.SC_OK);
            resp.flushBuffer();
        } else {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}

From source file:com.holidaycheck.marathon.maven.DeployMojoTest.java

private String getMarathonHost() {
    return StringUtils.removeEnd(server.url("").toString(), "/");
}

From source file:com.tbodt.jswerve.maven.GenerateTemplatesMojo.java

/**
 * Executes the mojo./*from www.  j av  a2s .c  o  m*/
 *
 * @throws MojoExecutionException if something really bad happens
 */
public void execute() throws MojoExecutionException {
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.addDefaultExcludes();
    scanner.setBasedir(sourceDirectory);
    scanner.setIncludes(new String[] { "**/*.jtl" });
    scanner.scan();

    for (String templatePath : scanner.getIncludedFiles()) {
        File template = new File(sourceDirectory, templatePath);

        String templateClassName = StringUtils.removeEnd(templatePath, ".jtl").replace('.', '_')
                .replace(File.separatorChar, '.');

        int lastDot = templateClassName.lastIndexOf('.');
        String templatePackage = templateClassName.substring(0, lastDot);
        String templateName = templateClassName.substring(lastDot + 1);

        File outputFile = new File(outputDirectory,
                templateClassName.replace('.', File.separatorChar) + ".java");
        Reader input = null;
        PrintWriter output = null;
        try {
            input = new FileReader(template);
            getLog().debug(String.valueOf(outputFile.getParentFile().mkdirs()));
            output = new PrintWriter(new FileWriter(outputFile));

            output.println("package " + templatePackage + ";");
            output.println();
            output.println("public class " + templateName + " implements com.tbodt.jswerve.Template {");
            output.println("    @Override");
            output.println("    public String render() {");
            output.write(Jtl.generateCode(input));
            output.println("    }");
            output.println("}");
        } catch (IOException ioe) {
            throw new MojoExecutionException("IOException!", ioe);
        } finally {
            if (input != null)
                try {
                    input.close();
                } catch (IOException ex) {
                    getLog().error(ex); // nothing else can be done
                }
            if (output != null)
                output.close();
        }
    }

    // notify maven of the new output directory
    project.addCompileSourceRoot(outputDirectory.getPath());
}

From source file:io.restassured.internal.print.RequestPrinter.java

public static String print(FilterableRequestSpecification requestSpec, String requestMethod,
        String completeRequestUri, LogDetail logDetail, PrintStream stream, boolean shouldPrettyPrint) {
    final StringBuilder builder = new StringBuilder();
    if (logDetail == ALL || logDetail == METHOD) {
        addSingle(builder, "Request method:", requestMethod);
    }/*ww w  .j av  a 2 s.  c  o m*/
    if (logDetail == ALL || logDetail == URI) {
        addSingle(builder, "Request URI:", completeRequestUri);
    }
    if (logDetail == ALL) {
        addProxy(requestSpec, builder);
    }
    if (logDetail == ALL || logDetail == PARAMS) {
        addMapDetails(builder, "Request params:", requestSpec.getRequestParams());
        addMapDetails(builder, "Query params:", requestSpec.getQueryParams());
        addMapDetails(builder, "Form params:", requestSpec.getFormParams());
        addMapDetails(builder, "Path params:", requestSpec.getNamedPathParams());
        addMultiParts(requestSpec, builder);
    }

    if (logDetail == ALL || logDetail == HEADERS) {
        addHeaders(requestSpec, builder);
    }
    if (logDetail == ALL || logDetail == COOKIES) {
        addCookies(requestSpec, builder);
    }
    if (logDetail == ALL || logDetail == BODY) {
        addBody(requestSpec, builder, shouldPrettyPrint);
    }
    String logString = builder.toString();
    if (logString.endsWith("\n")) {
        logString = StringUtils.removeEnd(logString, "\n");
    }
    stream.println(logString);
    return logString;
}

From source file:com.monarchapis.client.resource.AbstractResource.java

public AbstractResource(String baseUrl, RestClientFactory clientFactory,
        List<RequestProcessor> requestSigners) {
    baseUrl = StringUtils.removeEnd(baseUrl, "/");

    if (StringUtils.isBlank(baseUrl)) {
        throw new IllegalArgumentException("baseUrl must not be blank or null");
    }/*w ww .j av  a  2  s . com*/

    if (clientFactory == null) {
        throw new IllegalArgumentException("clientFactory must not be null");
    }

    this.baseUrl = baseUrl;
    this.clientFactory = clientFactory;
    this.requestSigners = requestSigners;
}

From source file:com.google.dart.tools.ui.internal.cleanup.migration.Migrate_1M4_CleanUp.java

@Override
protected void createFix() {
    unitNode.accept(new ASTVisitor<Void>() {

        @Override/* ww w . ja  v a  2s  . c  o m*/
        public Void visitMethodInvocation(DartMethodInvocation node) {
            super.visitMethodInvocation(node);
            DartExpression realTarget = node.getRealTarget();
            DartIdentifier nameNode = node.getFunctionName();
            String name = nameNode.getName();
            // with target
            if (realTarget != null && realTarget.getType() instanceof InterfaceType) {
                InterfaceType targetType = (InterfaceType) realTarget.getType();
                // xMatching renamed to xWhere
                if ("firstMatching".equals(name) || "lastMatching".equals(name)
                        || "singleMatching".equals(name)) {
                    if (isSubType(targetType, "Iterable", "dart://core/core.dart")
                            || isSubType(targetType, "Stream", "dart://async/async.dart")) {
                        name = StringUtils.removeEnd(name, "Matching") + "Where";
                        addReplaceEdit(SourceRangeFactory.create(nameNode), name);
                        return null;
                    }
                }
                if ("removeMatching".equals(name) || "retainMatching".equals(name)) {
                    if (isSubType(targetType, "Collection", "dart://core/core.dart")) {
                        name = StringUtils.removeEnd(name, "Matching") + "Where";
                        addReplaceEdit(SourceRangeFactory.create(nameNode), name);
                        return null;
                    }
                }
            }
            return null;
        }
    });
}