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


Java FileUtil.onlyPath方法代码示例

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


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

示例1: getUri

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
private String getUri(String systemId) {
    if (resourcePath != null) {
        return FileUtil.onlyPath(resourceUri) + "/" + systemId;
    } else {
        return systemId;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:DefaultLSResourceResolver.java

示例2: resolveResource

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
    // systemId should be mandatory
    if (systemId == null) {
        throw new IllegalArgumentException(String.format("Resource: %s refers an invalid resource without SystemId."
                + " Invalid resource has type: %s, namespaceURI: %s, publicId: %s, systemId: %s, baseURI: %s", resourceUri, type, namespaceURI, publicId, systemId, baseURI));
    }
    String resourceURI = null;
    // Build up the relative path for using relatedURI and baseURI
    if (baseURI == null) {
        relatedURI = FileUtil.compactPath(getUri(systemId), '/');
        resourceURI = relatedURI;
    } else {
        String relatedPath = relatedURIMap.get(baseURI);
        if (relatedPath == null) {
            relatedPath = FileUtil.onlyPath(relatedURI);
            if (relatedPath == null) {
                relatedPath = "";
            }
            relatedURI = FileUtil.compactPath(FileUtil.onlyPath(relatedURI) + "/" + systemId, '/');
            resourceURI = relatedURI;
            relatedURIMap.put(baseURI, relatedPath);
        } else {
            resourceURI = FileUtil.compactPath(relatedPath + "/" + systemId, '/');
            relatedURI = resourceURI;
        }
    }
    return new DefaultLSInput(publicId, systemId, baseURI, resourceURI);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:30,代码来源:DefaultLSResourceResolver.java

示例3: createDoneFileName

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
/**
 * Creates the associated name of the done file based on the given file name.
 * <p/>
 * This method should only be invoked if a done filename property has been set on this endpoint.
 *
 * @param fileName the file name
 * @return name of the associated done file name
 */
protected String createDoneFileName(String fileName) {
    String pattern = getDoneFileName();
    ObjectHelper.notEmpty(pattern, "doneFileName", pattern);

    // we only support ${file:name} or ${file:name.noext} as dynamic placeholders for done files
    String path = FileUtil.onlyPath(fileName);
    String onlyName = FileUtil.stripPath(fileName);

    pattern = pattern.replaceFirst("\\$\\{file:name\\}", onlyName);
    pattern = pattern.replaceFirst("\\$simple\\{file:name\\}", onlyName);
    pattern = pattern.replaceFirst("\\$\\{file:name.noext\\}", FileUtil.stripExt(onlyName));
    pattern = pattern.replaceFirst("\\$simple\\{file:name.noext\\}", FileUtil.stripExt(onlyName));

    // must be able to resolve all placeholders supported
    if (StringHelper.hasStartToken(pattern, "simple")) {
        throw new ExpressionIllegalSyntaxException(fileName + ". Cannot resolve reminder: " + pattern);
    }

    String answer = pattern;
    if (ObjectHelper.isNotEmpty(path) && ObjectHelper.isNotEmpty(pattern)) {
        // done file must always be in same directory as the real file name
        answer = path + getFileSeparator() + pattern;
    }

    if (getConfiguration().needToNormalize()) {
        // must normalize path to cater for Windows and other OS
        answer = FileUtil.normalizePath(answer);
    }

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

示例4: storeFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public synchronized boolean storeFile(String name, Exchange exchange) throws GenericFileOperationFailedException {
    // must normalize name first
    name = endpoint.getConfiguration().normalizePath(name);

    LOG.trace("storeFile({})", name);

    boolean answer = false;
    String currentDir = null;
    String path = FileUtil.onlyPath(name);
    String targetName = name;

    try {
        if (path != null && endpoint.getConfiguration().isStepwise()) {
            // must remember current dir so we stay in that directory after the write
            currentDir = getCurrentDirectory();

            // change to path of name
            changeCurrentDirectory(path);

            // the target name should be without path, as we have changed directory
            targetName = FileUtil.stripPath(name);
        }

        // store the file
        answer = doStoreFile(name, targetName, exchange);
    } finally {
        // change back to current directory if we changed directory
        if (currentDir != null) {
            changeCurrentDirectory(currentDir);
        }
    }

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

示例5: existsFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public synchronized boolean existsFile(String name) throws GenericFileOperationFailedException {
    LOG.trace("existsFile({})", name);
    if (endpoint.isFastExistsCheck()) {
        return fastExistsFile(name);
    }
    // check whether a file already exists
    String directory = FileUtil.onlyPath(name);
    if (directory == null) {
        // assume current dir if no path could be extracted
        directory = ".";
    }
    String onlyName = FileUtil.stripPath(name);

    try {
        @SuppressWarnings("rawtypes")
        Vector files = channel.ls(directory);
        // can return either null or an empty list depending on FTP servers
        if (files == null) {
            return false;
        }
        for (Object file : files) {
            ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) file;
            String existing = entry.getFilename();
            LOG.trace("Existing file: {}, target file: {}", existing, name);
            existing = FileUtil.stripPath(existing);
            if (existing != null && existing.equals(onlyName)) {
                return true;
            }
        }
        return false;
    } catch (SftpException e) {
        // or an exception can be thrown with id 2 which means file does not exists
        if (ChannelSftp.SSH_FX_NO_SUCH_FILE == e.id) {
            return false;
        }
        // otherwise its a more serious error so rethrow
        throw new GenericFileOperationFailedException(e.getMessage(), e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:40,代码来源:SftpOperations.java

示例6: storeFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public boolean storeFile(String name, Exchange exchange) throws GenericFileOperationFailedException {
    // must normalize name first
    name = endpoint.getConfiguration().normalizePath(name);

    log.trace("storeFile({})", name);

    boolean answer = false;
    String currentDir = null;
    String path = FileUtil.onlyPath(name);
    String targetName = name;

    try {
        if (path != null && endpoint.getConfiguration().isStepwise()) {
            // must remember current dir so we stay in that directory after the write
            currentDir = getCurrentDirectory();

            // change to path of name
            changeCurrentDirectory(path);

            // the target name should be without path, as we have changed directory
            targetName = FileUtil.stripPath(name);
        }

        // store the file
        answer = doStoreFile(name, targetName, exchange);
    } finally {
        // change back to current directory if we changed directory
        if (currentDir != null) {
            changeCurrentDirectory(currentDir);
        }
    }

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

示例7: existsFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public boolean existsFile(String name) throws GenericFileOperationFailedException {
    log.trace("existsFile({})", name);
    if (endpoint.isFastExistsCheck()) {
        return fastExistsFile(name);
    }
    // check whether a file already exists
    String directory = FileUtil.onlyPath(name);
    String onlyName = FileUtil.stripPath(name);
    try {
        String[] names;
        if (directory != null) {
            names = client.listNames(directory);
        } else {
            names = client.listNames();
        }
        // can return either null or an empty list depending on FTP servers
        if (names == null) {
            return false;
        }
        for (String existing : names) {
            log.trace("Existing file: {}, target file: {}", existing, name);
            existing = FileUtil.stripPath(existing);
            if (existing != null && existing.equals(onlyName)) {
                return true;
            }
        }
        return false;
    } catch (IOException e) {
        throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:32,代码来源:FtpOperations.java

示例8: DefaultLSResourceResolver

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public DefaultLSResourceResolver(CamelContext camelContext, String resourceUri) {
    this.camelContext = camelContext;
    this.resourceUri = resourceUri;
    this.resourcePath = FileUtil.onlyPath(resourceUri);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:6,代码来源:DefaultLSResourceResolver.java

示例9: doMoveExistingFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
/**
 * Moves any existing file due fileExists=Move is in use.
 */
private void doMoveExistingFile(String fileName) 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();
    String parent = FileUtil.onlyPath(fileName);
    String onlyName = FileUtil.stripPath(fileName);
    dummy.getIn().setHeader(Exchange.FILE_NAME, fileName);
    dummy.getIn().setHeader(Exchange.FILE_NAME_ONLY, onlyName);
    dummy.getIn().setHeader(Exchange.FILE_PARENT, parent);

    String to = endpoint.getMoveExisting().evaluate(dummy, String.class);
    // we must normalize it (to avoid having both \ and / in the name which confuses java.io.File)
    to = FileUtil.normalizePath(to);
    if (ObjectHelper.isEmpty(to)) {
        throw new GenericFileOperationFailedException("moveExisting evaluated as empty String, cannot move existing file: " + fileName);
    }

    // ensure any paths is created before we rename as the renamed file may be in a different path (which may be non exiting)
    // use java.io.File to compute the file path
    File toFile = new File(to);
    String directory = toFile.getParent();
    boolean absolute = FileUtil.isAbsolute(toFile);
    if (directory != null) {
        if (!buildDirectory(directory, absolute)) {
            LOG.debug("Cannot build directory [{}] (could be because of denied permissions)", directory);
        }
    }

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

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

示例10: 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

示例11: retrieveFileToStreamInBody

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private boolean retrieveFileToStreamInBody(String name, Exchange exchange) throws GenericFileOperationFailedException {
    OutputStream os = null;
    boolean result;
    try {
        GenericFile<FTPFile> target = (GenericFile<FTPFile>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
        ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
        
        String remoteName = name;
        String currentDir = null;
        if (endpoint.getConfiguration().isStepwise()) {
            // remember current directory
            currentDir = getCurrentDirectory();

            // change directory to path where the file is to be retrieved
            // (must do this as some FTP servers cannot retrieve using absolute path)
            String path = FileUtil.onlyPath(name);
            if (path != null) {
                changeCurrentDirectory(path);
            }
            // remote name is now only the file name as we just changed directory
            remoteName = FileUtil.stripPath(name);
        }

        log.trace("Client retrieveFile: {}", remoteName);
        
        if (endpoint.getConfiguration().isStreamDownload()) {
            InputStream is = client.retrieveFileStream(remoteName); 
            target.setBody(is);
            exchange.getIn().setHeader(RemoteFileComponent.REMOTE_FILE_INPUT_STREAM, is);
            result = true;
        } else {
            os = new ByteArrayOutputStream();
            target.setBody(os);
            result = client.retrieveFile(remoteName, os);
        }

        // store client reply information after the operation
        exchange.getIn().setHeader(FtpConstants.FTP_REPLY_CODE, client.getReplyCode());
        exchange.getIn().setHeader(FtpConstants.FTP_REPLY_STRING, client.getReplyString());

        // change back to current directory
        if (endpoint.getConfiguration().isStepwise()) {
            changeCurrentDirectory(currentDir);
        }

    } catch (IOException e) {
        throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
    } finally {
        IOHelper.close(os, "retrieve: " + name, log);
    }

    return result;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:55,代码来源:FtpOperations.java

示例12: 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


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