InputStream オブジェクトを使用して、ファイルの Md5 を計算しています。ストリームをマークします 後でストリームをリセットします。ただし、大きなファイルの場合、次の例外が発生します...
inStreamLatestFile.mark(0);
checkSumCalculated = MD5CheckSumCalculator.calculateMD5CheckSum(inStreamLatestFile);
inStreamLatestFile.reset();
例外
.Md5ValidationAggrStrat ||**Error in calculating checksum:: java.io.IOException: Resetting to invalid mark**
||java.io.IOException: Resetting to invalid mark
||at java.io.BufferedInputStream.reset(BufferedInputStream.java:437)
||at com.amadeus.apt.ib.modules.func.map.camel.strategy.Md5ValidationAggrStrategy.aggregate(Md5ValidationAggrStrategy.java:81)
||at org.apache.camel.processor.aggregate.AggregateProcessor.onAggregation(AggregateProcessor.java:365)
||at org.apache.camel.processor.aggregate.AggregateProcessor.doAggregation(AggregateProcessor.java:245)
||at org.apache.camel.processor.aggregate.AggregateProcessor.process(AggregateProcessor.java:201)
||at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
||at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
ストリームを閉じて、この方法で再度開いてみました..次のようにいくつかの例外を取得するためだけに::
try {
inStreamLatestFile= ExchangeHelper.getMandatoryInBody(
oldExchange, InputStream.class);
//inStreamLatestFile.mark(0);
checkSumCalculated = MD5CheckSumCalculator.calculateMD5CheckSum(inStreamLatestFile);
//closing the inputStream of the latest file
if(inStreamLatestFile != null){
try {
inStreamLatestFile.close();
} catch (IOException e) {
logger.error("Error occurred in closing the stream :: "+ e.getMessage());
}
}
tempInputStream= ExchangeHelper.getMandatoryInBody(
oldExchange, InputStream.class);
oldExchange.getIn().setBody(tempInputStream);
ただし、新しく取得した InputStream を再利用しようとすると、次の例外が発生します。
caught: java.io.IOException: Stream closed: java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162)