Search in sources :

Example 16 with HttpRequest

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);
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Example 17 with HttpRequest

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);
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) JSONObject(org.json.JSONObject)

Example 18 with HttpRequest

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);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject)

Example 19 with HttpRequest

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");
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) TimerTask(java.util.TimerTask) File(java.io.File) ZipFile(net.lingala.zip4j.ZipFile) URL(java.net.URL) IOException(java.io.IOException)

Example 20 with HttpRequest

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();
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) TimerTask(java.util.TimerTask) File(java.io.File)

Aggregations

HttpRequest (com.github.kevinsawicki.http.HttpRequest)86 HttpRequestException (com.github.kevinsawicki.http.HttpRequest.HttpRequestException)29 IOException (java.io.IOException)25 JSONObject (org.json.JSONObject)19 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 File (java.io.File)8 TimerTask (java.util.TimerTask)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 Pair (android.util.Pair)6 URL (java.net.URL)5 JSONException (org.json.JSONException)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)4 JSONObject (com.alibaba.fastjson.JSONObject)4 ZipFile (net.lingala.zip4j.ZipFile)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 IPEntity (com.example.li.springboot_crawler_demo.utils.img.entity.IPEntity)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2