當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtils.forceMkdirParent方法代碼示例

本文整理匯總了Java中org.apache.commons.io.FileUtils.forceMkdirParent方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtils.forceMkdirParent方法的具體用法?Java FileUtils.forceMkdirParent怎麽用?Java FileUtils.forceMkdirParent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.io.FileUtils的用法示例。


在下文中一共展示了FileUtils.forceMkdirParent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolveUrlBasedMetadataResource

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
private void resolveUrlBasedMetadataResource(final SamlRegisteredService service,
                                             final List<MetadataResolver> metadataResolvers,
                                             final AbstractResource metadataResource) throws Exception {

    final SamlIdPProperties.Metadata md = casProperties.getAuthn().getSamlIdp().getMetadata();
    final File backupDirectory = new File(md.getLocation().getFile(), "metadata-backups");
    final File backupFile = new File(backupDirectory, metadataResource.getFilename());

    LOGGER.debug("Metadata backup directory is designated to be [{}]", backupDirectory.getCanonicalPath());
    FileUtils.forceMkdir(backupDirectory);

    LOGGER.debug("Metadata backup file will be at [{}]", backupFile.getCanonicalPath());
    FileUtils.forceMkdirParent(backupFile);

    final HttpClientMultithreadedDownloader downloader =
            new HttpClientMultithreadedDownloader(metadataResource, backupFile);

    final FileBackedHTTPMetadataResolver metadataProvider = new FileBackedHTTPMetadataResolver(
            this.httpClient.getWrappedHttpClient(), metadataResource.getURL().toExternalForm(),
            backupFile.getCanonicalPath());
    buildSingleMetadataResolver(metadataProvider, service);
    metadataResolvers.add(metadataProvider);
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:24,代碼來源:ChainingMetadataResolverCacheLoader.java

示例2: saveObject

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
private void saveObject(@NonNull final File _portScannerResultFile,
                        @NonNull final Object _objectToPersist,
                        @NonNull final List<Class<?>> _asStringClasses) {
    try {
        FileUtils.forceMkdirParent(_portScannerResultFile);
        final boolean success = _portScannerResultFile.createNewFile();

        if (!success) {
            log.debug("Output file already exists: {}", _portScannerResultFile.getPath());
        }

        @Cleanup final FileOutputStream fos = new FileOutputStream(_portScannerResultFile);

        log.info("Saving file: " + _portScannerResultFile.getPath());

        saveCorePlugin.getExtension().save(fos, _objectToPersist, _asStringClasses);
    } catch (IOException _e) {
        log.error("Failed to save port scan result", _e);
    }
}
 
開發者ID:jonfryd,項目名稱:tifoon,代碼行數:21,代碼來源:PortScannerFileIOServiceImpl.java

示例3: takeFullScreenshot

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
public static void takeFullScreenshot(WebDriver webDriver, File pngFile, By... highlights)
        throws IOException {
    final PageSnapshot pageSnapshot = Shutterbug.shootPage(webDriver, BOTH_DIRECTIONS);
    if (ArrayUtils.isNotEmpty(highlights)) {
        Arrays.stream(highlights)
                .map(webDriver::findElements)
                .flatMap(Collection::stream)
                .forEach(pageSnapshot::highlight);
    }
    FileUtils.forceMkdirParent(pngFile);
    pageSnapshot.withName(pngFile.getName());
    pageSnapshot.save(pngFile.getParent());
    FileUtils.deleteQuietly(pngFile);
    FileUtils.moveFile(new File(pngFile.getPath() + ".png"), pngFile);
}
 
開發者ID:ldaume,項目名稱:headless-chrome,代碼行數:16,代碼來源:HeadlessDriverUtils.java

示例4: extract

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
/**
 * Unpack the contents of a tarball (.tar.gz)
 *
 * @param tarball The source tarbal
 */
public static void extract(File tarball) throws IOException {

  TarArchiveInputStream tarIn = new TarArchiveInputStream(
      new GzipCompressorInputStream(
          new BufferedInputStream(
              new FileInputStream(tarball))));

  TarArchiveEntry tarEntry = tarIn.getNextTarEntry();

  while (tarEntry != null) {
    File entryDestination = new File(tarball.getParent(), tarEntry.getName());
    FileUtils.forceMkdirParent(entryDestination);

    if (tarEntry.isDirectory()) {
      FileUtils.forceMkdir(entryDestination);
    } else {
      entryDestination.createNewFile();

      BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(entryDestination));
      byte[] buffer = new byte[1024];
      int len;

      while ((len = tarIn.read(buffer)) != -1) {
        outputStream.write(buffer, 0, len);
      }

      outputStream.close();
    }

    tarEntry = tarIn.getNextTarEntry();
  }

  tarIn.close();
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:40,代碼來源:TarArchiveUtils.java

示例5: getObb

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
/**
 * Check if any OBB files are available, and if so, download and install them. This
 * also deletes any obsolete OBB files, per the spec, since there can be only one
 * "main" and one "patch" OBB installed at a time.
 *
 * @see <a href="https://developer.android.com/google/play/expansion-files.html">APK Expansion Files</a>
 */
private void getObb(final String urlString, String obbUrlString,
                    final File obbDestFile, final String sha256) {
    if (obbDestFile == null || obbDestFile.exists() || TextUtils.isEmpty(obbUrlString)) {
        return;
    }
    final BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Downloader.ACTION_STARTED.equals(action)) {
                Utils.debugLog(TAG, action + " " + intent);
            } else if (Downloader.ACTION_PROGRESS.equals(action)) {

                int bytesRead = intent.getIntExtra(Downloader.EXTRA_BYTES_READ, 0);
                int totalBytes = intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, 0);
                appUpdateStatusManager.updateApkProgress(urlString, totalBytes, bytesRead);
            } else if (Downloader.ACTION_COMPLETE.equals(action)) {
                localBroadcastManager.unregisterReceiver(this);
                File localFile = new File(intent.getStringExtra(Downloader.EXTRA_DOWNLOAD_PATH));
                Uri localApkUri = Uri.fromFile(localFile);
                Utils.debugLog(TAG, "OBB download completed " + intent.getDataString()
                        + " to " + localApkUri);

                try {
                    if (Hasher.isFileMatchingHash(localFile, sha256, "SHA-256")) {
                        Utils.debugLog(TAG, "Installing OBB " + localFile + " to " + obbDestFile);
                        FileUtils.forceMkdirParent(obbDestFile);
                        FileUtils.copyFile(localFile, obbDestFile);
                        FileFilter filter = new WildcardFileFilter(
                                obbDestFile.getName().substring(0, 4) + "*.obb");
                        for (File f : obbDestFile.getParentFile().listFiles(filter)) {
                            if (!f.equals(obbDestFile)) {
                                Utils.debugLog(TAG, "Deleting obsolete OBB " + f);
                                FileUtils.deleteQuietly(f);
                            }
                        }
                    } else {
                        Utils.debugLog(TAG, localFile + " deleted, did not match hash: " + sha256);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    FileUtils.deleteQuietly(localFile);
                }
            } else if (Downloader.ACTION_INTERRUPTED.equals(action)) {
                localBroadcastManager.unregisterReceiver(this);
            } else if (Downloader.ACTION_CONNECTION_FAILED.equals(action)) {
                DownloaderService.queue(context, urlString, 0, urlString);
            } else {
                throw new RuntimeException("intent action not handled!");
            }
        }
    };
    DownloaderService.queue(this, obbUrlString, 0, obbUrlString);
    localBroadcastManager.registerReceiver(downloadReceiver,
            DownloaderService.getIntentFilter(obbUrlString));
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:65,代碼來源:InstallManagerService.java


注:本文中的org.apache.commons.io.FileUtils.forceMkdirParent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。