我正在解决与您的问题非常相似的问题,我找不到任何开源解决方案,因此我正在尝试自己制定一个解决方案。这就是我想出的。
我认为您应该将 inputSources 和 outputSources 表示为不同的东西,例如
public interface Input{
abstract InputStream getFileInputStream();
abstract String getStreamId();
}
//You can have differen implementation of this interface (1 for ftp, 1 for local files, 1 for Blob on db etc)
public interface Output{
abstract OutputStream getOutputStream();
abstract String getStreamId();
}
//You can have differen implementation of this interface (1 for ftp, 1 for local files, 1 for mailing the file etc)
那么你应该有一个运动来描述哪个输入应该去哪个输出。
class Movement{
String inputId;
String outputId;
}
描述要制作的运动列表的类。
class MovementDescriptor{
public addMovement(Movement a);
public Movement[] getAllMovements();
}
然后是一个自己执行工作的类。
class FileMover{
HashMap<String,Input> inputRegistry;
HashMap<String,Output> outputRegistry;
addInputToRegistry(Input a ){
inputRegistry.put(a.getId(),a);
}
addOutputToRegistry(Output a){
outputRegistry.put(a.getId(),a);
}
transferFiles(MovementDescriptor movementDescriptor){
Movement[] movements =movementDescriptor.getAllMovements();
foreach (Movement movement: movements){
//get the input Id
//find it in the registry and retrieve the associated InputStream
//get the output Id
//find it in the registry and retrieve the associated OutputStream
//copy the stream from the input to the output (you may want to use a temporary file in between)
}
}
}
使用它的代码将像这样运行:
FileMover fm=new FileMover();
//Register your sources and your destinations
fm.addInputToRegistry(input);
fm.addOutputToRegistry(output)
// each time you have to make a movement create a MovementDescriptor and call
fm.transferFiles(movementDescriptor)
如果您想通过邮件交流我们对该主题的看法,请发送电子邮件至(我的昵称)@gmail dot com。
注意:代码只是一个草图:-)