+ final File newFile = new File(this.path, filename);
+ FileChannel channel = new RandomAccessFile(newFile, READ).getChannel();
+
+ FileLock lock = null;
+ final Stopwatch stopwatch = Stopwatch.createStarted();
+ while (lock == null || stopwatch.elapsed(TimeUnit.SECONDS) > TIMEOUT_SECONDS) {
+ try {
+ lock = channel.tryLock();
+ } catch (final IllegalStateException e) {
+ //Ignore
+ }
+ if (lock == null) {
+ try {
+ Thread.sleep(100L);
+ } catch (InterruptedException e) {
+ LOG.warn("Failed to lock xml", e);
+ }
+ }
+ }
+
+ try (InputStream resourceAsStream = new FileInputStream(newFile)) {