Search in sources :

Example 1 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method deleteRepo.

public void deleteRepo(String repoID) throws SeafException {
    try {
        HttpRequest req = prepareApiDeleteRequest(String.format("api2/repos/%s/", repoID), null);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException)

Example 2 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method getRepos.

public String getRepos() throws SeafException {
    HttpRequest req = null;
    try {
        req = prepareApiGetRequest("api2/repos/");
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String result = new String(req.bytes(), "UTF-8");
        return result;
    } catch (SeafException e) {
        throw e;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    } catch (IOException e) {
        throw SeafException.networkException;
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) IOException(java.io.IOException)

Example 3 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method copy.

/**
 * Copy a file or multiple files, multiple file/folder names should be seperated by a ":".
 *
 * @param srcRepoId the source repo id
 * @param srcDir    the source folder in src_repo
 * @param srcFn     list of file/folder names to copy. 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 copy(String srcRepoId, String srcDir, String srcFn, String dstRepoId, String dstDir) throws SeafException {
    try {
        Map<String, Object> params = Maps.newHashMap();
        params.put("p", encodeUriComponent(srcDir).replaceAll("\\+", "%20"));
        HttpRequest req = prepareApiPostRequest("api2/repos/" + srcRepoId + "/fileops/copy/", 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);
    } catch (UnsupportedEncodingException e) {
        throw SeafException.encodingException;
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONObject(org.json.JSONObject)

Example 4 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method getAvatar.

public String getAvatar(String email, int size) throws SeafException {
    try {
        String apiPath = String.format("api2/avatars/user/%s/resized/%d", email, size);
        HttpRequest req = prepareApiGetRequest(apiPath);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String result = new String(req.bytes(), "UTF-8");
        return result;
    } catch (SeafException e) {
        throw e;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    } catch (IOException e) {
        throw SeafException.networkException;
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) IOException(java.io.IOException)

Example 5 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method createNewFile.

public Pair<String, String> createNewFile(String repoID, String parentDir, String fileName) throws SeafException {
    try {
        String fullPath = Utils.pathJoin(parentDir, fileName);
        final String encodeUriComponent = encodeUriComponent(fullPath).replaceAll("\\+", "%20");
        Map<String, Object> params = Maps.newHashMap();
        params.put("p", encodeUriComponent);
        params.put("reloaddir", "true");
        HttpRequest req = prepareApiPostRequest("api2/repos/" + repoID + "/file/", true, params, false);
        req.form("operation", "create");
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String newDirID = req.header("oid");
        if (newDirID == null) {
            return null;
        }
        String content = new String(req.bytes(), "UTF-8");
        if (content.length() == 0) {
            return null;
        }
        return new Pair<String, String>(newDirID, content);
    } catch (SeafException e) {
        throw e;
    } catch (UnsupportedEncodingException e) {
        throw SeafException.encodingException;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject) Pair(android.util.Pair)

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