• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperwallet / java-sdk / #694

15 May 2025 08:53PM CUT coverage: 96.097%. Remained the same
#694

Pull #220

grmeyer-hw-dev
Prepare to release 1.9.7
Pull Request #220: Deprecate Double to String

5048 of 5253 relevant lines covered (96.1%)

65.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/main/java/com/hyperwallet/clientsdk/util/MultipartRequest.java
1
package com.hyperwallet.clientsdk.util;
2

3

4
import cc.protea.util.http.Response;
5
import com.hyperwallet.clientsdk.util.Multipart.MultipartData;
6

7
import java.io.DataOutputStream;
8
import java.io.File;
9
import java.io.IOException;
10
import java.net.Proxy;
11
import java.nio.file.Files;
12
import java.util.List;
13
import java.util.Map;
14

15
/**
16
 * Represents the HTTP Multipart Request message.
17
 */
18
public class MultipartRequest extends Request{
19

20
    public static final String BOUNDARY = "--0011010110123111";
21
    public static final String CRLF = "\r\n";
22
    private static final String SEPARATOR = "--";
23

24
    /**
25
     * The Constructor takes the url as a String, a proxy as a Proxy, and proxy credentials as a String.
26
     *
27
     * @param url               The url parameter does not need the query string parameters if they are going to be supplied via calls to
28
     *                          {@link #addQueryParameter(String, String)}. You can, however, supply the query parameters in the URL if you wish.
29
     * @param connectionTimeout A specified timeout value, in milliseconds, to establish communications link to the resource by
30
     *                          {@link  java.net.URLConnection}.
31
     * @param readTimeout       A specified timeout, in milliseconds, for reading data from an established connection to the resource
32
     *                          by {@link  java.net.URLConnection}.
33
     * @param proxy             The Connection's Proxy value
34
     * @param proxyUsername     The Proxy username
35
     * @param proxyPassword     The Proxy password
36
     */
37
    public MultipartRequest(String url, int connectionTimeout, int readTimeout, Proxy proxy, String proxyUsername,
38
            String proxyPassword) {
39
        super(url, connectionTimeout, readTimeout, proxy, proxyUsername, proxyPassword);
4✔
40
    }
4✔
41

42
    /**
43
     * Issues a PUT to the server.
44
     *
45
     * @param multipart The {@link Multipart}
46
     * @return The {@link Response} from the server
47
     * @throws IOException a {@link IOException}
48
     */
49
    public Response putMultipartResource(final Multipart multipart) throws IOException {
50
        return writeMuiltipartResource("PUT", multipart);
4✔
51
    }
52

53
    private Response writeMuiltipartResource(final String method, final Multipart multipartList) throws IOException {
54
        buildQueryString();
4✔
55
        buildHeaders();
4✔
56

57
        connection.setDoOutput(true);
4✔
58
        connection.setRequestMethod(method);
4✔
59

60
        DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
4✔
61
        writeMultipartBody(dataOutputStream, multipartList.getMultipartList());
1✔
62
        dataOutputStream.flush();
1✔
63
        dataOutputStream.close();
1✔
64

65
        Response response = readResponse();
1✔
66
        connection.disconnect();
×
67
        return response;
×
68
    }
69

70
    private void writeMultipartBody(DataOutputStream dataOutputStream, List<MultipartData> multipartList) throws IOException {
71
        for (MultipartData multipartData : multipartList) {
1✔
72
            for (Map.Entry<String, String> entry : multipartData.getEntity().entrySet()) {
×
73
                dataOutputStream.writeBytes(SEPARATOR + BOUNDARY + CRLF);
×
74
                dataOutputStream.writeBytes(multipartData.getContentDisposition());
×
75
                dataOutputStream.writeBytes(multipartData.getContentType());
×
76
                dataOutputStream.writeBytes(CRLF);
×
77

78
                if (multipartData.getContentType().contains("image")) {
×
79
                    byte[] bytes = Files.readAllBytes(new File(entry.getValue().toString()).toPath());
×
80
                    dataOutputStream.write(bytes);
×
81
                } else {
×
82
                    dataOutputStream.writeBytes(entry.getValue());
×
83
                }
84
                dataOutputStream.writeBytes(CRLF);
×
85
                dataOutputStream.flush();
×
86
            }
×
87
        }
×
88
        dataOutputStream.writeBytes(CRLF);
1✔
89
        dataOutputStream.writeBytes(SEPARATOR + BOUNDARY + SEPARATOR + CRLF);
1✔
90
    }
1✔
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc