作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在读取 SWIFT 消息 (MT103) 并将其加载到数据库中。之后我需要删除该文件,以避免在下一个周期中进行第二次解析。但它接缝全范围不会自动关闭InputStream
解析消息后。如何关闭InputStream以便文件能够成功归档?当我尝试使用 FileUtils
存档文件时我收到错误:Failed to delete original file '\home\swift\991904100973103097.out' after copy to '\home\Outswift\991904100973103097.out'
public static void loadMessageInformationToDatabase(String sourceDir, File archiveDir) {
log.debug("Listening to Incoming SWIFT Messages");
File[] files = new File(sourceDir).listFiles();
log.debug("Found " + files.length + " SWIFT Files for Processing");
if (files.length > 0) {
for (int i = 0; i < files.length; i++) {
log.debug("Attepting to process file " + files[i].getAbsolutePath());
int swiftSerialNumner = 0;
try {
MtSwiftMessage msg = MtSwiftMessage.parse(files[i]);
String mtNumber = msg.getMessageType();
String receiver = msg.getReceiver();
String sender = msg.getSender();
byte[] message = IOUtils.toByteArray(new FileInputStream(files[i]));
String pde = msg.getPde();
String instructedCurrency = "";
double instructedAmount = 0.00;
String inOutIndicator = "";
if (msg.isIncoming()) {
inOutIndicator = "I";
} else if (msg.isOutgoing()) {
inOutIndicator = "O";
}
String senderReference = "";
if (mtNumber.equalsIgnoreCase("103")) {
MT103 model = MT103.parse(files[i]);
List<Field> fields = model.getFields();
for (Field field : fields) {
if (field.getName().equalsIgnoreCase("20")) {
senderReference = field.getValue();
}
if (field.getName().equalsIgnoreCase("33B")) {
instructedCurrency = field.getValue().substring(0, 3);
instructedAmount = Double.parseDouble(field.getValue().substring(3).replace(",", "."));
}
}
}
swiftSerialNumner = Swift.addSwiftMessage(mtNumber, receiver, message, "N", null, null, null, null, "S", "SYSTEM", new Date(), "Y", new Date(), "SYSTEM", new Date(), "SYSTEM", null, inOutIndicator, null, null, null, pde, "Y", receiver, sender, null, senderReference, null, instructedAmount, instructedCurrency, null, null, null, null, null, "N", "Y", "N", Gct.getBankId(), "Y");
if (swiftSerialNumner > 0) {
log.debug("File " + files[i].getAbsolutePath() + " Parsed Successfully");
if (Swift.isDuplicateReference(senderReference)) {
Swift.markSwiftMessageAsDuplicate(swiftSerialNumner);
log.warn("SWIFT Serial " + swiftSerialNumner + " Marked as Duplicate");
}
} else {
log.error("Error in Parsing File Name " + files[i].getAbsolutePath());
}
FileUtils.moveFileToDirectory(files[i], archiveDir, true);//Error comes on this line
log.debug("SWIFT File " + files[i] + " archived in " + archiveDir.getAbsolutePath());
} catch (IOException | NumberFormatException asd) {
log.error("SWIFT Processing Error: " + asd.getMessage());
}
}
}
}
最佳答案
试试这个:
FileInputStream fis = new FileInputStream(files[i])
byte[] message = IOUtils.toByteArray(fis);
并添加带有 fis 结尾的 finally 子句:
} catch (IOException | NumberFormatException asd) {
log.error("SWIFT Processing Error: " + asd.getMessage());
} finally {
fis.close()
}
关于java - 读取 Swift Message Prowide (WIFE) 后关闭 fileInputStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55607612/
我正在读取 SWIFT 消息 (MT103) 并将其加载到数据库中。之后我需要删除该文件,以避免在下一个周期中进行第二次解析。但它接缝全范围不会自动关闭InputStream解析消息后。如何关闭Inp
如何在 Prowide Core (WIFE) 中设置 MT518 swift 消息模型对象的方向。方向在消息应用程序头 block ( block 2)中指示。例如。{2:O518101316071
我正在解析一条快速的 MT564 消息,并且可以使用 getSequence() 获取所有序列(A、B、C、D、F),但每当我尝试获取序列 E 时,我都会得到 null,尽管事实上我正在解析的消息包含
我是一名优秀的程序员,十分优秀!