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


Java FileUtil.isAbsolute方法代码示例

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


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

示例1: writeFile

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public void writeFile(Exchange exchange, String fileName) throws GenericFileOperationFailedException {
    // build directory if auto create is enabled
    if (endpoint.isAutoCreate()) {
        // we must normalize it (to avoid having both \ and / in the name which confuses java.io.File)
        String name = FileUtil.normalizePath(fileName);

        // use java.io.File to compute the file path
        File file = new File(name);
        String directory = file.getParent();
        boolean absolute = FileUtil.isAbsolute(file);
        if (directory != null) {
            if (!operations.buildDirectory(directory, absolute)) {
                log.debug("Cannot build directory [{}] (could be because of denied permissions)", directory);
            }
        }
    }

    // upload
    if (log.isTraceEnabled()) {
        log.trace("About to write [{}] to [{}] from exchange [{}]", new Object[]{fileName, getEndpoint(), exchange});
    }

    boolean success = operations.storeFile(fileName, exchange);
    if (!success) {
        throw new GenericFileOperationFailedException("Error writing file [" + fileName + "]");
    }
    log.debug("Wrote [{}] to [{}]", fileName, getEndpoint());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:GenericFileProducer.java

示例2: isAbsolute

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
protected boolean isAbsolute(String name) {
    return FileUtil.isAbsolute(new File(name));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:GenericFile.java

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

示例4: createConsumer

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public FileConsumer createConsumer(Processor processor) throws Exception {
    ObjectHelper.notNull(operations, "operations");
    ObjectHelper.notNull(file, "file");

    // auto create starting directory if needed
    if (!file.exists() && !file.isDirectory()) {
        if (isAutoCreate()) {
            log.debug("Creating non existing starting directory: {}", file);
            boolean absolute = FileUtil.isAbsolute(file);
            boolean created = operations.buildDirectory(file.getPath(), absolute);
            if (!created) {
                log.warn("Cannot auto create starting directory: {}", file);
            }
        } else if (isStartingDirectoryMustExist()) {
            throw new FileNotFoundException("Starting directory does not exist: " + file);
        }
    }

    FileConsumer result = newFileConsumer(processor, operations);

    if (isDelete() && getMove() != null) {
        throw new IllegalArgumentException("You cannot set both delete=true and move options");
    }

    // if noop=true then idempotent should also be configured
    if (isNoop() && !isIdempotentSet()) {
        log.info("Endpoint is configured with noop=true so forcing endpoint to be idempotent as well");
        setIdempotent(true);
    }

    // if idempotent and no repository set then create a default one
    if (isIdempotentSet() && isIdempotent() && idempotentRepository == null) {
        log.info("Using default memory based idempotent repository with cache max size: " + DEFAULT_IDEMPOTENT_CACHE_SIZE);
        idempotentRepository = MemoryIdempotentRepository.memoryIdempotentRepository(DEFAULT_IDEMPOTENT_CACHE_SIZE);
    }

    // set max messages per poll
    result.setMaxMessagesPerPoll(getMaxMessagesPerPoll());
    result.setEagerLimitMaxMessagesPerPoll(isEagerMaxMessagesPerPoll());

    configureConsumer(result);
    return result;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:44,代码来源:FileEndpoint.java

示例5: isAbsolute

import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
@Override
public boolean isAbsolute(String name) {
    // relative or absolute path?
    return FileUtil.isAbsolute(new File(name));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:6,代码来源:FileEndpoint.java


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