List of usage examples for org.apache.commons.io FileUtils sizeOfDirectory
public static long sizeOfDirectory(File directory)
From source file:org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource.java
private synchronized void checkSecondaryStorageResourceLimit(TemplateOrVolumePostUploadCommand cmd, int contentLengthInGB) { String rootDir = this.getRootDir(cmd.getDataTo(), cmd.getNfsVersion()) + File.separator; long accountId = cmd.getAccountId(); long accountTemplateDirSize = 0; File accountTemplateDir = new File(rootDir + getTemplatePathForAccount(accountId)); if (accountTemplateDir.exists()) { FileUtils.sizeOfDirectory(accountTemplateDir); }/*from ww w.j a va 2s. c o m*/ long accountVolumeDirSize = 0; File accountVolumeDir = new File(rootDir + getVolumePathForAccount(accountId)); if (accountVolumeDir.exists()) { accountVolumeDirSize = FileUtils.sizeOfDirectory(accountVolumeDir); } long accountSnapshotDirSize = 0; File accountSnapshotDir = new File(rootDir + getSnapshotPathForAccount(accountId)); if (accountSnapshotDir.exists()) { accountSnapshotDirSize = FileUtils.sizeOfDirectory(accountSnapshotDir); } s_logger.debug("accountTemplateDirSize: " + accountTemplateDirSize + " accountSnapshotDirSize: " + accountSnapshotDirSize + " accountVolumeDirSize: " + accountVolumeDirSize); int accountDirSizeInGB = getSizeInGB( accountTemplateDirSize + accountSnapshotDirSize + accountVolumeDirSize); int defaultMaxAccountSecondaryStorageInGB = Integer.parseInt(cmd.getDefaultMaxAccountSecondaryStorage()); if ((accountDirSizeInGB + contentLengthInGB) > defaultMaxAccountSecondaryStorageInGB) { s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxAccountSecondaryStorageInGB: " + defaultMaxAccountSecondaryStorageInGB + " contentLengthInGB:" + contentLengthInGB); String errorMessage = "Maximum number of resources of type secondary_storage for account has exceeded"; updateStateMapWithError(cmd.getEntityUUID(), errorMessage); throw new InvalidParameterValueException(errorMessage); } }
From source file:org.apache.jackrabbit.oak.benchmark.RepositoryGrowthTest.java
@Override protected void tearDown(RepositoryFixture fixture) throws IOException { if (fixture instanceof OakRepositoryFixture) { OakFixture oakFixture = ((OakRepositoryFixture) fixture).getOakFixture(); if (oakFixture instanceof SegmentFixture) { SegmentFixture sf = (SegmentFixture) oakFixture; long size = sf.getStores()[0].size(); if (sf.getBlobStoreFixtures().length > 0) { size = sf.getBlobStoreFixtures()[0].size(); }//from w w w. j a va 2 s. c o m File indexDir = indexDirs.get(fixture); if (indexDir != null) { size += FileUtils.sizeOfDirectory(indexDir); } System.out.printf("Repository size %s %s %n", fixture, IOUtils.humanReadableByteCount(size)); } } super.tearDown(fixture); }
From source file:org.apache.jackrabbit.oak.fixture.BlobStoreFixture.java
public static BlobStoreFixture getFileDataStore(final File basedir, final int fdsCacheInMB) { return new BlobStoreFixture("FDS") { private File storeDir; private FileDataStore fds; @Override//w w w . j a v a2s . co m public BlobStore setUp() { fds = new FileDataStore(); fds.setMinRecordLength(4092); storeDir = new File(basedir, unique); fds.init(storeDir.getAbsolutePath()); configure(fds); BlobStore bs = new DataStoreBlobStore(fds, true, fdsCacheInMB); configure(bs); return bs; } @Override public void tearDown() { fds.close(); FileUtils.deleteQuietly(storeDir); } @Override public long size() { return FileUtils.sizeOfDirectory(storeDir); } }; }
From source file:org.apache.jackrabbit.oak.fixture.BlobStoreFixture.java
public static BlobStoreFixture getFileBlobStore(final File basedir) { return new BlobStoreFixture("FBS") { private File storeDir; private FileBlobStore fbs; @Override/* ww w . j a va2s.co m*/ public BlobStore setUp() { storeDir = new File(basedir, unique); fbs = new FileBlobStore(storeDir.getAbsolutePath()); configure(fbs); return fbs; } @Override public void tearDown() { FileUtils.deleteQuietly(storeDir); } @Override public long size() { return FileUtils.sizeOfDirectory(storeDir); } }; }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory.java
public long getSize() { return FileUtils.sizeOfDirectory(indexRootDir); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir.java
public long size() { return FileUtils.sizeOfDirectory(dir); }
From source file:org.apache.jackrabbit.oak.run.CompactCommand.java
@Override public void execute(String... args) throws Exception { OptionParser parser = new OptionParser(); OptionSpec<String> directoryArg = parser.nonOptions("Path to segment store (required)") .ofType(String.class); OptionSpec<Void> forceFlag = parser.accepts("force", "Force compaction and ignore non matching segment version"); OptionSpec<?> segmentTar = parser.accepts("segment-tar", "Use oak-segment-tar instead of oak-segment"); OptionSet options = parser.parse(args); String path = directoryArg.value(options); if (path == null) { System.err.println("Compact a file store. Usage: compact [path] <options>"); parser.printHelpOn(System.err); System.exit(-1);/*w w w . j ava 2 s . c o m*/ } File directory = new File(path); boolean force = options.has(forceFlag); boolean success = false; Set<String> beforeLs = newHashSet(); Set<String> afterLs = newHashSet(); Stopwatch watch = Stopwatch.createStarted(); System.out.println("Compacting " + directory); System.out.println(" before "); beforeLs.addAll(list(directory)); long sizeBefore = FileUtils.sizeOfDirectory(directory); System.out .println(" size " + IOUtils.humanReadableByteCount(sizeBefore) + " (" + sizeBefore + " bytes)"); System.out.println(" -> compacting"); try { if (options.has(segmentTar)) { SegmentTarUtils.compact(directory, force); } else { SegmentUtils.compact(directory, force); } success = true; } catch (Throwable e) { System.out.println("Compaction failure stack trace:"); e.printStackTrace(System.out); } finally { watch.stop(); if (success) { System.out.println(" after "); afterLs.addAll(list(directory)); long sizeAfter = FileUtils.sizeOfDirectory(directory); System.out.println( " size " + IOUtils.humanReadableByteCount(sizeAfter) + " (" + sizeAfter + " bytes)"); System.out.println(" removed files " + difference(beforeLs, afterLs)); System.out.println(" added files " + difference(afterLs, beforeLs)); System.out.println("Compaction succeeded in " + watch.toString() + " (" + watch.elapsed(TimeUnit.SECONDS) + "s)."); } else { System.out.println("Compaction failed in " + watch.toString() + " (" + watch.elapsed(TimeUnit.SECONDS) + "s)."); System.exit(1); } } }
From source file:org.apache.kylin.dict.lookup.cache.RocksDBLookupTableCache.java
public long getTotalCacheSize() { return FileUtils.sizeOfDirectory(new File(getCacheBasePath(config))); }
From source file:org.apache.oodt.product.handlers.ofsn.util.OFSNUtils.java
public static Document getOFSNDoc(List<File> fileList, OFSNHandlerConfig cfg, String productRoot, boolean showDirSize, boolean showFileSize) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);// w w w.j a v a 2 s. c om Document document; try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); Element root = (Element) document.createElement(DIR_RESULT_TAG); XMLUtils.addAttribute(document, root, "xmlns", DIR_LISTING_NS); document.appendChild(root); for (File file : fileList) { Element dirEntryElem = XMLUtils.addNode(document, root, DIR_ENTRY_TAG); String ofsn = toOFSN(file.getAbsolutePath(), productRoot); //This ensures that we get ofsn names with unix style separators. //On a Windows machine, the product server would return '\' //separators. String unixStyleOFSN = FilenameUtils.separatorsToUnix(ofsn); if (cfg.getType().equals(LISTING_CMD)) { if (!Boolean.valueOf(cfg.getHandlerConf().getProperty("isSizeCmd"))) { XMLUtils.addNode(document, dirEntryElem, OFSN_TAG, unixStyleOFSN); } } long size = Long.MIN_VALUE; if (file.isDirectory()) { if (showDirSize) { size = FileUtils.sizeOfDirectory(file); } } else { if (showFileSize) { size = file.length(); } } if (size != Long.MIN_VALUE) { XMLUtils.addNode(document, dirEntryElem, FILE_SIZE_TAG, String.valueOf(size)); } } return document; } catch (ParserConfigurationException e) { LOG.log(Level.SEVERE, e.getMessage()); return null; } }
From source file:org.artifactory.storage.service.StorageServiceImpl.java
@Override public void logStorageSizes() { ArtifactoryHome artifactoryHome = ContextHelper.get().getArtifactoryHome(); File derbyDirectory = new File(artifactoryHome.getDataDir(), "derby"); long sizeOfDirectory = FileUtils.sizeOfDirectory(derbyDirectory); log.info("Derby database storage size: {} ({})", StorageUnit.toReadableString(sizeOfDirectory), derbyDirectory);/* w w w . j a va 2 s. c o m*/ }