use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method createNewRepo.
public void createNewRepo(String repoName, String description, String password) throws SeafException {
HttpRequest req = prepareApiPostRequest("api2/repos/", true, null);
req.form("name", repoName);
if (description.length() > 0) {
req.form("desc", description);
}
if (password.length() > 0) {
req.form("passwd", password);
}
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method renameRepo.
public void renameRepo(String repoID, String newName) throws SeafException {
Map<String, Object> params = Maps.newHashMap();
params.put("op", "rename");
HttpRequest req = prepareApiPostRequest(String.format("api2/repos/%s/", repoID), true, params);
req.form("repo_name", newName);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method move.
/**
* Move multiple files
*
* @param srcRepoId the source repo id
* @param srcDir the source folder in src_repo
* @param srcFn list of file/folder names to move. Multiple file/folder names can be seperated by ":"
* @param dstRepoId the destination repo id
* @param dstDir the destination folder in dst_repo
* @throws SeafException
*/
public void move(String srcRepoId, String srcDir, String srcFn, String dstRepoId, String dstDir) throws SeafException {
try {
Map<String, Object> params = Maps.newHashMap();
params.put("p", srcDir);
HttpRequest req = prepareApiPostRequest("api2/repos/" + srcRepoId + "/fileops/move/", true, params);
req.form("dst_repo", dstRepoId);
req.form("dst_dir", dstDir);
req.form("file_names", srcFn);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
} catch (SeafException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
}
}
use of com.github.kevinsawicki.http.HttpRequest in project PowerNukkitX by PowerNukkitX.
the class AdoptOpenJDKInstall method downloadAdoptOpenJDK17.
@SuppressWarnings("ResultOfMethodCallIgnored")
private void downloadAdoptOpenJDK17() {
final File localJavaDir = new File("./java");
if (!localJavaDir.exists()) {
localJavaDir.mkdirs();
}
final URL downloadURL = URLUtils.adopt17URL();
if (downloadURL == null) {
Logger.trWarn("display.fail.install-java17");
return;
}
try {
suffix = StringUtils.uriSuffix(downloadURL);
final File targetZip = new File("tmp." + suffix);
HttpRequest request = HttpRequest.get(downloadURL);
Logger.trInfo("display.connecting", downloadURL.toString());
final AtomicLong atomicLong = new AtomicLong(0);
cli.timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
final long total = request.getConnection().getContentLength();
final long finished = targetZip.length();
final long speed = finished - atomicLong.get();
atomicLong.set(finished);
Logger.bar((float) (finished * 1.0 / total), displayableBytes(finished) + "/" + displayableBytes(total) + " (" + displayableBytes(speed) + "/s)");
if (finished == total) {
Logger.trInfo("display.success.download", "Java17");
this.cancel();
}
}
}, 500, 500);
request.receive(targetZip);
} catch (Exception e) {
Logger.trWarn("display.fail.install-java17");
}
}
use of com.github.kevinsawicki.http.HttpRequest in project PowerNukkitX by PowerNukkitX.
the class DownloadDialog method init.
private void init() {
{
this.setTitle(LanguageUtils.tr("gui.download-dialog.title", name));
this.setSize(600, 108);
this.setLayout(null);
this.setVisible(true);
this.setResizable(false);
}
final JPanel panel = new JPanel(null);
this.setContentPane(panel);
label = new JLabel(link);
{
panel.add(label);
label.setSize(400, 36);
label.setLocation(8, 0);
}
final JProgressBar progressBar = new JProgressBar(0, 100);
{
progressBar.setStringPainted(true);
progressBar.setOrientation(HORIZONTAL);
panel.add(progressBar);
progressBar.setLocation(8, 36);
progressBar.setSize(new Dimension(560, 16));
}
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() {
final File dir = target.getParentFile();
if (dir != null && !dir.exists()) {
// noinspection ResultOfMethodCallIgnored
dir.mkdirs();
}
final HttpRequest request = HttpRequest.get(link);
final AtomicLong atomicLong = new AtomicLong(0);
CommonModel.TIMER.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
final long finished = target.length();
final long total = request.getConnection().getContentLength();
final long speed = finished - atomicLong.get();
atomicLong.set(finished);
SwingUtilities.invokeLater(() -> {
progressBar.setValue((int) Math.min(100, (finished * 1.0 / total) * 100));
label.setText(StringUtils.displayableBytes(speed) + "/s - " + link);
});
if (finished == total) {
this.cancel();
}
}
}, 500, 500);
request.receive(target);
return null;
}
@Override
protected void done() {
self.dispose();
callback.accept(self);
}
}.execute();
}
Aggregations