/*
  * (non-Javadoc)
  *
  * @see org.abstracthorizon.proximity.storage.Storage#retrieveItem(java.lang.String, boolean)
  */
 public Item retrieveItem(String path, boolean propsOnly)
     throws ItemNotFoundException, StorageException {
   logger.debug("Retrieving {} from storage directory {}", path, getStorageBaseDir());
   try {
     ItemProperties properties = loadItemProperties(path);
     Item result = new Item();
     result.setProperties(properties);
     if (!propsOnly) {
       File target = new File(getStorageBaseDir(), path);
       if (target.isFile()) {
         result.setStream(new LazyFileInputStream(target));
         properties.setSize(target.length());
         properties.setLastModified(new Date(target.lastModified()));
       }
     }
     return result;
   } catch (FileNotFoundException ex) {
     throw new ItemNotFoundException(
         "FileNotFound in FS storage [" + getStorageBaseDir() + "] for path [" + path + "]");
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see org.abstracthorizon.proximity.storage.local.AbstractLocalStorage#storeItem(org.abstracthorizon.proximity.Item)
  */
 public void storeItem(Item item) throws StorageException {
   if (!item.getProperties().isFile()) {
     throw new IllegalArgumentException("Only files can be stored!");
   }
   logger.debug(
       "Storing item in [{}] in storage directory {}",
       item.getProperties().getPath(),
       getStorageBaseDir());
   try {
     if (item.getStream() != null) {
       File file = new File(getStorageBaseDir(), item.getProperties().getPath());
       file.getParentFile().mkdirs();
       FileOutputStream os = new FileOutputStream(file);
       try {
         IOUtils.copy(item.getStream(), os);
         item.getStream().close();
         os.flush();
       } finally {
         os.close();
       }
       item.setStream(new FileInputStream(file));
       file.setLastModified(item.getProperties().getLastModified().getTime());
       if (isMetadataAware()) {
         item.getProperties()
             .putAllMetadata(
                 getProxiedItemPropertiesFactory()
                     .expandItemProperties(item.getProperties().getPath(), file, false)
                     .getAllMetadata());
         storeItemProperties(item.getProperties());
       }
     }
   } catch (IOException ex) {
     throw new StorageException("IOException in FS storage " + getStorageBaseDir(), ex);
   }
 }