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


Java DownloadUtil類代碼示例

本文整理匯總了Java中com.intellij.platform.templates.github.DownloadUtil的典型用法代碼示例。如果您正苦於以下問題:Java DownloadUtil類的具體用法?Java DownloadUtil怎麽用?Java DownloadUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: OnResult

import com.intellij.platform.templates.github.DownloadUtil; //導入依賴的package包/類
@Override
public void OnResult(String result) {
    int extPos = result.lastIndexOf('/');
    if (extPos < 0 && extPos != result.length() - 1) {
        return;
    }
    String fileName = result.substring(extPos + 1);
    String title = "Download:" + fileName;
    File downloadFile = new File(Constant.CACHE_PATH + "search/" + fileName);
    ProgressManager.getInstance().run(new Task.Backgroundable(project, title) {
        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            try {
                DownloadUtil.downloadAtomically(null, result, downloadFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (downloadFile.exists()) {
                Utils.openFileInPanel(downloadFile.getPath(), project);
            }
        }
    });

}
 
開發者ID:pengwei1024,項目名稱:AndroidSourceViewer,代碼行數:25,代碼來源:GlobalSearchAction.java

示例2: onDownload

import com.intellij.platform.templates.github.DownloadUtil; //導入依賴的package包/類
@Override
public Pair<Boolean, List<File>> onDownload(@NotNull ClassEntity[] classEntities, @NotNull File outputFolder) {
    List<File> fileList = new ArrayList<File>();
    for (int i = 0; i < classEntities.length; i++) {
        String url = classEntities[i].getDownloadUrl();
        if (url == null) {
            continue;
        }
        String filename;
        if (Utils.isEmpty(classEntities[i].getSaveName())) {
            filename = url.substring(url.lastIndexOf("/") + 1);
        } else {
            filename = classEntities[i].getSaveName();
        }
        File outFile = new File(outputFolder, filename);
        if (outFile.exists()) {
            fileList.add(outFile);
            continue;
        }
        try {
            DownloadUtil.downloadAtomically(null, url, outFile);
        } catch (IOException e) {
            Log.e(e);
        }
        if (outFile.exists()) {
            fileList.add(outFile);
        }
    }
    return Pair.create(classEntities.length == fileList.size(), fileList);
}
 
開發者ID:pengwei1024,項目名稱:AndroidSourceViewer,代碼行數:31,代碼來源:XrefDownload.java

示例3: downloadAtomically

import com.intellij.platform.templates.github.DownloadUtil; //導入依賴的package包/類
/**
 * Downloads content of {@code url} to {@code outputFile}.
 * {@code outputFile} won't be modified in case of any I/O download errors.
 *
 * @param indicator   progress indicator
 * @param url         url to download
 * @param outputFile  output file
 */
public static void downloadAtomically(@Nullable ProgressIndicator indicator,
                                      @NotNull String url,
                                      @NotNull File outputFile,
                                      @NotNull String userName,
                                      @NotNull String repositoryName) throws IOException
{
  String tempFileName = String.format("github-%s-%s-%s", userName, repositoryName, outputFile.getName());
  File tempFile = FileUtil.createTempFile(tempFileName + "-", ".tmp");
  DownloadUtil.downloadAtomically(indicator, url, outputFile, tempFile);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:GithubDownloadUtil.java

示例4: downloadContentToFileWithProgressSynchronously

import com.intellij.platform.templates.github.DownloadUtil; //導入依賴的package包/類
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public static void downloadContentToFileWithProgressSynchronously(
  @Nullable Project project,
  @NotNull final String url,
  @NotNull String progressTitle,
  @NotNull final File outputFile,
  @NotNull final String userName,
  @NotNull final String repositoryName,
  final boolean retryOnError) throws GeneratorException
{
  Outcome<File> outcome = DownloadUtil.provideDataWithProgressSynchronously(
    project,
    progressTitle,
    "Downloading zip archive" + DownloadUtil.CONTENT_LENGTH_TEMPLATE + " ...",
    new Callable<File>() {
      @Override
      public File call() throws Exception {
        ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
        downloadAtomically(progress, url, outputFile, userName, repositoryName);
        return outputFile;
      }
    }, new Producer<Boolean>() {
      @Override
      public Boolean produce() {
        if (!retryOnError) {
          return false;
        }
        return IOExceptionDialog.showErrorDialog("Download Error", "Can not download '" + url + "'");
      }
    }
  );
  File out = outcome.get();
  if (out != null) {
    return;
  }
  Exception e = outcome.getException();
  if (e != null) {
    throw new GeneratorException("Can not fetch content from " + url, e);
  }
  throw new GeneratorException("Download was cancelled");
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:42,代碼來源:GithubDownloadUtil.java

示例5: downloadContentToFileWithProgressSynchronously

import com.intellij.platform.templates.github.DownloadUtil; //導入依賴的package包/類
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public static void downloadContentToFileWithProgressSynchronously(
  @Nullable Project project,
  @NotNull final String url,
  @NotNull String progressTitle,
  @NotNull final File outputFile,
  @NotNull final String userName,
  @NotNull final String repositoryName,
  final boolean retryOnError) throws GeneratorException
{
  Outcome<File> outcome = DownloadUtil.provideDataWithProgressSynchronously(
    project,
    progressTitle,
    "Downloading zip archive" + DownloadUtil.CONTENT_LENGTH_TEMPLATE + " ...",
    new Callable<File>() {
      @Override
      public File call() throws Exception {
        ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
        downloadAtomically(progress, url, outputFile, userName, repositoryName);
        return outputFile;
      }
    }, new Producer<Boolean>() {
      @Override
      public Boolean produce() {
        if (!retryOnError) {
          return false;
        }
        return IOExceptionDialog.showErrorDialog("Download Error", "Can not download '" + url + "'");
      }
    }
  );
  File out = outcome.get();
  if (out != null) {
    return;
  }
  Exception e = outcome.getException();
  if (e != null) {
    throw new GeneratorException("Can not fetch content from " + url);
  }
  throw new GeneratorException("Download was cancelled");
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:42,代碼來源:GithubDownloadUtil.java


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