JulImportCallable extends AbstractProgressingCallable<Long> { @Override @SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.CloseResource"}) public Long call() throws Exception { if(!inputFile.isFile()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a file!"); } if(!inputFile.canRead()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a readable!"); } long fileSize = inputFile.length(); setNumberOfSteps(fileSize); InputStream fis = Files.newInputStream(inputFile.toPath()); CountingInputStream cis = new CountingInputStream(fis); String fileName=inputFile.getName().toLowerCase(Locale.US); XMLStreamReader xmlStreamReader; Reader reader; if(fileName.endsWith(".gz")) { reader = new InputStreamReader(new GZIPInputStream(cis), StandardCharsets.UTF_8); } else { reader = new InputStreamReader(cis, StandardCharsets.UTF_8); } xmlStreamReader = XML_INPUT_FACTORY.createXMLStreamReader(new ReplaceInvalidXmlCharacterReader(reader)); for(;;) { try { LoggingEvent event = loggingEventReader.read(xmlStreamReader); setCurrentStep(cis.getByteCount()); if(event == null) { break; } result++; EventWrapper<LoggingEvent> wrapper = new EventWrapper<>(); wrapper.setEvent(event); SourceIdentifier sourceIdentifier = new SourceIdentifier(inputFile.getAbsolutePath()); EventIdentifier eventId = new EventIdentifier(sourceIdentifier, result); wrapper.setEventIdentifier(eventId); buffer.add(wrapper); } catch(XMLStreamException ex) { if(logger.isWarnEnabled()) logger.warn("Exception while importing...", ex); } } return result; } JulImportCallable(File inputFile, AppendOperation<EventWrapper<LoggingEvent>> buffer); AppendOperation<EventWrapper<LoggingEvent>> getBuffer(); @SuppressWarnings("unused") File getInputFile(); @Override @SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.CloseResource"}) Long call();  }
@Test public void example() throws Exception { createTempFile("/testcases/log.xml"); AppendOpStub buffer = new AppendOpStub(); JulImportCallable instance = new JulImportCallable(inputFile, buffer); long result = instance.call(); if(logger.isInfoEnabled()) logger.info("Call returned {}.", result); if(logger.isDebugEnabled()) logger.debug("Appended events: {}", buffer.getList()); assertEquals(3, result); assertEquals(3, buffer.getList().size()); }