Skip to Content
0
Former Member
Jun 24, 2010 at 05:25 AM

Error in Duplicate file Handling

16 Views

Hi All,

We want to avoid duplicate files in XI for that we used below code in UDF in mapping

try{

String processedFileDatabase = processedFile[0];

String sourceFileName;

DynamicConfiguration attrib = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey fileKey = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/File","FileName");

attrib.put(fileKey,attrib.get(fileKey));

sourceFileName = attrib.get(fileKey);

File fileDB=new File(processedFileDatabase);

if (!(fileDB.exists() && fileDB.canWrite() && fileDB.canRead())){

fileDB.createNewFile();

}

Vector fileNameList = new Vector();

BufferedReader br = null;

br = new BufferedReader(new FileReader(processedFileDatabase));

String name = new String();

//loop and read a line from the file as long as we dont get null

while ((name = br.readLine()) != null)

//add the read word to the wordList

fileNameList.add(name);

br.close();

boolean fileAlreadyProcessed = fileNameList.contains(sourceFileName);

if (!fileAlreadyProcessed) {

Writer output = new BufferedWriter(new FileWriter(new File(processedFileDatabase),true));

output.write(sourceFileName + "\r\n");

output.flush();

output.close();

}

result.addValue("" + !fileAlreadyProcessed);

}catch(java.io.IOException e){

e.printStackTrace();

}

But this is not working ..its unable to Map....

Plz help us in this regard,