List of usage examples for org.apache.commons.io FileUtils sizeOfDirectory
public static long sizeOfDirectory(File directory)
From source file:com.boundlessgeo.geoserver.api.controllers.ImportController.java
/** * API endpoint to get space available info when uploading files * /*w w w . j a va2 s . c o m*/ * TODO: If a dedicated file/resource API controller gets created, migrate this method to there * TODO: If/when workspace-specific upload limitations are implemented, update this to be * workspace-specific * @return A JSON object containing information about the space available in the workspace * @throws IOException */ @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj info(@PathVariable String wsName) throws IOException { JSONObj obj = new JSONObj(); Catalog catalog = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, catalog); if (ws != null) { obj.put("workspace", ws.getName()); } //Temp dir File tmpDir = new File(System.getProperty("java.io.tmpdir")); //Global REST upload dir String externalRoot = null; if (externalRoot == null) { externalRoot = RESTUtils.extractMapItem( RESTUtils.loadMapfromWorkSpace(ws == null ? null : ws.getName(), catalog), RESTUtils.ROOT_KEY); } if (externalRoot == null) { externalRoot = RESTUtils.extractMapItem(RESTUtils.loadMapFromGlobal(), RESTUtils.ROOT_KEY); } if (externalRoot == null) { externalRoot = Paths.toFile(catalog.getResourceLoader().getBaseDirectory(), Paths.path("data", ws == null ? null : ws.getName())).getAbsolutePath(); } File destDir = new File(externalRoot); long freeSpace = 0; if (tmpDir.exists()) { freeSpace = tmpDir.getUsableSpace(); obj.put("tmpDir", tmpDir.getPath()); obj.put("tmpSpace", freeSpace); } if (destDir.exists()) { freeSpace = destDir.getUsableSpace(); obj.put("uploadDir", destDir.getPath()); obj.put("uploadSpace", freeSpace); obj.put("spaceUsed", FileUtils.sizeOfDirectory(destDir)); } //In case the destDir is on a different filesystem than the tmpDir, take the min of both if (tmpDir.exists() && destDir.exists()) { freeSpace = Math.min(tmpDir.getUsableSpace(), destDir.getUsableSpace()); } obj.put("spaceAvailable", freeSpace); return obj; }
From source file:net.sf.logsaw.index.internal.LuceneIndexServiceImpl.java
@Override public String size(ILogResource log) { Assert.isNotNull(log, "log"); //$NON-NLS-1$ long size = FileUtils.sizeOfDirectory(IndexPlugin.getDefault().getIndexFile(log)); return FileUtils.byteCountToDisplaySize(size); }
From source file:de.uzk.hki.da.sb.SIPFactory.java
/** * Starts the progress manager and creates a progress manager job for each * SIP to build/* w ww .jav a2 s.c o m*/ * * @param folderList * The source folder list * @return The method result as a Feedback enum */ private Feedback initializeProgressManager(List<File> folderList) { progressManager.reset(); if (createCollection) progressManager.addJob(-1, collectionName, 0); int i = 0; for (File folder : folderList) { if (!folder.exists()) { logger.error("Folder " + folder.getAbsolutePath() + " does not exist anymore."); return Feedback.COPY_ERROR; } progressManager.addJob(i, folder.getName(), FileUtils.sizeOfDirectory(folder)); i++; } progressManager.calculateProgressParts(createCollection); progressManager.createStartMessage(); return Feedback.SUCCESS; }
From source file:dpfmanager.shell.interfaces.gui.component.report.ReportsModel.java
public String getReportsSize() { Long bytes = FileUtils.sizeOfDirectory(new File(DPFManagerProperties.getReportsDir())); return readableFileSize(bytes); }
From source file:com.thoughtworks.go.agent.UrlBasedArtifactsRepositoryTest.java
@Test public void shouldUploadArtifactChecksumForADirectory() throws IOException { String data = "Some text whose checksum can be asserted"; String secondData = "some more"; FileUtils.writeStringToFile(tempFile, data); File anotherFile = new File(artifactFolder, "bond/james_bond/another_file"); FileUtils.writeStringToFile(anotherFile, secondData); when(httpService.upload(eq("http://baseurl/artifacts/dest?attempt=1&buildId=build42"), eq(FileUtils.sizeOfDirectory(artifactFolder)), any(File.class), eq(expectedProperties(data, secondData)))).thenReturn(HttpServletResponse.SC_OK); artifactsRepository.upload(console, artifactFolder, "dest", "build42"); }
From source file:com.ethercamp.harmony.service.ContractsService.java
public IndexStatusDTO getIndexStatus() throws IOException { final long totalSize = Arrays.asList("/storageDict", "/contractCreation").stream() .mapToLong(name -> FileUtils.sizeOfDirectory(new File(config.databaseDir() + name))).sum(); return new IndexStatusDTO(totalSize, SolcUtils.getSolcVersion(), syncedBlock.orElse(-1L)); }
From source file:net.naonedbus.fragment.impl.SettingsFragment.java
/** * Calculer la taille du cache/*from w w w . ja v a 2 s.c o m*/ * * @return La taille du cache en octets */ private long getCacheSize() { final File cache = getActivity().getCacheDir(); return FileUtils.sizeOfDirectory(cache); }
From source file:net.naonedbus.activity.impl.OldSettingsActivity.java
/** * Calculer la taille du cache/*from w ww .j av a 2 s . c o m*/ * * @return La taille du cache en octets */ private long getCacheSize() { final File cache = getCacheDir(); return FileUtils.sizeOfDirectory(cache); }
From source file:com.iyonger.apm.web.service.PerfTestRunnable.java
/** * Distribute files to agents.// w w w.ja va 2 s . com * * @param perfTest perftest * @param singleConsole console to be used. */ void distributeFileOn(final PerfTest perfTest, SingleConsole singleConsole) { // Distribute files perfTestService.markStatusAndProgress(perfTest, DISTRIBUTE_FILES, "All necessary files are being distributed."); ListenerSupport<SingleConsole.FileDistributionListener> listener = ListenerHelper.create(); final long safeThreadHold = getSafeTransmissionThreshold(); listener.add(new SingleConsole.FileDistributionListener() { @Override public void distributed(String fileName) { perfTestService.markProgress(perfTest, " - " + fileName); } @Override public boolean start(File dir, boolean safe) { if (safe) { perfTestService.markProgress(perfTest, "Safe file distribution mode is enabled."); return safe; } long sizeOfDirectory = FileUtils.sizeOfDirectory(dir); if (sizeOfDirectory > safeThreadHold) { perfTestService.markProgress(perfTest, "The total size of distributed files is over " + UnitUtils.byteCountToDisplaySize(safeThreadHold) + "B.\n- Safe file distribution mode is enabled by force."); return true; } return safe; } }); // the files have prepared before singleConsole.distributeFiles(perfTestService.getDistributionPath(perfTest), listener, isSafeDistPerfTest(perfTest)); perfTestService.markStatusAndProgress(perfTest, DISTRIBUTE_FILES_FINISHED, "All necessary files are distributed."); }
From source file:com.playonlinux.framework.WinePrefix.java
/** * Wait for all wine application to be terminated and create a progress bar watching for the size of a directory * @param directory Directory to watch/*from w w w .j a v a2 s . co m*/ * @param endSize Expected size of the directory when the installation is terminated * @return the same object * @throws CancelException if the users cancels or if there is any error */ public WinePrefix waitAllWatchDirectory(File directory, long endSize) throws CancelException { ObservableDirectorySize observableDirectorySize; ProgressStep progressStep = this.setupWizard.progressBar( String.format(translate("Please wait while the program is being installed..."), prefixName)); try { observableDirectorySize = new ObservableDirectorySize(directory, FileUtils.sizeOfDirectory(directory), endSize); } catch (PlayOnLinuxException e) { throw new ScriptFailureException(e); } observableDirectorySize.setCheckInterval(10); observableDirectorySize.addObserver(progressStep); backgroundServicesManager.register(observableDirectorySize); try { waitAll(); } finally { observableDirectorySize.deleteObserver(progressStep); backgroundServicesManager.unregister(observableDirectorySize); } return this; }