Project

General

Profile

CommitSync JAVA » History » Version 1

Tomek Dziemidowicz, 2019-07-18 09:01 PM

1 1 Tomek Dziemidowicz
h1. CommitSync JAVA
2
3
<pre><code class="java">
4
/**
5
 * Send info to remote server about successful single table synchronization
6
 * @param syncId id of synchronization
7
 * @throws Exception
8
 */
9
private void commitSynchronization(@NonNull int syncId) throws Exception {
10
    HttpURLConnection connection = null;
11
    InputStream resultStream = null;
12
    String resultString = null;
13
14
    String requestUrl = String.format("%s/CommitSync/%s", _serverURL, syncId);
15
16
    try {
17
        connection = (HttpURLConnection) new URL(requestUrl).openConnection();
18
19
        int status = connection.getResponseCode();
20
21
        switch (status){
22
            case HttpURLConnection.HTTP_OK:
23
                resultStream = connection.getInputStream();
24
                resultString = IOUtils.toString(resultStream, "UTF-8");
25
                break;
26
            default:
27
                resultStream = connection.getErrorStream();
28
                resultString = IOUtils.toString(resultStream, "UTF-8");
29
                throw new Exception(resultString);
30
        }
31
    }
32
    finally {
33
        if (resultStream != null) {
34
            try {
35
                resultStream.close();
36
            } catch (IOException e) {
37
            }
38
        }
39
        if (connection != null) {
40
            connection.disconnect();
41
        }
42
    }
43
}
44
</code></pre>
Go to top