/* * (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); } }