当前位置: 首页>>代码示例>>Java>>正文


Java FileUtil.stripLeadingSeparator方法代码示例

本文整理汇总了Java中org.apache.camel.util.FileUtil.stripLeadingSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.stripLeadingSeparator方法的具体用法?Java FileUtil.stripLeadingSeparator怎么用?Java FileUtil.stripLeadingSeparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.util.FileUtil的用法示例。


在下文中一共展示了FileUtil.stripLeadingSeparator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: asRemoteFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
private RemoteFile<ChannelSftp.LsEntry> asRemoteFile(String absolutePath, ChannelSftp.LsEntry file, String charset) {
    RemoteFile<ChannelSftp.LsEntry> answer = new RemoteFile<ChannelSftp.LsEntry>();

    answer.setCharset(charset);
    answer.setEndpointPath(endpointPath);
    answer.setFile(file);
    answer.setFileNameOnly(file.getFilename());
    answer.setFileLength(file.getAttrs().getSize());
    answer.setLastModified(file.getAttrs().getMTime() * 1000L);
    answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost());
    answer.setDirectory(file.getAttrs().isDir());

    // absolute or relative path
    boolean absolute = FileUtil.hasLeadingSeparator(absolutePath);
    answer.setAbsolute(absolute);

    // create a pseudo absolute name
    String dir = FileUtil.stripTrailingSeparator(absolutePath);
    String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + file.getFilename());
    // if absolute start with a leading separator otherwise let it be relative
    if (absolute) {
        absoluteFileName = "/" + absoluteFileName;
    }
    answer.setAbsoluteFilePath(absoluteFileName);

    // the relative filename, skip the leading endpoint configured path
    String relativePath = ObjectHelper.after(absoluteFileName, endpointPath);
    // skip trailing /
    relativePath = FileUtil.stripLeadingSeparator(relativePath);
    answer.setRelativeFilePath(relativePath);

    // the file name should be the relative path
    answer.setFileName(answer.getRelativeFilePath());

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:37,代码来源:SftpConsumer.java

示例2: ensureRelativeFtpDirectory

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
/**
 * Checks whether directory used in ftp/ftps/sftp endpoint URI is relative.
 * Absolute path will be converted to relative path and a WARN will be printed.
 * @see <a href="http://camel.apache.org/ftp2.html">FTP/SFTP/FTPS Component</a>
 * @param ftpComponent
 * @param configuration
 */
public static void ensureRelativeFtpDirectory(Component ftpComponent, RemoteFileConfiguration configuration) {
    if (FileUtil.hasLeadingSeparator(configuration.getDirectoryName())) {
        String relativePath = FileUtil.stripLeadingSeparator(configuration.getDirectoryName());
        LOG.warn(String.format("%s doesn't support absolute paths, \"%s\" will be converted to \"%s\". "
                + "After Camel 2.16, absolute paths will be invalid.",
                ftpComponent.getClass().getSimpleName(),
                configuration.getDirectoryName(),
                relativePath));
        configuration.setDirectory(relativePath);
        configuration.setDirectoryName(relativePath);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:FtpUtils.java

示例3: asRemoteFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
private RemoteFile<FTPFile> asRemoteFile(String absolutePath, FTPFile file, String charset) {
    RemoteFile<FTPFile> answer = new RemoteFile<FTPFile>();

    answer.setCharset(charset);
    answer.setEndpointPath(endpointPath);
    answer.setFile(file);
    answer.setFileNameOnly(file.getName());
    answer.setFileLength(file.getSize());
    answer.setDirectory(file.isDirectory());
    if (file.getTimestamp() != null) {
        answer.setLastModified(file.getTimestamp().getTimeInMillis());
    }
    answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost());

    // absolute or relative path
    boolean absolute = FileUtil.hasLeadingSeparator(absolutePath);
    answer.setAbsolute(absolute);

    // create a pseudo absolute name
    String dir = FileUtil.stripTrailingSeparator(absolutePath);
    String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + file.getName());
    // if absolute start with a leading separator otherwise let it be relative
    if (absolute) {
        absoluteFileName = "/" + absoluteFileName;
    }
    answer.setAbsoluteFilePath(absoluteFileName);

    // the relative filename, skip the leading endpoint configured path
    String relativePath = ObjectHelper.after(absoluteFileName, endpointPath);
    // skip leading /
    relativePath = FileUtil.stripLeadingSeparator(relativePath);
    answer.setRelativeFilePath(relativePath);

    // the file name should be the relative path
    answer.setFileName(answer.getRelativeFilePath());

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:39,代码来源:FtpConsumer.java

示例4: buildUrl

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public static String buildUrl(String path1, String path2) {
    String s1 = FileUtil.stripTrailingSeparator(path1);
    String s2 = FileUtil.stripLeadingSeparator(path2);
    if (s1 != null && s2 != null) {
        return s1 + "/" + s2;
    } else if (path1 != null) {
        return path1;
    } else {
        return path2;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:SwaggerHelper.java

示例5: createConsumer

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
@Override
public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                               String consumes, String produces, Map<String, Object> parameters) throws Exception {

    String path = basePath;
    if (uriTemplate != null) {
        // make sure to avoid double slashes
        if (uriTemplate.startsWith("/")) {
            path = path + uriTemplate;
        } else {
            path = path + "/" + uriTemplate;
        }
    }
    path = FileUtil.stripLeadingSeparator(path);

    String scheme = "http";
    String host = "";
    int port = 0;

    // if no explicit port/host configured, then use port from rest configuration
    RestConfiguration config = getCamelContext().getRestConfiguration();
    if (config.getComponent() == null || config.getComponent().equals("jetty")) {
        if (config.getScheme() != null) {
            scheme = config.getScheme();
        }
        if (config.getHost() != null) {
            host = config.getHost();
        }
        int num = config.getPort();
        if (num > 0) {
            port = num;
        }
    }

    // if no explicit hostname set then resolve the hostname
    if (ObjectHelper.isEmpty(host)) {
        if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
            host = HostUtils.getLocalHostName();
        } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
            host = HostUtils.getLocalIp();
        }
    }

    Map<String, Object> map = new HashMap<String, Object>();
    // build query string, and append any endpoint configuration properties
    if (config != null && (config.getComponent() == null || config.getComponent().equals("jetty"))) {
        // setup endpoint options
        if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
            map.putAll(config.getEndpointProperties());
        }
    }

    String query = URISupport.createQueryString(map);

    String url = "jetty:%s://%s:%s/%s?httpMethodRestrict=%s";
    // must use upper case for restrict
    String restrict = verb.toUpperCase(Locale.US);
    // get the endpoint
    url = String.format(url, scheme, host, port, path, restrict);

    if (!query.isEmpty()) {
        url = url + "&" + query;
    }
    
    JettyHttpEndpoint endpoint = camelContext.getEndpoint(url, JettyHttpEndpoint.class);
    setProperties(endpoint, parameters);

    // disable this filter as we want to use ours
    endpoint.setEnableMultipartFilter(false);
    // use the rest binding
    endpoint.setBinding(new JettyRestHttpBinding(endpoint));

    // configure consumer properties
    Consumer consumer = endpoint.createConsumer(processor);
    if (config != null && config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
        setProperties(consumer, config.getConsumerProperties());
    }

    return consumer;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:81,代码来源:JettyHttpComponent.java

示例6: doCreateConsumer

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
Consumer doCreateConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                          String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters, boolean api) throws Exception {

    String path = basePath;
    if (uriTemplate != null) {
        // make sure to avoid double slashes
        if (uriTemplate.startsWith("/")) {
            path = path + uriTemplate;
        } else {
            path = path + "/" + uriTemplate;
        }
    }
    path = FileUtil.stripLeadingSeparator(path);

    // if no explicit port/host configured, then use port from rest configuration
    RestConfiguration config = configuration;
    if (config == null) {
        config = camelContext.getRestConfiguration("servlet", true);
    }

    Map<String, Object> map = new HashMap<String, Object>();
    // build query string, and append any endpoint configuration properties
    if (config.getComponent() == null || config.getComponent().equals("servlet")) {
        // setup endpoint options
        if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
            map.putAll(config.getEndpointProperties());
        }
    }

    boolean cors = config.isEnableCORS();
    if (cors) {
        // allow HTTP Options as we want to handle CORS in rest-dsl
        map.put("optionsEnabled", "true");
    }

    // do not append with context-path as the servlet path should be without context-path

    String query = URISupport.createQueryString(map);

    String url;
    if (api) {
        url = "servlet:///%s?matchOnUriPrefix=true&httpMethodRestrict=%s";
    } else {
        url = "servlet:///%s?httpMethodRestrict=%s";
    }

    // must use upper case for restrict
    String restrict = verb.toUpperCase(Locale.US);
    if (cors) {
        restrict += ",OPTIONS";
    }
    // get the endpoint
    url = String.format(url, path, restrict);
    
    if (!query.isEmpty()) {
        url = url + "&" + query;
    }       

    ServletEndpoint endpoint = camelContext.getEndpoint(url, ServletEndpoint.class);
    setProperties(camelContext, endpoint, parameters);

    if (!map.containsKey("httpBindingRef")) {
        // use the rest binding, if not using a custom http binding
        HttpBinding binding = new ServletRestHttpBinding();
        binding.setHeaderFilterStrategy(endpoint.getHeaderFilterStrategy());
        binding.setTransferException(endpoint.isTransferException());
        binding.setEagerCheckContentAvailable(endpoint.isEagerCheckContentAvailable());
        endpoint.setHttpBinding(binding);
    }

    // configure consumer properties
    Consumer consumer = endpoint.createConsumer(processor);
    if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
        setProperties(camelContext, consumer, config.getConsumerProperties());
    }

    return consumer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:79,代码来源:ServletComponent.java

示例7: doMoveExistingFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
/**
 * Moves any existing file due fileExists=Move is in use.
 */
private void doMoveExistingFile(String name, String targetName) throws GenericFileOperationFailedException {
    // need to evaluate using a dummy and simulate the file first, to have access to all the file attributes
    // create a dummy exchange as Exchange is needed for expression evaluation
    // we support only the following 3 tokens.
    Exchange dummy = endpoint.createExchange();
    // we only support relative paths for the ftp component, so dont provide any parent
    String parent = null;
    String onlyName = FileUtil.stripPath(targetName);
    dummy.getIn().setHeader(Exchange.FILE_NAME, targetName);
    dummy.getIn().setHeader(Exchange.FILE_NAME_ONLY, onlyName);
    dummy.getIn().setHeader(Exchange.FILE_PARENT, parent);

    String to = endpoint.getMoveExisting().evaluate(dummy, String.class);
    // we only support relative paths for the ftp component, so strip any leading paths
    to = FileUtil.stripLeadingSeparator(to);
    // normalize accordingly to configuration
    to = endpoint.getConfiguration().normalizePath(to);
    if (ObjectHelper.isEmpty(to)) {
        throw new GenericFileOperationFailedException("moveExisting evaluated as empty String, cannot move existing file: " + name);
    }

    // do we have a sub directory
    String dir = FileUtil.onlyPath(to);
    if (dir != null) {
        // ensure directory exists
        buildDirectory(dir, false);
    }

    // deal if there already exists a file
    if (existsFile(to)) {
        if (endpoint.isEagerDeleteTargetFile()) {
            LOG.trace("Deleting existing file: {}", to);
            deleteFile(to);
        } else {
            throw new GenericFileOperationFailedException("Cannot moved existing file from: " + name + " to: " + to + " as there already exists a file: " + to);
        }
    }

    LOG.trace("Moving existing file: {} to: {}", name, to);
    if (!renameFile(targetName, to)) {
        throw new GenericFileOperationFailedException("Cannot rename file from: " + name + " to: " + to);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:47,代码来源:SftpOperations.java

示例8: doMoveExistingFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
/**
 * Moves any existing file due fileExists=Move is in use.
 */
private void doMoveExistingFile(String name, String targetName) throws GenericFileOperationFailedException {
    // need to evaluate using a dummy and simulate the file first, to have access to all the file attributes
    // create a dummy exchange as Exchange is needed for expression evaluation
    // we support only the following 3 tokens.
    Exchange dummy = endpoint.createExchange();
    // we only support relative paths for the ftp component, so dont provide any parent
    String parent = null;
    String onlyName = FileUtil.stripPath(targetName);
    dummy.getIn().setHeader(Exchange.FILE_NAME, targetName);
    dummy.getIn().setHeader(Exchange.FILE_NAME_ONLY, onlyName);
    dummy.getIn().setHeader(Exchange.FILE_PARENT, parent);

    String to = endpoint.getMoveExisting().evaluate(dummy, String.class);
    // we only support relative paths for the ftp component, so strip any leading paths
    to = FileUtil.stripLeadingSeparator(to);
    // normalize accordingly to configuration
    to = endpoint.getConfiguration().normalizePath(to);
    if (ObjectHelper.isEmpty(to)) {
        throw new GenericFileOperationFailedException("moveExisting evaluated as empty String, cannot move existing file: " + name);
    }

    // do we have a sub directory
    String dir = FileUtil.onlyPath(to);
    if (dir != null) {
        // ensure directory exists
        buildDirectory(dir, false);
    }

    // deal if there already exists a file
    if (existsFile(to)) {
        if (endpoint.isEagerDeleteTargetFile()) {
            log.trace("Deleting existing file: {}", to);
            boolean result;
            try {
                result = client.deleteFile(to);
                if (!result) {
                    throw new GenericFileOperationFailedException("Cannot delete file: " + to);
                }
            } catch (IOException e) {
                throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), "Cannot delete file: " + to, e);
            }
        } else {
            throw new GenericFileOperationFailedException("Cannot moved existing file from: " + name + " to: " + to + " as there already exists a file: " + to);
        }
    }

    log.trace("Moving existing file: {} to: {}", name, to);
    if (!renameFile(targetName, to)) {
        throw new GenericFileOperationFailedException("Cannot rename file from: " + name + " to: " + to);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:55,代码来源:FtpOperations.java

示例9: doCreateConsumer

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
Consumer doCreateConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                          String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters, boolean api) throws Exception {

    String path = basePath;
    if (uriTemplate != null) {
        // make sure to avoid double slashes
        if (uriTemplate.startsWith("/")) {
            path = path + uriTemplate;
        } else {
            path = path + "/" + uriTemplate;
        }
    }
    path = FileUtil.stripLeadingSeparator(path);

    RestConfiguration config = configuration;
    if (config == null) {
        config = camelContext.getRestConfiguration("spark-rest", true);
    }

    Map<String, Object> map = new HashMap<String, Object>();
    if (consumes != null) {
        map.put("accept", consumes);
    }

    // setup endpoint options
    if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
        map.putAll(config.getEndpointProperties());
    }

    if (ObjectHelper.isNotEmpty(path)) {
        // spark-rest uses :name syntax instead of {name} so we need to replace those
        Matcher matcher = pattern.matcher(path);
        path = matcher.replaceAll(":$1");
    }

    // prefix path with context-path if configured in rest-dsl configuration
    String contextPath = config.getContextPath();
    if (ObjectHelper.isNotEmpty(contextPath)) {
        contextPath = FileUtil.stripTrailingSeparator(contextPath);
        contextPath = FileUtil.stripLeadingSeparator(contextPath);
        if (ObjectHelper.isNotEmpty(contextPath)) {
            path = contextPath + "/" + path;
        }
    }

    String url;
    if (api) {
        url = "spark-rest:%s:%s?matchOnUriPrefix=true";
    } else {
        url = "spark-rest:%s:%s";
    }

    url = String.format(url, verb, path);

    String query = URISupport.createQueryString(map);
    if (!query.isEmpty()) {
        url = url + "?" + query;
    }

    // get the endpoint
    SparkEndpoint endpoint = camelContext.getEndpoint(url, SparkEndpoint.class);
    setProperties(camelContext, endpoint, parameters);

    // configure consumer properties
    Consumer consumer = endpoint.createConsumer(processor);
    if (config.isEnableCORS()) {
        // if CORS is enabled then configure that on the spark consumer
        if (config.getConsumerProperties() == null) {
            config.setConsumerProperties(new HashMap<String, Object>());
        }
        config.getConsumerProperties().put("enableCors", true);
    }
    if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
        setProperties(camelContext, consumer, config.getConsumerProperties());
    }
    return consumer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:78,代码来源:SparkComponent.java


注:本文中的org.apache.camel.util.FileUtil.stripLeadingSeparator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。