public static final long getFreeSpace(File dir) { // Use JNI to find out the free space on this partition. long freeSpace = -1; try { Class<? extends File> c = dir.getClass(); Method m = c.getDeclaredMethod("getFreeSpace", new Class<?>[0]); if (m != null) { Long lFreeSpace = (Long) m.invoke(dir, new Object[0]); if (lFreeSpace != null) { freeSpace = lFreeSpace.longValue(); System.err.println( "Found free space on node's partition: on " + dir + " = " + SizeUtil.formatSize(freeSpace)); } } } catch (NoSuchMethodException e) { // Ignore freeSpace = -1; } catch (Throwable t) { System.err.println("Trying to access 1.6 getFreeSpace(), caught " + t); freeSpace = -1; } return freeSpace; }
@Override public void moveItem( final Repository repository, final File repositoryBaseDir, final ResourceStoreRequest from, final File fromTarget, final ResourceStoreRequest to, final File toTarget) throws ItemNotFoundException, UnsupportedStorageOperationException, LocalStorageException { if (fromTarget.exists()) { // create parents down to the file itself (this will make those if needed, otherwise return // silently) mkParentDirs(repository, toTarget); try { org.sonatype.nexus.util.FileUtils.move(fromTarget, toTarget); } catch (IOException e) { getLogger() .warn( "Unable to move item, falling back to copy+delete: " + toTarget.getPath(), getLogger().isDebugEnabled() ? e : null); if (fromTarget.isDirectory()) { try { FileUtils.copyDirectoryStructure(fromTarget, toTarget); } catch (IOException ioe) { throw new LocalStorageException("Error during moveItem", ioe); } } else if (fromTarget.isFile()) { try { FileUtils.copyFile(fromTarget, toTarget); } catch (IOException ioe) { throw new LocalStorageException("Error during moveItem", ioe); } } else { // TODO throw exception? getLogger().error("Unexpected item kind: " + toTarget.getClass()); } shredItem(repository, repositoryBaseDir, from, fromTarget); } } else { throw new ItemNotFoundException(from, repository); } }
public CSFileInputStream(File arg0) throws FileNotFoundException { super(arg0); if (!(arg0 instanceof CSFile)) throw new Error( "Must use CSFile. used " + arg0.getClass().getName() + " for " + arg0.getAbsolutePath()); }