本文整理匯總了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);
}
}
});
}
示例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);
}
示例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);
}
示例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");
}
示例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");
}