• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FileUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createPersistentConnectionFactory

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
private static ConnectionFactory createPersistentConnectionFactory(String options) {
        // using a unique broker name improves testing when running the entire test suite in the same JVM
        int id = counter.incrementAndGet();

        // use an unique data directory in target
        String dir = "target/activemq-data-" + id;

        // remove dir so its empty on startup
        FileUtil.removeDir(new File(dir));

        String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir;
        if (options != null) {
            url = url + "&" + options;
        }
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
        // optimize AMQ to be as fast as possible so unit testing is quicker
        connectionFactory.setCopyMessageOnSend(false);
        connectionFactory.setOptimizeAcknowledge(true);
        connectionFactory.setOptimizedMessageDispatch(true);
        connectionFactory.setAlwaysSessionAsync(false);
//        connectionFactory.setTrustAllPackages(true);
        return connectionFactory;
    }
 
开发者ID:eXcellme,项目名称:eds,代码行数:24,代码来源:CamelJmsTestHelper.java


示例2: fileOnlyNameExpression

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
public static Expression fileOnlyNameExpression() {
    return new ExpressionAdapter() {
        public Object evaluate(Exchange exchange) {
            String answer = exchange.getIn().getHeader(Exchange.FILE_NAME_ONLY, String.class);
            if (answer == null) {
                answer = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
                answer = FileUtil.stripPath(answer);
            }
            return answer;
        }

        @Override
        public String toString() {
            return "file:onlyname";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:ExpressionBuilder.java


示例3: renameFile

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
public boolean renameFile(String from, String to) throws GenericFileOperationFailedException {
    boolean renamed = false;
    File file = new File(from);
    File target = new File(to);
    try {
        if (endpoint.isRenameUsingCopy()) {
            renamed = FileUtil.renameFileUsingCopy(file, target);
        } else {
            renamed = FileUtil.renameFile(file, target, endpoint.isCopyAndDeleteOnRenameFail());
        }
    } catch (IOException e) {
        throw new GenericFileOperationFailedException("Error renaming file from " + from + " to " + to, e);
    }
    
    return renamed;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:FileOperations.java


示例4: buildFileEndpoint

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
protected GenericFileEndpoint<File> buildFileEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // the starting directory must be a static (not containing dynamic expressions)
    if (StringHelper.hasStartToken(remaining, "simple")) {
        throw new IllegalArgumentException("Invalid directory: " + remaining
                + ". Dynamic expressions with ${ } placeholders is not allowed."
                + " Use the fileName option to set the dynamic expression.");
    }

    File file = new File(remaining);

    FileEndpoint result = new FileEndpoint(uri, this);
    result.setFile(file);

    GenericFileConfiguration config = new GenericFileConfiguration();
    config.setDirectory(FileUtil.isAbsolute(file) ? file.getAbsolutePath() : file.getPath());
    result.setConfiguration(config);

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


示例5: configureMessage

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
/**
 * Configures the given message with the file which sets the body to the
 * file object.
 */
public void configureMessage(GenericFile<T> file, Message message) {
    message.setBody(file);

    if (flatten) {
        // when flatten the file name should not contain any paths
        message.setHeader(Exchange.FILE_NAME, file.getFileNameOnly());
    } else {
        // compute name to set on header that should be relative to starting directory
        String name = file.isAbsolute() ? file.getAbsoluteFilePath() : file.getRelativeFilePath();

        // skip leading endpoint configured directory
        String endpointPath = getConfiguration().getDirectory() + getFileSeparator();

        // need to normalize paths to ensure we can match using startsWith
        endpointPath = FileUtil.normalizePath(endpointPath);
        String copyOfName = FileUtil.normalizePath(name);
        if (ObjectHelper.isNotEmpty(endpointPath) && copyOfName.startsWith(endpointPath)) {
            name = name.substring(endpointPath.length());
        }

        // adjust filename
        message.setHeader(Exchange.FILE_NAME, name);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:GenericFileEndpoint.java


示例6: configureMoveOrPreMoveExpression

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
/**
 * Strategy to configure the move, preMove, or moveExisting option based on a String input.
 *
 * @param expression the original string input
 * @return configured string or the original if no modifications is needed
 */
protected String configureMoveOrPreMoveExpression(String expression) {
    // if the expression already have ${ } placeholders then pass it unmodified
    if (StringHelper.hasStartToken(expression, "simple")) {
        return expression;
    }

    // remove trailing slash
    expression = FileUtil.stripTrailingSeparator(expression);

    StringBuilder sb = new StringBuilder();

    // if relative then insert start with the parent folder
    if (!isAbsolute(expression)) {
        sb.append("${file:parent}");
        sb.append(getFileSeparator());
    }
    // insert the directory the end user provided
    sb.append(expression);
    // append only the filename (file:name can contain a relative path, so we must use onlyname)
    sb.append(getFileSeparator());
    sb.append("${file:onlyname}");

    return sb.toString();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:GenericFileEndpoint.java


示例7: acquireExclusiveReadLock

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
@Override
public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,
                                        GenericFile<File> file, Exchange exchange) throws Exception {

    if (!markerFile) {
        // if not using marker file then we assume acquired
        return true;
    }

    String lockFileName = getLockFileName(file);
    LOG.trace("Locking the file: {} using the lock file name: {}", file, lockFileName);

    // create a plain file as marker filer for locking (do not use FileLock)
    boolean acquired = FileUtil.createNewFile(new File(lockFileName));

    // store read-lock state
    exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_ACQUIRED), acquired);
    exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_NAME), lockFileName);

    return acquired;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MarkerFileExclusiveReadLockStrategy.java


示例8: doReleaseExclusiveReadLock

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
protected void doReleaseExclusiveReadLock(GenericFileOperations<File> operations,
                                          GenericFile<File> file, Exchange exchange) throws Exception {
    if (!markerFile) {
        // if not using marker file then nothing to release
        return;
    }

    boolean acquired = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_ACQUIRED), false, Boolean.class);

    // only release the file if camel get the lock before
    if (acquired) {
        String lockFileName = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_NAME), String.class);
        File lock = new File(lockFileName);

        if (lock.exists()) {
            LOG.trace("Unlocking file: {}", lockFileName);
            boolean deleted = FileUtil.deleteFile(lock);
            LOG.trace("Lock file: {} was deleted: {}", lockFileName, deleted);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MarkerFileExclusiveReadLockStrategy.java


示例9: testFile

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
public void testFile() throws Exception {
    assertExpression("${file:ext}", "txt");
    assertExpression("${file:name.ext}", "txt");
    assertExpression("${file:name.ext.single}", "txt");
    assertExpression("${file:name}", "test" + File.separator + file.getName());
    assertExpression("${file:name.noext}", "test" + File.separator + "hello");
    assertExpression("${file:name.noext.single}", "test" + File.separator + "hello");
    assertExpression("${file:onlyname}", file.getName());
    assertExpression("${file:onlyname.noext}", "hello");
    assertExpression("${file:onlyname.noext.single}", "hello");
    assertExpression("${file:parent}", file.getParent());
    assertExpression("${file:path}", file.getPath());
    assertExpression("${file:absolute}", FileUtil.isAbsolute(file));
    assertExpression("${file:absolute.path}", file.getAbsolutePath());
    assertExpression("${file:length}", file.length());
    assertExpression("${file:size}", file.length());

    // modified is a long object
    Long modified = SimpleLanguage.simple("${file:modified}").evaluate(exchange, Long.class);
    assertEquals(file.lastModified(), modified.longValue());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:FileLanguageTest.java


示例10: testFileUsingAlternativeStartToken

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
public void testFileUsingAlternativeStartToken() throws Exception {
    assertExpression("$simple{file:ext}", "txt");
    assertExpression("$simple{file:name.ext}", "txt");
    assertExpression("$simple{file:name}", "test" + File.separator + file.getName());
    assertExpression("$simple{file:name.noext}", "test" + File.separator + "hello");
    assertExpression("$simple{file:onlyname}", file.getName());
    assertExpression("$simple{file:onlyname.noext}", "hello");
    assertExpression("$simple{file:parent}", file.getParent());
    assertExpression("$simple{file:path}", file.getPath());
    assertExpression("$simple{file:absolute}", FileUtil.isAbsolute(file));
    assertExpression("$simple{file:absolute.path}", file.getAbsolutePath());
    assertExpression("$simple{file:length}", file.length());
    assertExpression("$simple{file:size}", file.length());

    // modified is a long object
    long modified = SimpleLanguage.simple("${file:modified}").evaluate(exchange, long.class);
    assertEquals(file.lastModified(), modified);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:FileLanguageTest.java


示例11: checkImage

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
protected void checkImage(MockEndpoint mock, int height, int width, String type, BarcodeFormat format) throws IOException {
    Exchange ex = mock.getReceivedExchanges().get(0);
    File in = ex.getIn().getBody(File.class);
    FileInputStream fis = new FileInputStream(in);

    // check image
    BufferedImage i = ImageIO.read(fis);
    IOHelper.close(fis);

    assertTrue(height >= i.getHeight());
    assertTrue(width >= i.getWidth());
    this.checkType(in, type);
    this.checkFormat(in, format);

    FileUtil.deleteFile(in);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:BarcodeTestBase.java


示例12: pollDirectory

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
@Override
protected boolean pollDirectory(String fileName, List<GenericFile<ChannelSftp.LsEntry>> fileList, int depth) {
    String currentDir = null;
    if (isStepwise()) {
        // must remember current dir so we stay in that directory after the poll
        currentDir = operations.getCurrentDirectory();
    }

    // strip trailing slash
    fileName = FileUtil.stripTrailingSeparator(fileName);

    boolean answer = doPollDirectory(fileName, null, fileList, depth);
    if (currentDir != null) {
        operations.changeCurrentDirectory(currentDir);
    }

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


示例13: pollDirectory

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
@Override
protected boolean pollDirectory(String fileName, List<GenericFile<FTPFile>> fileList, int depth) {
    String currentDir = null;
    if (isStepwise()) {
        // must remember current dir so we stay in that directory after the poll
        currentDir = operations.getCurrentDirectory();
    }

    // strip trailing slash
    fileName = FileUtil.stripTrailingSeparator(fileName);

    boolean answer = doPollDirectory(fileName, null, fileList, depth);
    if (currentDir != null) {
        operations.changeCurrentDirectory(currentDir);
    }

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


示例14: testSftpTempFileNoStartingPath

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
@Test
public void testSftpTempFileNoStartingPath() throws Exception {
    if (!canTest()) {
        return;
    }

    template.sendBodyAndHeader("sftp://localhost:" + getPort()
            + "/?username=admin&password=admin&tempFileName=temp-${file:name}", "Hello World", Exchange.FILE_NAME, "hello.txt");

    File file = new File("hello.txt");
    assertTrue("File should exist: " + file, file.exists());
    assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, file));

    // delete file when we are done testing
    FileUtil.deleteFile(file);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:SftpProduceTempFileTest.java


示例15: createPersistentConnectionFactory

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
public static ConnectionFactory createPersistentConnectionFactory(String options) {
    // using a unique broker name improves testing when running the entire test suite in the same JVM
    int id = counter.incrementAndGet();

    // use an unique data directory in target
    String dir = "target/activemq-data-" + id;

    // remove dir so its empty on startup
    FileUtil.removeDir(new File(dir));

    String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir;
    if (options != null) {
        url = url + "&" + options;
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
    // optimize AMQ to be as fast as possible so unit testing is quicker
    connectionFactory.setCopyMessageOnSend(false);
    connectionFactory.setOptimizeAcknowledge(true);
    connectionFactory.setOptimizedMessageDispatch(true);
    connectionFactory.setAlwaysSessionAsync(false);
    connectionFactory.setTrustAllPackages(true);
    return connectionFactory;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:CamelJmsTestHelper.java


示例16: setUp

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void setUp() throws Exception {
    deleteDirectory("target/fileidempotent");
    createDirectory("target/fileidempotent");

    File file = new File("target/fileidempotent/.filestore.dat");
    FileOutputStream fos = new FileOutputStream(file);

    // insert existing name to the file repo, so we should skip this file
    String name = FileUtil.normalizePath(new File("target/fileidempotent/report.txt").getAbsolutePath());
    fos.write(name.getBytes());
    fos.write(LS.getBytes());

    fos.close();

    super.setUp();

    // add a file to the repo
    repo = context.getRegistry().lookupByNameAndType("fileStore", IdempotentRepository.class);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:FileConsumerIdempotentLoadStoreTest.java


示例17: testIdempotentLoad

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
public void testIdempotentLoad() throws Exception {
    // send two files (report.txt exists already in idempotent repo)
    template.sendBodyAndHeader("file://target/fileidempotent/", "Hello World", Exchange.FILE_NAME, "report.txt");
    template.sendBodyAndHeader("file://target/fileidempotent/", "Bye World", Exchange.FILE_NAME, "report2.txt");

    // consume the file the first time
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Bye World");

    assertMockEndpointsSatisfied();
    // wait for the exchange to be done, as it only append to idempotent repo after success
    oneExchangeDone.matchesMockWaitTime();

    String name = FileUtil.normalizePath(new File("target/fileidempotent/report.txt").getAbsolutePath());
    assertTrue("Should contain file: " + name, repo.contains(name));

    String name2 = FileUtil.normalizePath(new File("target/fileidempotent/report2.txt").getAbsolutePath());
    assertTrue("Should contain file: " + name2, repo.contains(name2));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:FileConsumerIdempotentLoadStoreTest.java


示例18: buildUrl

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
private static String buildUrl(String scheme, String hostname, Object port, String path, String uri) {
    // build together from component level and given uri that has additional context path to append
    String build = scheme + "://" + hostname;
    if (port != null) {
        build += ":" + port;
    }
    if (path != null) {
        build = FileUtil.stripTrailingSeparator(build);
        build += "/" + path;
    }

    String query = null;
    if (uri != null && uri.contains("?")) {
        query = StringHelper.after(uri, "?");
        uri = StringHelper.before(uri, "?");
        uri = StringHelper.after(uri, "://");
    }

    // remaining is to be appending
    if (uri != null) {
        build = FileUtil.stripTrailingSeparator(build);
        build += "/" + uri;
    }

    if (query != null) {
        build += "?" + query;
    }
    return build;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:30,代码来源:HttpComponent.java


示例19: cleanUpTempFile

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
void cleanUpTempFile() {
    // cleanup temporary file
    try {
        if (tempFile != null) {
            FileUtil.deleteFile(tempFile);
            tempFile = null;
        }
    } catch (Exception e) {
        LOG.warn("Error deleting temporary cache file: " + tempFile + ". This exception will be ignored.", e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:FileInputStreamCache.java


示例20: appendToStore

import org.apache.camel.util.FileUtil; //导入依赖的package包/类
/**
 * Appends the given message id to the file store
 *
 * @param messageId  the message id
 */
protected void appendToStore(final String messageId) {
    LOG.debug("Appending {} to idempotent filestore: {}", messageId, fileStore);
    FileOutputStream fos = null;
    try {
        // create store parent directory if missing
        File storeParentDirectory = fileStore.getParentFile();
        if (storeParentDirectory != null && !storeParentDirectory.exists()) {
            LOG.info("Parent directory of file store {} doesn't exist. Creating.", fileStore);
            if (fileStore.getParentFile().mkdirs()) {
                LOG.info("Parent directory of file store {} successfully created.", fileStore);
            } else {
                LOG.warn("Parent directory of file store {} cannot be created.", fileStore);
            }
        }
        // create store if missing
        if (!fileStore.exists()) {
            FileUtil.createNewFile(fileStore);
        }
        // append to store
        fos = new FileOutputStream(fileStore, true);
        fos.write(messageId.getBytes());
        fos.write(STORE_DELIMITER.getBytes());
    } catch (IOException e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    } finally {
        IOHelper.close(fos, "Appending to file idempotent repository", LOG);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:FileIdempotentRepository.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Service类代码示例发布时间:2022-05-22
下一篇:
Java ResourceBundleWrapper类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap