List of usage examples for org.apache.commons.io FileUtils sizeOfDirectory
public static long sizeOfDirectory(File directory)
From source file:org.goobi.presentation.contentservlet.controller.ContentCache.java
@SuppressWarnings("unchecked") public void cleanCache() { long limit = (long) ((maxSizeInMB * 1024 * 1024) * 0.75); File[] files = cacheFolder.listFiles(); Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); for (File file : files) { FileUtils.deleteQuietly(file);/* w w w . jav a 2s . co m*/ if (FileUtils.sizeOfDirectory(cacheFolder) < limit) { return; } } }
From source file:org.goobi.presentation.contentservlet.controller.ContentCache.java
/************************************************************************************* * check if maximum size of cache already exceeded * //from w w w. j ava 2 s . c o m * @return true, if size of cache is already bigger than configured maximum * @throws CacheException ************************************************************************************/ public boolean isCacheSizeExceeded() throws CacheException { LOGGER.debug("Checking cache size"); long currentSize = FileUtils.sizeOfDirectory(cacheFolder); long maxSize = maxSizeInMB * 1024 * 1024; LOGGER.debug("Current cache size = " + currentSize); if (currentSize >= maxSize) { LOGGER.debug("Cleaning cache"); cleanCache(); currentSize = FileUtils.sizeOfDirectory(cacheFolder); LOGGER.debug("Done cleaning cache"); } return (currentSize >= maxSize); }
From source file:org.h819.commons.file.MyPDFUtilss.java
/** * ???// w ww. ja v a 2 s . co m * * @param srcPdfFileDir * @param descPdfFileDir * @return */ private static boolean isEnoughtSpace(File srcPdfFileDir, File descPdfFileDir) { if (!srcPdfFileDir.exists() && !srcPdfFileDir.isDirectory()) { logger.info(srcPdfFileDir.getAbsolutePath() + " not exist."); return false; } try { FileUtils.forceMkdir(descPdfFileDir); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // ?? // long prefixDiskFreeSize = descPdfFileDir.getFreeSpace(); // ?? long srcSize = FileUtils.sizeOfDirectory(srcPdfFileDir); // logger.info(descPdfFileDir.getAbsolutePath() + " " // + prefixDiskFreeSize / 1000000.00 + " M"); // logger.info(srcPdfFileDir.getAbsolutePath() + " ? :" + srcSize // / 1000000.00 + " M"); if (prefixDiskFreeSize < srcSize) { logger.info(FilenameUtils.getPrefix(descPdfFileDir.getAbsolutePath()) + " has not enoght disk size ."); return false; } return true; }
From source file:org.jclouds.examples.blobstore.BlobUploaderMain.java
public static void main(String[] args) throws IOException { OptionParser parser = new OptionParser(); parser.accepts("directory").withRequiredArg().required().ofType(String.class); parser.accepts("provider").withRequiredArg().required().ofType(String.class); parser.accepts("username").withRequiredArg().required().ofType(String.class); parser.accepts("password").withRequiredArg().required().ofType(String.class); parser.accepts("region").withRequiredArg().required().ofType(String.class); parser.accepts("threads").withRequiredArg().ofType(Integer.TYPE).describedAs("number of parallel threads"); OptionSet options = null;/*from w w w. j a va2 s . c om*/ try { options = parser.parse(args); } catch (OptionException e) { System.out.println(e.getLocalizedMessage()); parser.printHelpOn(System.out); return; } if (options.has("threads")) { numThreads = Integer.valueOf((String) options.valueOf("numThreads")); } File rootDir = new File((String) options.valueOf("directory")); Collection<File> files = FileUtils.listFiles(rootDir, CanReadFileFilter.CAN_READ, TrueFileFilter.TRUE); totalBytes = FileUtils.sizeOfDirectory(rootDir); System.out.println("Uploading " + rootDir.getName() + " " + totalBytes / FileUtils.ONE_MB + "MB"); ExecutorService executor = Executors.newFixedThreadPool(numThreads); for (File f : files) { BlobUploader b = new BlobUploader((String) options.valueOf("username"), (String) options.valueOf("password"), (String) options.valueOf("provider"), (String) options.valueOf("region"), f); executor.execute(b); } executor.shutdown(); try { executor.awaitTermination(1, TimeUnit.DAYS); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:org.jumpmind.symmetric.service.impl.FileSyncService.java
protected List<IncomingBatch> processZip(InputStream is, String sourceNodeId, ProcessInfo processInfo) throws IOException { File unzipDir = new File(parameterService.getTempDirectory(), String.format("filesync_incoming/%s/%s", engine.getNodeService().findIdentityNodeId(), sourceNodeId)); FileUtils.deleteDirectory(unzipDir); unzipDir.mkdirs();/* w ww .j av a 2s. c o m*/ AppUtils.unzip(is, unzipDir); Set<Long> batchIds = new TreeSet<Long>(); String[] files = unzipDir.list(DirectoryFileFilter.INSTANCE); if (files != null) { for (int i = 0; i < files.length; i++) { try { batchIds.add(Long.parseLong(files[i])); } catch (NumberFormatException e) { log.error( "Unexpected directory name. Expected a number representing a batch id. Instead the directory was named '{}'", files[i]); } } } List<IncomingBatch> batchesProcessed = new ArrayList<IncomingBatch>(); IIncomingBatchService incomingBatchService = engine.getIncomingBatchService(); processInfo.setStatus(ProcessInfo.Status.LOADING); for (Long batchId : batchIds) { processInfo.setCurrentBatchId(batchId); processInfo.incrementBatchCount(); File batchDir = new File(unzipDir, Long.toString(batchId)); IncomingBatch incomingBatch = new IncomingBatch(); File batchInfo = new File(batchDir, "batch-info.txt"); if (batchInfo.exists()) { List<String> info = FileUtils.readLines(batchInfo); if (info != null && info.size() > 0) { incomingBatch.setChannelId(info.get(0).trim()); } else { incomingBatch.setChannelId(Constants.CHANNEL_FILESYNC); } } else { incomingBatch.setChannelId(Constants.CHANNEL_FILESYNC); } incomingBatch.setBatchId(batchId); incomingBatch.setStatus(IncomingBatch.Status.LD); incomingBatch.setNodeId(sourceNodeId); incomingBatch.setByteCount(FileUtils.sizeOfDirectory(batchDir)); batchesProcessed.add(incomingBatch); if (incomingBatchService.acquireIncomingBatch(incomingBatch)) { File syncScript = new File(batchDir, "sync.bsh"); if (syncScript.exists()) { String script = FileUtils.readFileToString(syncScript); Interpreter interpreter = new Interpreter(); boolean isLocked = false; try { interpreter.set("log", log); interpreter.set("batchDir", batchDir.getAbsolutePath().replace('\\', '/')); interpreter.set("engine", engine); interpreter.set("sourceNodeId", sourceNodeId); long waitMillis = getParameterService().getLong(ParameterConstants.FILE_SYNC_LOCK_WAIT_MS); log.debug("The {} node is attempting to get shared lock for to update incoming status", sourceNodeId); isLocked = engine.getClusterService().lock(ClusterConstants.FILE_SYNC_SHARED, ClusterConstants.TYPE_SHARED, waitMillis); if (isLocked) { log.debug("The {} node got a shared file sync lock", sourceNodeId); @SuppressWarnings("unchecked") Map<String, String> filesToEventType = (Map<String, String>) interpreter.eval(script); updateFileIncoming(sourceNodeId, filesToEventType); incomingBatch.setStatementCount(filesToEventType != null ? filesToEventType.size() : 0); } else { throw new RuntimeException( "Could not obtain file sync shared lock within " + waitMillis + " millis"); } incomingBatch.setStatus(IncomingBatch.Status.OK); if (incomingBatchService.isRecordOkBatchesEnabled()) { incomingBatchService.updateIncomingBatch(incomingBatch); } else if (incomingBatch.isRetry()) { incomingBatchService.deleteIncomingBatch(incomingBatch); } } catch (Throwable ex) { if (ex instanceof TargetError) { Throwable target = ((TargetError) ex).getTarget(); if (target != null) { ex = target; } } else if (ex instanceof EvalError) { log.error("Failed to evalulate the script:\n{}", script); } if (ex instanceof FileConflictException) { log.error(ex.getMessage() + ". Failed to process file sync batch " + batchId); } else { log.error("Failed to process file sync batch " + batchId, ex); } incomingBatch.setErrorFlag(true); incomingBatch.setStatus(IncomingBatch.Status.ER); incomingBatch.setSqlMessage(ex.getMessage()); if (incomingBatchService.isRecordOkBatchesEnabled() || incomingBatch.isRetry()) { incomingBatchService.updateIncomingBatch(incomingBatch); } else { incomingBatchService.insertIncomingBatch(incomingBatch); } processInfo.setStatus(ProcessInfo.Status.ERROR); break; } finally { log.debug("The {} node is done processing file sync files", sourceNodeId); if (isLocked) { engine.getClusterService().unlock(ClusterConstants.FILE_SYNC_SHARED, ClusterConstants.TYPE_SHARED); } } } else { log.error("Could not find the sync.bsh script for batch {}", batchId); } } } return batchesProcessed; }
From source file:org.jwebsocket.plugins.quota.definitions.QuotaDiskSpace.java
private long getDirectorySpace(String aDirectory) throws Exception { File lFiles = new File(aDirectory); long lUsedSpace = 0; if (lFiles.exists() && lFiles.isDirectory()) { lUsedSpace = FileUtils.sizeOfDirectory(lFiles); } else {//w w w . j a va 2 s . c o m throw new Exception("Directory: " + aDirectory + " not found"); } return lUsedSpace; }
From source file:org.jwebsocket.plugins.quota.definitions.singleIntance.QuotaDiskSpaceSI.java
/** * *//* w w w .j a v a 2 s . co m*/ public void testing() { File lFiles = new File("/home/svn/ijwssvn/rte/jWebSocket-1.0/filesystem/"); mRoots = lFiles.listFiles(); long lTotalHddSpace = 0; long lSpace = 0; for (File lRoot : mRoots) { if (lRoot.isDirectory()) { lSpace = FileUtils.sizeOfDirectory(lRoot); lTotalHddSpace += lSpace; } } }
From source file:org.kitodo.filemanagement.FileManagement.java
@Override public Long getSizeOfDirectory(URI directory) throws IOException { if (!directory.isAbsolute()) { directory = fileMapper.mapUriToKitodoDataDirectoryUri(directory); }//from w ww . ja v a2 s. co m if (isDirectory(directory)) { return FileUtils.sizeOfDirectory(new File(directory)); } else { throw new IOException("Given URI doesn't point to the directory!"); } }
From source file:org.madsonic.controller.HelpController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); if (versionService.isNewFinalVersionAvailable()) { map.put("newVersionAvailable", true); map.put("latestVersion", versionService.getLatestFinalVersion()); } else if (versionService.isNewBetaVersionAvailable()) { map.put("newVersionAvailable", true); map.put("latestVersion", versionService.getLatestBetaVersion()); }/*from ww w. j ava 2 s. c om*/ File HSQLDB = new File(SettingsService.getMadsonicHome() + Util.getDefaultSlash() + "db"); long sizeHSQLDB = HSQLDB.exists() ? FileUtils.sizeOfDirectory(HSQLDB) / 1024 / 1024 : 0; File lastFMCache = new File(SettingsService.getMadsonicHome() + Util.getDefaultSlash() + ".last.fm-cache"); long sizeLastFMCache = lastFMCache.exists() ? FileUtils.sizeOfDirectory(lastFMCache) / 1024 / 1024 : 0; File luceneCache = new File(SettingsService.getMadsonicHome() + Util.getDefaultSlash() + "lucene2"); long sizeLuceneCache = luceneCache.exists() ? FileUtils.sizeOfDirectory(luceneCache) / 1024 / 1024 : 0; File thumbsCache = new File(SettingsService.getMadsonicHome() + Util.getDefaultSlash() + "thumbs"); long sizeThumbsCache = thumbsCache.exists() ? FileUtils.sizeOfDirectory(thumbsCache) / 1024 / 1024 : 0; String cacheInfo; cacheInfo = "Size: Database: " + sizeHSQLDB + "MB, Thumbs-Cache: " + sizeThumbsCache + "MB, LastFM-Cache: " + sizeLastFMCache + "MB, Lucene-Cache: " + sizeLuceneCache + "MB"; // Check transcoder String ffmpegVersion = "WARNING no transcoder found!"; String commandLine = settingsService.getDownsamplingCommand(); boolean transcoderFound = isTranscodingStepInstalled(commandLine); String transcoderPath = transcodingService.getTranscodeDirectory() + Util.getDefaultSlash() + StringUtil.split(commandLine)[0] + (Util.isWindows() == true ? ".exe" : ""); if (transcoderFound) { ProcessBuilder processBuilder = new ProcessBuilder(transcodingService.getTranscodeDirectory() + Util.getDefaultSlash() + StringUtil.split(commandLine)[0], "-version"); try { int readInt; Process process = processBuilder.start(); InputStream instream = process.getInputStream(); StringBuffer commandResult = new StringBuffer(); while ((readInt = instream.read()) != -1) commandResult.append((char) readInt); BufferedReader b = new BufferedReader(new StringReader(commandResult.toString())); for (String line = b.readLine(); line != null; line = b.readLine()) { if (line.contains("ffmpeg version")) { ffmpegVersion = line; File file = new File(transcoderPath); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); String ffmpegFileDate = sdf.format(file.lastModified()); ffmpegVersion = ffmpegVersion + " (" + ffmpegFileDate + ")"; break; } } } catch (IOException e) { } catch (Exception e) { } } long totalMemory = Runtime.getRuntime().totalMemory(); long freeMemory = Runtime.getRuntime().freeMemory(); String serverInfo = request.getSession().getServletContext().getServerInfo() + ", java " + System.getProperty("java.version") + ", " + System.getProperty("os.name"); map.put("licenseInfo", settingsService.getLicenseInfo()); map.put("brand", settingsService.getBrand()); map.put("localVersion", versionService.getLocalVersion()); map.put("buildTime", versionService.getLocalBuildTime()); map.put("buildDate", versionService.getLocalBuildDate()); map.put("buildNumber", versionService.getLocalBuildNumber()); map.put("serverInfo", serverInfo); map.put("cacheInfo", cacheInfo); map.put("springInfo", VersionChecker.getSpringFrameworkVersion()); map.put("databaseInfo", VersionChecker.getSpringSecurityVersion()); map.put("transcoderFound", !ffmpegVersion.contains("WARNING")); map.put("ffmpegInfo", ffmpegVersion); map.put("RESTInfo", StringUtil.getRESTProtocolVersion()); map.put("usedMemory", totalMemory - freeMemory); map.put("totalMemory", totalMemory); map.put("logEntries", Logger.getLatestLogEntries(settingsService.isLogfileReverse())); map.put("logFile", Logger.getLogFile()); map.put("user", securityService.getCurrentUser(request)); ModelAndView result = super.handleRequestInternal(request, response); result.addObject("model", map); return result; }
From source file:org.mule.modules.hdfs.automation.testcases.CopyToLocalFileTestCases.java
@Test public void testCopyToLocalFile() { try {// w w w . j a v a 2 s . co m runFlowAndGetPayload("copy-to-local-file"); assertTrue(FileUtils.sizeOfDirectory(new File(target)) > 0); } catch (Exception e) { fail(ConnectorTestUtils.getStackTrace(e)); } }