@Override public void onNodeDeletion() { String filePath = null; try { final String path = getRelativeFilePath(); if (path != null) { filePath = FileHelper.getFilePath(path); java.io.File toDelete = new java.io.File(filePath); if (toDelete.exists() && toDelete.isFile()) { toDelete.delete(); } } } catch (Throwable t) { logger.log( Level.WARNING, "Exception while trying to delete file {0}: {1}", new Object[] {filePath, t}); } }
public InputStream getInputStream() { final String path = getRelativeFilePath(); if (path != null) { final String filePath = FileHelper.getFilePath(path); FileInputStream fis = null; try { java.io.File fileOnDisk = new java.io.File(filePath); // Return file input stream and save checksum and size after closing fis = new FileInputStream(fileOnDisk); return fis; } catch (FileNotFoundException e) { logger.log(Level.FINE, "File not found: {0}", new Object[] {path}); if (fis != null) { try { fis.close(); } catch (IOException ignore) { } } } } return null; }
@Override public void afterCreation(SecurityContext securityContext) { try { final String filesPath = Services.getInstance().getConfigurationValue(Services.FILES_PATH); java.io.File fileOnDisk = new java.io.File(filesPath + "/" + getRelativeFilePath()); if (fileOnDisk.exists()) { return; } fileOnDisk.getParentFile().mkdirs(); try { fileOnDisk.createNewFile(); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not create file", ex); return; } setProperty(checksum, FileHelper.getChecksum(File.this)); setProperty(version, 0); long fileSize = FileHelper.getSize(File.this); if (fileSize > 0) { setProperty(size, fileSize); } } catch (FrameworkException ex) { logger.log(Level.SEVERE, "Could not create file", ex); } }
public OutputStream getOutputStream() { final String path = getRelativeFilePath(); if (path != null) { final String filePath = FileHelper.getFilePath(path); try { java.io.File fileOnDisk = new java.io.File(filePath); // Return file output stream and save checksum and size after closing FileOutputStream fos = new FileOutputStream(fileOnDisk) { @Override public void close() throws IOException { super.close(); try { setProperty(checksum, FileHelper.getChecksum(File.this)); setProperty(size, FileHelper.getSize(File.this)); } catch (FrameworkException ex) { logger.log( Level.SEVERE, "Could not determine or save checksum and size after closing file output stream", ex); } } }; return fos; } catch (FileNotFoundException e) { logger.log(Level.SEVERE, "File not found: {0}", new Object[] {path}); } } return null; }
@Override public String getPath() { return FileHelper.getFolderPath(this); }