void readBinary() { // A file lock will be held on Windows OS when reading try (final InputStream fis = new BufferedInputStream(Files.newInputStream(path, StandardOpenOption.READ))) { readWriteLock.writeLock().lock(); final XStream xstream = configureXStream(new XStreamJVM9(new StoredObjectReflectionProvider(objects), new BinaryStreamDriver())); try (final ObjectInputStream in = xstream.createObjectInputStream(fis)) { in.readObject(); } } catch (final IOException | ClassNotFoundException e) { Logger.getLogger(BinaryContainer.class.getName()).log(Level.SEVERE, null, e); } finally { if (!acquireFileLock()) { // lock the file on open Logger.getLogger(BinaryContainer.class.getName()).severe("Could not acquire the file lock"); } readWriteLock.writeLock().unlock(); } } }
BinaryStreamDriver bsd = new BinaryStreamDriver(); XStream xstream = new XStreamJVM9(new PureJavaReflectionProvider(), bsd); BinaryStreamDriver bsd = new BinaryStreamDriver(); XStream xstream = new XStreamJVM9(new PureJavaReflectionProvider(), bsd);