本文整理汇总了Java中org.apache.camel.util.FileUtil类的典型用法代码示例。如果您正苦于以下问题:Java FileUtil类的具体用法?Java FileUtil怎么用?Java FileUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileUtil类属于org.apache.camel.util包,在下文中一共展示了FileUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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";
}
};
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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;
}
示例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);
}
}
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}