`
xfxlch
  • 浏览: 167427 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

CamelJmsToFileDemo

阅读更多


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileConverter;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ssgx.calypso.processor.CompareProcessor;

public class CamelJmsToFileDemo {

public CamelJmsToFileDemo() {
}

private static int m = 0;
static Logger LOG = LoggerFactory.getLogger(CamelJmsToFileDemo.class);

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
//只处理.txt后缀结尾的文件
from("file://test1?include=.*\\.txt&delay=30000").to("file://test");
from("file://test2?include=.*\\.txt&delay=30000").to("file://test");
}
});
context.start();
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
Thread.sleep(5000);
File file = new File("test");
System.out.println(" path=" + file.getAbsolutePath());

String[] strs = file.list();
InputStream is = new FileInputStream(new File("fileList/fileList.txt"));
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
String temp = null;
boolean all = true;//all file is ready
while ((temp = reader.readLine()) != null) {
System.out.println("neirong:" + temp);
for (int i = 0; i < strs.length; i++) {
System.out.println("strs[i]:" + strs[i]);
if (temp.equals(strs[i])) {
break;
}
if (temp != strs[i] && i == strs.length - 1) {
all = false;
}
}
}
System.out.println("all:" + all);
if (all) {
from("file://test").process(new CompareProcessor());
}
}
});
// context.addRoutes(new TimerRouteBuilder());
Thread.sleep(5000);

context.stop();
}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics