List of usage examples for org.apache.commons.io FileUtils sizeOfDirectory
public static long sizeOfDirectory(File directory)
From source file:desktopsearch.ExploreFiles.java
private void RecursivelyExplore(File Directory) { String[] List = Directory.list(); String AbsPath = Directory.getAbsolutePath() + "/"; String SQLQuery = null;/*ww w. j a va 2 s. c o m*/ ArrayList<String> DirList = new ArrayList(); String FormattedPath = Directory.getPath(); if (FormattedPath.contains("'")) { FormattedPath = FormattedPath.replace("'", "''"); } try { for (int i = 0; i < List.length; i++) { File path = new File(AbsPath + List[i]); Path Location = Paths.get(path.getAbsolutePath()); FileTime LastModifiedTime = Files.getLastModifiedTime(Location); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(LastModifiedTime.toMillis()); try { if (path.isFile()) { String Type = FilenameUtils.getExtension(Directory.getPath() + "/" + List[i]); if (Type.endsWith("~") || Type.equals("")) { Type = "Text"; } if (List[i].contains("'")) { List[i] = List[i].replace("'", "''"); System.out.println(List[i]); } SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i] + "','" + Type + "','" + calendar.getTime() + "'," + (path.length() / 1024) + ");"; } else { if (List[i].contains("'")) { List[i] = List[i].replace("'", "''"); System.out.println(List[i]); } if (!Files.isSymbolicLink(Location)) { long size = FileUtils.sizeOfDirectory(path); SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i] + "','FOLDER','" + calendar.getTime() + "'," + size + ");"; } else { SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i] + "','LINK','" + calendar.getTime() + "',0);"; } DirList.add(List[i]); } output.println(SQLQuery); } catch (Exception exp) { exp.printStackTrace(); } ; } for (int i = 0; i < DirList.size(); i++) { File subDir = new File(AbsPath + DirList.get(i)); Path path = Paths.get(AbsPath + DirList.get(i)); if (subDir.canRead() && !Files.isSymbolicLink(path)) { RecursivelyExplore(subDir); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.splout.db.dnode.Fetcher.java
/** * Use this method to know the total size of a deployment URI. */// w ww. j a v a2 s . com public long sizeOf(String uriStr) throws IOException, URISyntaxException { URI uri = new URI(uriStr); if (uriStr.startsWith("file:")) { File f = new File(uri); return f.isDirectory() ? FileUtils.sizeOfDirectory(f) : f.length(); } else if (uriStr.startsWith("s3")) { return -1; // NotYetImplemented // Be flexible as to what we can expect here (e.g. maprfs, etc) } else { // } else if(uriStr.startsWith("hdfs")) { return FileSystem.get(hadoopConf).getContentSummary(new Path(uriStr)).getLength(); // } else { // throw new IllegalArgumentException("Scheme not recognized or non-absolute URI provided: " + uri); } }
From source file:com.ssn.listener.SSNHiveAlbumSelectionListner.java
public SSNGalleryMetaData getSSNMediaFolderProperties(String mediaPath) { if (null == mediaPath || mediaPath.equals("viewAllAlbums") || mediaPath.equals("instagramMedia") || mediaPath.equals("tagUnTaggedMedia") || mediaPath.contains(getFacebookPhotosDirPath())) { mediaPath = SSNHelper.getSsnDefaultDirPath(); }/* w ww .j av a2 s.c o m*/ SSNGalleryMetaData data = new SSNGalleryMetaData(); File folder = new File(mediaPath); listFiles(folder); data.setMediaLocation(mediaPath); data.setTitle(folder.getName()); data.setNoOfFiles(iT); data.setNoOfFolders(dT); Date dNow = new Date(folder.lastModified()); SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); data.setModiFied(ft.format(dNow)); long size = FileUtils.sizeOfDirectory(folder); double flKB = (double) size / 1024; double flMB = flKB / 1024; String s = String.format("%.2f", flMB); data.setSize(s); form.getSsnHomeRightPanel().removeAll(); form.getSsnHomeRightPanel().add(SSMMediaGalleryPanel.populateMediaFolderPanel(data), BorderLayout.NORTH); form.getSsnHomeRightPanel().revalidate(); form.getSsnHomeRightPanel().repaint(); form.revalidate(); form.repaint(); return data; }
From source file:com.thoughtworks.go.service.ConfigRepository.java
private String getConfigRepoDisplaySize() { return FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(workingDir)); }
From source file:es.pode.localizador.negocio.servicios.SrvLocalizadorServiceImpl.java
private long calculaEspacio(File localizacion) { try {//w ww. ja va 2 s . co m return FileUtils.sizeOfDirectory(localizacion); } catch (Exception e) { logger.error("Error al calcular el espacio del fichero " + e); long vuelta = 0; return vuelta; } // if (localizacion.isFile()) // return localizacion.length(); // File[] files = localizacion.listFiles(); // long size = 0; // if (files != null) { // for (int i = 0; i < files.length; i++) // size += calculaEspacio(files[i]); // } // return size; }
From source file:de.uzk.hki.da.sb.SIPFactory.java
/** * Creates a tar oder tgz archive file out of the given folder. The value of * the field 'compress' determines if a tar or tgz file is created. * //www .j a va 2 s .com * @param jobId * The job ID * @param folder * The folder to archive * @param archiveFile * The target archive file * @return The method result as a Feedback enum */ public Feedback buildArchive(int jobId, File folder, File archiveFile) { progressManager.setJobFolderSize(jobId, FileUtils.sizeOfDirectory(folder)); progressManager.archiveProgress(jobId, 0); SipArchiveBuilder archiveBuilder = null; try { archiveBuilder = new SipArchiveBuilder(); archiveBuilder.setProgressManager(progressManager); archiveBuilder.setJobId(jobId); archiveBuilder.setSipBuildingProcess(sipBuildingProcess); } catch (Exception e) { logger.error("Failed to instantiate the ArchiveBuilder ", e); return Feedback.ABORT; } try { if (!archiveBuilder.archiveFolder(folder, archiveFile, true, compress)) return Feedback.ABORT; } catch (Exception e) { logger.error("Failed to archive folder " + folder.getAbsolutePath() + " to archive " + archiveFile.getAbsolutePath(), e); return Feedback.ARCHIVE_ERROR; } return Feedback.SUCCESS; }
From source file:com.playonlinux.framework.Wine.java
/** * Wait for all wine application to be terminated and createPrefix a * progress bar watching for the size of a directory * * @param directory/*from ww w . ja va2 s. c o m*/ * Directory to watch * @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 Wine waitAllWatchDirectory(File directory, long endSize) throws CancelException { ProgressControl progressControl = this.setupWizard .progressBar(format(translate("Please wait while the program is being installed..."), prefixName)); final long startSize = FileUtils.sizeOfDirectory(directory); try (DirectoryWatcherSize observableDirectorySize = new DirectoryWatcherSize(executorService, prefix.getWinePrefixDirectory().toPath())) { observableDirectorySize.setOnChange(newSize -> { final double percentage = 100. * (newSize - startSize) / (endSize - startSize); progressControl.setProgressPercentage(percentage); }); waitExit(); } catch (IllegalStateException e) { throw new ScriptFailureException(e); } return this; }
From source file:edu.ur.file.db.TreeFolderInfo.java
/** * Get the size in bytes of this folder. * /* ww w . j av a 2 s . com*/ * @see edu.ur.file.db.FolderInfo#getSize() */ public Long getSize() { return FileUtils.sizeOfDirectory(new File(this.getFullPath())); }
From source file:com.splout.db.dnode.DNodeHandler.java
/** * Returns an {@link com.splout.db.dnode.beans.DNodeSystemStatus} filled with * the appropriated data./*from w w w . jav a2s .co m*/ */ @Override public String status() throws DNodeException { try { DNodeSystemStatus status = new DNodeSystemStatus(); if (lastException == null) { status.setSystemStatus("UP"); status.setLastExceptionTime(-1); } else { status.setSystemStatus("Last exception: " + lastException); status.setLastExceptionTime(lastExceptionTime); } status.setUpSince(upSince); status.setFailedQueries(failedQueries.get()); status.setnQueries(performanceTool.getNQueries()); status.setAverage(performanceTool.getAverage()); status.setSlowQueries(slowQueries); status.setDeploysInProgress(deployInProgress.get()); status.setHttpExchangerAddress(httpExchangerAddress()); status.setTcpAddress(getTCPAPIAddress()); status.setBalanceActionsStateMap(balanceActionsStateMap); File folder = new File(config.getString(DNodeProperties.DATA_FOLDER)); if (folder.exists()) { status.setFreeSpaceInDisk(FileSystemUtils.freeSpaceKb(folder.toString())); status.setOccupiedSpaceInDisk(FileUtils.sizeOfDirectory(folder)); Collection<File> files = FileUtils.listFilesAndDirs(folder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); status.setFiles(new ArrayList<String>( Lists.transform(Lists.newArrayList(files), new Function<File, String>() { @Override public String apply(File file) { return file.getAbsolutePath() + " (" + FileUtils.sizeOf(file) + " bytes)"; } }))); Collections.sort(status.getFiles()); } else { status.setOccupiedSpaceInDisk(0); status.setFreeSpaceInDisk(FileSystemUtils.freeSpaceKb(".")); status.setFiles(new ArrayList<String>()); } return JSONSerDe.ser(status); } catch (Throwable t) { unexpectedException(t); throw new DNodeException(EXCEPTION_UNEXPECTED, t.getMessage()); } }
From source file:com.edgenius.core.repository.SimpleRepositoryServiceImpl.java
public long[] getSpaceQuoteUsage(ITicket ticket, String spacename) { long[] ret = new long[2]; CrWorkspace crW = getCrWorkspace(ticket); if (crW == null) { //maybe $SYSTEM$ log.warn("Unable to get CR Workspace: " + spacename); return new long[] { 0, 0 }; }//from w ww .j a v a 2 s . com long quota = crW.getQuota(); long used = 0; File spaceDir = new File(FileUtil.getFullPath(homeDir, crW.getSpaceUuid())); //if dir not exist, then just treat it as 0 size and valid if (spaceDir.exists()) { //append file size used = FileUtils.sizeOfDirectory(spaceDir); } ret[0] = used; ret[1] = quota; return ret; }