LJL-Futures-v1/solutions/001_creating_futures/src/main/java/com/lightbend/futures/FileBasedObjectStore.java
/**
     * Reads an object from the file store.
     * @param id - The ID of the object
     * @return The object if it exists or empty if it does not.
     */
Reads an object from the file store.
@param id - The ID of the object
@return The object if it exists or empty if it does not.
Reads an object from the file store . @param id - The ID of the object @return The object if it exists or empty if it does not .
@Override
    public Optional<Object> read(UUID id) {
        lock.readLock().lock();
        File file = new File(storeFolder, id.toString());
        Optional<Object> result;
        try (
            FileInputStream fileIn = new FileInputStream(file);
            ObjectInputStream in = new ObjectInputStream(fileIn)
        ) {
            result = Optional.ofNullable(in.readObject());
        } catch ( IOException | ClassNotFoundException ex) {
            result = Optional.empty();
        } finally {
            lock.readLock().unlock();
        }
        return result;
    }
@ Override public Optional < Object > read ( UUID id ) { lock . readLock ( ) . lock ( ) ; File file = new File ( storeFolder , id . toString ( ) ) ; Optional < Object > result ; try ( FileInputStream fileIn = new FileInputStream ( file ) ; ObjectInputStream in = new ObjectInputStream ( fileIn ) ) { result = Optional . ofNullable ( in . readObject ( ) ) ; } catch ( IOException | ClassNotFoundException ex ) { result = Optional . empty ( ) ; } finally { lock . readLock ( ) . unlock ( ) ; } return result ; }
Reads an object from the file store.
Reads an object from the file store .