List of usage examples for org.apache.commons.io FileUtils sizeOfDirectory
public static long sizeOfDirectory(File directory)
From source file:com.talis.entity.db.EntityDatabasePerfTestBase.java
private void testClearingSingleGraph(int graphs, int stmtsPerGraph) throws EntityDatabaseException { int stmtsPerSubject = 20; int subjectCount = Math.round(stmtsPerGraph / stmtsPerSubject); long start = System.currentTimeMillis(); db.begin();/* w w w . j a v a 2 s .co m*/ int quadCount = 0; for (int i = 0; i < graphs; i++) { Node thisGraph = Node.createURI(graph.getURI() + "/" + i); for (int j = 0; j < subjectCount; j++) { Node thisSubject = Node.createURI(subject.getURI() + "/" + i + "/" + j); db.put(thisSubject, thisGraph, getQuads(thisGraph, thisSubject, stmtsPerSubject)); quadCount += stmtsPerSubject; } } db.commit(); System.out.println(String.format("Populated %s graphs (%s total statements) in %s ms", graphs, quadCount, (System.currentTimeMillis() - start))); int iter = Math.round(graphs / 4); Set<Node> deleted = new HashSet<Node>(); Random r = new Random(); start = System.currentTimeMillis(); while (deleted.size() < iter) { Node thisGraph = Node.createURI(graph.getURI() + "/" + r.nextInt(graphs)); if (!deleted.contains(thisGraph)) { db.deleteGraph(thisGraph); deleted.add(thisGraph); } } long end = System.currentTimeMillis(); long duration = end - start; System.out.println(String.format("Iterations: %s, Total: %s, PerOp: %s", iter, duration, (double) ((double) duration / (double) iter))); long size = FileUtils.sizeOfDirectory(tmpDir.getRoot()); System.out.println(String.format("Size on disk : %s (%s)", FileUtils.byteCountToDisplaySize(size), size)); }
From source file:alluxio.cli.validation.StorageSpaceValidationTask.java
private boolean addDirectoryInfo(String path, long quota, Map<String, MountedStorage> storageMap) throws IOException { File file = new File(path); if (!file.exists()) { System.err.format("Path %s does not exist.%n", path); return false; }/*from w ww . java2 s . c om*/ if (!file.isDirectory()) { System.err.format("Path %s is not a valid directory.%n", path); return false; } long directorySize = FileUtils.sizeOfDirectory(file); // gets mounted FileStore that backs the directory of the given path FileStore store = Files.getFileStore(Paths.get(path)); MountedStorage storage = storageMap.get(store.name()); if (storage == null) { storage = new MountedStorage(store); storageMap.put(store.name(), storage); } storage.addDirectoryInfo(path, quota, directorySize); return true; }
From source file:com.ssn.listener.SSNHiveAlbumSelectionListner.java
@Override public void valueChanged(TreeSelectionEvent e) { iT = 0;//from w ww . j a va2 s . c o m dT = 0; DefaultMutableTreeNode node = treeHelper.getTreeNode(e.getPath()); List hiveFiles = new ArrayList(); if (this.form.getHiveTree() != null) { this.form.getHiveTree().clearSelection(); } this.form.setCursor(new Cursor(Cursor.WAIT_CURSOR)); SSNFileNode fnode = null; try { if (((SSNIconData) node.getUserObject()).getObject() instanceof SSNFileNode) { fnode = (SSNFileNode) ((SSNIconData) node.getUserObject()).getObject(); } } catch (ClassCastException ee) { logger.error(ee); this.form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } getAlbumMedia(form.getHomeModel().getLoggedInUserAccessToken(), 1, fileTree.hiveAlbumMap.get(fnode.getFile().getName())); /** * ******* * */ if (fnode != null) { if (fileTree.m_display.getText() != null && !fileTree.m_display.getText().equals("viewAllAlbums") && !fileTree.m_display.getText().equals("instagramMedia") && !fileTree.m_display.getText().equals("tagUnTaggedMedia")) { fileTree.m_display.setText(fnode.getFile().getAbsolutePath()); } if (fnode.getFile().isDirectory()) { this.fileTree.setSelectedFolder(fnode.getFile().getName()); getSSNMediaFolderProperties(fnode.getFile().getPath()); File[] file = fnode.getFile().listFiles(); for (File f : file) { if (f.isFile()) { hiveFiles.add(f.getName()); } else { } } } if (hiveFiles != null && hiveFiles.size() > 0) { createCompontents(fnode.getFile().getAbsolutePath(), form, true); } else { createCompontents(fnode.getFile().getAbsolutePath(), form, false); } } else { SSNHelper.toggleDeleteAndShareImages(false, form); String path = SSNHelper.getSsnHiveDirPath(); path = SSNHelper.getSsnTempDirPath(); form.getFileNamesToBeDeleted().clear(); getSSNMediaFolderProperties(path); if (fileTree.m_display.getText() != null && !fileTree.m_display.getText().equals("viewAllAlbums") && !fileTree.m_display.getText().equals("instagramMedia") && !fileTree.m_display.getText().equals("tagUnTaggedMedia")) { fileTree.m_display.setText(path); } getForm().ssnFileExplorer.m_tree.setSelectionRow(1); long size = FileUtils.sizeOfDirectory(new File(path)); if (size > 0) { File file1 = new File(path); if (fileTree.m_display.getText() != null && !fileTree.m_display.getText().equals("viewAllAlbums") && !fileTree.m_display.getText().equals("instagramMedia") && !fileTree.m_display.getText().equals("tagUnTaggedMedia")) { fileTree.m_display.setText(file1.getAbsolutePath()); } //just copied from above if block if (file1.isDirectory()) { this.form.setCurrentSelectedFile(null); fileTree.setSelectedFolder(file1.getName()); File[] file = file1.listFiles(); for (File f : file) { if (f.isFile()) { hiveFiles.add(f.getName()); } else { } } } if (hiveFiles != null && hiveFiles.size() > 0) { createCompontents(file1.getAbsolutePath(), form, true); } else { createCompontents(file1.getAbsolutePath(), form, false); } } else { // show welcome screen addWelcomeIcons(); } this.form.getSsnHomeCenterMainPanel().revalidate(); this.form.getSsnHomeCenterMainPanel().repaint(); this.form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } this.form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
From source file:helpers.Methods.java
/** * This method will calculate size of files inside a folder. It will not * calculate recursively.//from ww w. j a va2 s .c o m * * @param Directory The path of directory. * @return Size of all elements in long or 0 if security restrictions occur * or -1 if the size is longer than {@link Long#MAX_VALUE}. */ public static synchronized long getFolderSize(String Directory) { return FileUtils.sizeOfDirectory(new File(Directory)); }
From source file:com.vvote.verifierlibrary.utils.io.IOUtils.java
/** * Utility class to extract a zip file//from w ww .j a va2 s . c om * * @param filepath * @return the location of the extract zip file * @throws IOException */ public static String extractZipFile(String filepath) throws IOException { if (IOUtils.checkExtension(FileType.ZIP, filepath)) { try (ZipFile zipFile = new ZipFile(filepath)) { // files in zip file Enumeration<? extends ZipEntry> entries = zipFile.entries(); // current zip directory File zipDirectory = new File(filepath); // output directory - doesn't include the .zip extension File outputDirectory = new File( IOUtils.join(zipDirectory.getParent(), IOUtils.getFileNameWithoutExtension(filepath))); // make directory if not exists if (!outputDirectory.exists()) { outputDirectory.mkdir(); } InputStream is = null; FileOutputStream fos = null; byte[] bytes = null; int length = 0; // loop over each file in zip file while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); String entryName = zipEntry.getName(); // current output file File file = new File(IOUtils.join(outputDirectory.getPath(), entryName)); File currentOutputFile = new File(getFilePathWithoutExtension(file.getPath())); if (currentOutputFile.exists()) { if (getFileNameWithoutExtension(entryName) .contains(CommitFileNames.WBB_UPLOAD.getFileName())) { try (ZipFile currentZipFile = new ZipFile(file)) { Enumeration<? extends ZipEntry> currentZipEntries = currentZipFile.entries(); long currentUncompressedZipSize = currentZipEntries.nextElement().getSize(); long currentDirectorySize = FileUtils.sizeOfDirectory(currentOutputFile); if (currentUncompressedZipSize == currentDirectorySize) { continue; } } } } // if directory make it if (entryName.endsWith("/")) { file.mkdirs(); } else { // write current input zip file to output location is = zipFile.getInputStream(zipEntry); fos = new FileOutputStream(file); bytes = new byte[1024]; while ((length = is.read(bytes)) >= 0) { fos.write(bytes, 0, length); } is.close(); fos.close(); } } return outputDirectory.getPath(); } } logger.error("Provided filepath: {} does not point to a valid zip file", filepath); throw new IOException("Provided filepath: " + filepath + " does not point to a valid zip file"); }
From source file:desktopsearch.WatchDir.java
private void UpdateDB(String Event, Path FullLocation) throws SQLException, IOException { File file = new File(FullLocation.toString()); String path = file.getParent(); String Name = file.getName(); if (Name.contains("'")) { Name = Name.replace("'", "''"); }/*from w w w. j a va2s .c o m*/ if (path.contains("'")) { path = path.replace("'", "''"); } if (Event.equals("ENTRY_CREATE") && file.exists()) { FileTime LastModifiedTime = Files.getLastModifiedTime(FullLocation); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(LastModifiedTime.toMillis()); String Query; if (file.isFile()) { String Type = FilenameUtils.getExtension(FullLocation.toString()); if (Type.endsWith("~") || Type.equals("")) { Type = "Text"; } Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','" + Type + "','" + calendar.getTime() + "'," + (file.length() / 1024) + ");"; } else if (!Files.isSymbolicLink(FullLocation)) { long size = FileUtils.sizeOfDirectory(file); Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','FOLDER','" + calendar.getTime() + "'," + size + ");"; } else { Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','LINK','" + calendar.getTime() + "',0);"; } statement.executeUpdate(Query); } else if (Event.equals("ENTRY_MODIFY")) { System.out.println(path + "/" + Name); FileTime LastModifiedTime = Files.getLastModifiedTime(FullLocation); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(LastModifiedTime.toMillis()); String Query = "UPDATE FileInfo SET LastModified='" + calendar.getTime() + "' WHERE FileLocation='" + path + "' and FileName='" + Name + "';"; System.out.println(Query); statement.executeUpdate(Query); } else if (Event.equals("ENTRY_DELETE")) { String Query = "DELETE FROM FileInfo WHERE FileLocation = '" + path + "' AND FileName = '" + Name + "';"; statement.executeUpdate(Query); } connection.commit(); }
From source file:com.talis.entity.db.EntityDatabasePerfTestBase.java
@Test public void benchmarkRoundTripping() throws Exception { System.out.println("Round trip quads"); int iter = 10000; db.begin();//from w ww .ja v a 2s. c o m long start = System.currentTimeMillis(); for (int i = 0; i < iter; i++) { db.put(subject, graph, quads); db.get(subject); } db.commit(); long end = System.currentTimeMillis(); long duration = end - start; System.out.println(String.format("Iterations: %s, Total: %s, PerOp: %s", iter, duration, (double) ((double) duration / (double) iter))); long size = FileUtils.sizeOfDirectory(tmpDir.getRoot()); System.out.println(String.format("Size on disk : %s (%s)", FileUtils.byteCountToDisplaySize(size), size)); }
From source file:com.servoy.extension.install.CopyZipEntryImporter.java
protected void enforceBackUpFolderLimit() { // limit backup folder size to 1 GB; although it's hudge, it's there just not to cause HDD problems because of un-called for backups final int MAX = 1024 * 1024 * 1024; File backUpFolder = new File(installDir + File.separator + BACKUP_FOLDER); if (backUpFolder.exists() && backUpFolder.isDirectory()) { long size = FileUtils.sizeOfDirectory(backUpFolder); if (size > MAX) { // delete oldest files first long sizeOverflow = size - MAX; List<File> sortedByDate = new SortedList<File>(new Comparator<File>() { public int compare(File o1, File o2) { long result = o1.lastModified() - o2.lastModified(); return (result < 0) ? -1 : (result == 0 ? 0 : 1); }//from w w w. jav a 2 s. c o m }); sortedByDate.addAll(Arrays.asList(backUpFolder.listFiles())); for (File f : sortedByDate) { sizeOverflow -= FileUtils.sizeOf(f); FileUtils.deleteQuietly(f); if (f.exists()) sizeOverflow += FileUtils.sizeOf(f); if (sizeOverflow < 0) break; } } } }
From source file:net.sf.zekr.engine.audio.AudioCacheManager.java
/** * Removes {@link #getCapacitySize()} megabytes of files from user's audio cache, so that cache size limit * ({@link #getCapacitySize()}) is met. It simply ignores if audio cache size is not exceeded * {@link #getCapacitySize()}./*from www . ja va2 s .c o m*/ */ @SuppressWarnings("unchecked") public void flushCache() { logger.info("Flush audio cache."); long cacheSize = FileUtils.sizeOfDirectory(userPath); if (cacheSize > FileUtils.ONE_MB * capacitySize) { logger.info("Capacity size is " + capacitySize + " MB, of which " + FileUtils.byteCountToDisplaySize(cacheSize) + " is used. Flush size is " + flushSize + " MB."); Collection<File> audioDirectoryList = FileUtils.listFiles(userPath, new AbstractFileFilter() { public boolean accept(File file) { if (file.isDirectory()) { return true; } else { return false; } } }, null); List<File> fileList = new ArrayList<File>(); for (File dir : audioDirectoryList) { fileList.addAll(Arrays.asList(dir.listFiles())); } // return older files first Collections.sort(fileList, LastModifiedFileComparator.LASTMODIFIED_REVERSE); long deleteSize = 0; for (int i = 0; i < fileList.size(); i++) { if (deleteSize > flushSize + FileUtils.ONE_MB) { logger.info("Cache flushing suffices. " + FileUtils.byteCountToDisplaySize(deleteSize) + " were deleted."); break; } File file = fileList.get(i); deleteSize += file.length(); logger.debug("Delete: " + file); file.delete(); } } else { logger.info("No flush is required."); } }
From source file:com.thoughtworks.go.publishers.GoArtifactsManipulatorTest.java
@Test public void shouldUploadArtifactChecksumForADirectory() throws IOException { String data = "Some text whose checksum can be asserted"; String secondData = "some more"; FileUtils.writeStringToFile(tempFile, data, UTF_8); File anotherFile = new File(artifactFolder, "bond/james_bond/another_file"); FileUtils.writeStringToFile(anotherFile, secondData, UTF_8); when(httpService.upload(any(String.class), eq(FileUtils.sizeOfDirectory(artifactFolder)), any(File.class), eq(expectedProperties(data, secondData)))).thenReturn(HttpServletResponse.SC_OK); goArtifactsManipulatorStub.publish(goPublisher, "dest", artifactFolder, jobIdentifier); }