当前位置: 首页>>代码示例>>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;未经允许,请勿转载。