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

box / box-java-sdk / #6242

10 Feb 2026 05:27PM UTC coverage: 35.714% (+11.4%) from 24.324%
#6242

push

github

web-flow
fix(boxsdkgen): Move assigning default values from builder constructor to `build()` method (box/box-codegen#922) (#1712)

0 of 1677 new or added lines in 569 files covered. (0.0%)

2146 existing lines in 544 files now uncovered.

7382 of 20670 relevant lines covered (35.71%)

0.4 hits per line

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

0.0
/src/main/java/com/box/sdkgen/managers/downloads/DownloadsManager.java
1
package com.box.sdkgen.managers.downloads;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
6
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
7
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
8
import static com.box.sdkgen.internal.utils.UtilsManager.writeInputStreamToOutputStream;
9

10
import com.box.sdkgen.box.errors.BoxSDKError;
11
import com.box.sdkgen.networking.auth.Authentication;
12
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
13
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
14
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
15
import com.box.sdkgen.networking.network.NetworkSession;
16
import java.io.InputStream;
17
import java.io.OutputStream;
18
import java.util.Map;
19

20
public class DownloadsManager {
21

22
  public Authentication auth;
23

24
  public NetworkSession networkSession;
25

26
  public DownloadsManager() {
×
27
    this.networkSession = new NetworkSession();
×
28
  }
×
29

30
  protected DownloadsManager(Builder builder) {
×
31
    this.auth = builder.auth;
×
32
    this.networkSession = builder.networkSession;
×
33
  }
×
34

35
  /**
36
   * Returns the contents of a file in binary format.
37
   *
38
   * @param fileId The unique identifier that represents a file.
39
   *     <p>The ID for any file can be determined by visiting a file in the web application and
40
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
41
   *     `file_id` is `123`. Example: "12345"
42
   */
43
  public String getDownloadFileUrl(String fileId) {
44
    return getDownloadFileUrl(
×
45
        fileId, new GetDownloadFileUrlQueryParams(), new GetDownloadFileUrlHeaders());
46
  }
47

48
  /**
49
   * Returns the contents of a file in binary format.
50
   *
51
   * @param fileId The unique identifier that represents a file.
52
   *     <p>The ID for any file can be determined by visiting a file in the web application and
53
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
54
   *     `file_id` is `123`. Example: "12345"
55
   * @param queryParams Query parameters of downloadFile method
56
   */
57
  public String getDownloadFileUrl(String fileId, GetDownloadFileUrlQueryParams queryParams) {
58
    return getDownloadFileUrl(fileId, queryParams, new GetDownloadFileUrlHeaders());
×
59
  }
60

61
  /**
62
   * Returns the contents of a file in binary format.
63
   *
64
   * @param fileId The unique identifier that represents a file.
65
   *     <p>The ID for any file can be determined by visiting a file in the web application and
66
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
67
   *     `file_id` is `123`. Example: "12345"
68
   * @param headers Headers of downloadFile method
69
   */
70
  public String getDownloadFileUrl(String fileId, GetDownloadFileUrlHeaders headers) {
71
    return getDownloadFileUrl(fileId, new GetDownloadFileUrlQueryParams(), headers);
×
72
  }
73

74
  /**
75
   * Returns the contents of a file in binary format.
76
   *
77
   * @param fileId The unique identifier that represents a file.
78
   *     <p>The ID for any file can be determined by visiting a file in the web application and
79
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
80
   *     `file_id` is `123`. Example: "12345"
81
   * @param queryParams Query parameters of downloadFile method
82
   * @param headers Headers of downloadFile method
83
   */
84
  public String getDownloadFileUrl(
85
      String fileId, GetDownloadFileUrlQueryParams queryParams, GetDownloadFileUrlHeaders headers) {
86
    Map<String, String> queryParamsMap =
×
87
        prepareParams(
×
88
            mapOf(
×
89
                entryOf("version", convertToString(queryParams.getVersion())),
×
90
                entryOf("access_token", convertToString(queryParams.getAccessToken()))));
×
91
    Map<String, String> headersMap =
×
92
        prepareParams(
×
93
            mergeMaps(
×
94
                mapOf(
×
95
                    entryOf("range", convertToString(headers.getRange())),
×
96
                    entryOf("boxapi", convertToString(headers.getBoxapi()))),
×
97
                headers.getExtraHeaders()));
×
98
    FetchResponse response =
×
99
        this.networkSession
100
            .getNetworkClient()
×
101
            .fetch(
×
102
                new FetchOptions.Builder(
103
                        String.join(
×
104
                            "",
105
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
106
                            "/2.0/files/",
107
                            convertToString(fileId),
×
108
                            "/content"),
109
                        "GET")
110
                    .params(queryParamsMap)
×
111
                    .headers(headersMap)
×
112
                    .responseFormat(ResponseFormat.NO_CONTENT)
×
113
                    .auth(this.auth)
×
114
                    .networkSession(this.networkSession)
×
115
                    .followRedirects(false)
×
116
                    .build());
×
117
    if (response.getHeaders().containsKey("location")) {
×
118
      return response.getHeaders().get("location");
×
119
    }
120
    if (response.getHeaders().containsKey("Location")) {
×
121
      return response.getHeaders().get("Location");
×
122
    }
123
    throw new BoxSDKError("No location header in response");
×
124
  }
125

126
  /**
127
   * Returns the contents of a file in binary format.
128
   *
129
   * @param fileId The unique identifier that represents a file.
130
   *     <p>The ID for any file can be determined by visiting a file in the web application and
131
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
132
   *     `file_id` is `123`. Example: "12345"
133
   */
134
  public InputStream downloadFile(String fileId) {
135
    return downloadFile(fileId, new DownloadFileQueryParams(), new DownloadFileHeaders());
×
136
  }
137

138
  /**
139
   * Returns the contents of a file in binary format.
140
   *
141
   * @param fileId The unique identifier that represents a file.
142
   *     <p>The ID for any file can be determined by visiting a file in the web application and
143
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
144
   *     `file_id` is `123`. Example: "12345"
145
   * @param queryParams Query parameters of downloadFile method
146
   */
147
  public InputStream downloadFile(String fileId, DownloadFileQueryParams queryParams) {
148
    return downloadFile(fileId, queryParams, new DownloadFileHeaders());
×
149
  }
150

151
  /**
152
   * Returns the contents of a file in binary format.
153
   *
154
   * @param fileId The unique identifier that represents a file.
155
   *     <p>The ID for any file can be determined by visiting a file in the web application and
156
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
157
   *     `file_id` is `123`. Example: "12345"
158
   * @param headers Headers of downloadFile method
159
   */
160
  public InputStream downloadFile(String fileId, DownloadFileHeaders headers) {
161
    return downloadFile(fileId, new DownloadFileQueryParams(), headers);
×
162
  }
163

164
  /**
165
   * Returns the contents of a file in binary format.
166
   *
167
   * @param fileId The unique identifier that represents a file.
168
   *     <p>The ID for any file can be determined by visiting a file in the web application and
169
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
170
   *     `file_id` is `123`. Example: "12345"
171
   * @param queryParams Query parameters of downloadFile method
172
   * @param headers Headers of downloadFile method
173
   */
174
  public InputStream downloadFile(
175
      String fileId, DownloadFileQueryParams queryParams, DownloadFileHeaders headers) {
176
    Map<String, String> queryParamsMap =
×
177
        prepareParams(
×
178
            mapOf(
×
179
                entryOf("version", convertToString(queryParams.getVersion())),
×
180
                entryOf("access_token", convertToString(queryParams.getAccessToken()))));
×
181
    Map<String, String> headersMap =
×
182
        prepareParams(
×
183
            mergeMaps(
×
184
                mapOf(
×
185
                    entryOf("range", convertToString(headers.getRange())),
×
186
                    entryOf("boxapi", convertToString(headers.getBoxapi()))),
×
187
                headers.getExtraHeaders()));
×
188
    FetchResponse response =
×
189
        this.networkSession
190
            .getNetworkClient()
×
191
            .fetch(
×
192
                new FetchOptions.Builder(
193
                        String.join(
×
194
                            "",
195
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
196
                            "/2.0/files/",
197
                            convertToString(fileId),
×
198
                            "/content"),
199
                        "GET")
200
                    .params(queryParamsMap)
×
201
                    .headers(headersMap)
×
202
                    .responseFormat(ResponseFormat.BINARY)
×
203
                    .auth(this.auth)
×
204
                    .networkSession(this.networkSession)
×
205
                    .build());
×
206
    if (convertToString(response.getStatus()).equals("202")) {
×
207
      return null;
×
208
    }
209
    return response.getContent();
×
210
  }
211

212
  public void downloadFileToOutputStream(String fileId, OutputStream outputStream) {
213
    downloadFileToOutputStream(
×
214
        fileId,
215
        outputStream,
216
        new DownloadFileToOutputStreamQueryParams(),
217
        new DownloadFileToOutputStreamHeaders());
218
  }
×
219

220
  public void downloadFileToOutputStream(
221
      String fileId, OutputStream outputStream, DownloadFileToOutputStreamQueryParams queryParams) {
222
    downloadFileToOutputStream(
×
223
        fileId, outputStream, queryParams, new DownloadFileToOutputStreamHeaders());
224
  }
×
225

226
  public void downloadFileToOutputStream(
227
      String fileId, OutputStream outputStream, DownloadFileToOutputStreamHeaders headers) {
228
    downloadFileToOutputStream(
×
229
        fileId, outputStream, new DownloadFileToOutputStreamQueryParams(), headers);
230
  }
×
231

232
  public void downloadFileToOutputStream(
233
      String fileId,
234
      OutputStream outputStream,
235
      DownloadFileToOutputStreamQueryParams queryParams,
236
      DownloadFileToOutputStreamHeaders headers) {
237
    InputStream downloadStream =
×
238
        this.downloadFile(
×
239
            fileId,
240
            new DownloadFileQueryParams.Builder()
241
                .version(queryParams.getVersion())
×
242
                .accessToken(queryParams.getAccessToken())
×
243
                .build(),
×
244
            new DownloadFileHeaders.Builder()
245
                .range(headers.getRange())
×
246
                .boxapi(headers.getBoxapi())
×
247
                .extraHeaders(headers.getExtraHeaders())
×
248
                .build());
×
249
    writeInputStreamToOutputStream(downloadStream, outputStream);
×
250
  }
×
251

252
  public Authentication getAuth() {
253
    return auth;
×
254
  }
255

256
  public NetworkSession getNetworkSession() {
257
    return networkSession;
×
258
  }
259

260
  public static class Builder {
261

262
    protected Authentication auth;
263

264
    protected NetworkSession networkSession;
265

NEW
266
    public Builder() {}
×
267

268
    public Builder auth(Authentication auth) {
UNCOV
269
      this.auth = auth;
×
UNCOV
270
      return this;
×
271
    }
272

273
    public Builder networkSession(NetworkSession networkSession) {
UNCOV
274
      this.networkSession = networkSession;
×
UNCOV
275
      return this;
×
276
    }
277

278
    public DownloadsManager build() {
NEW
279
      if (this.networkSession == null) {
×
NEW
280
        this.networkSession = new NetworkSession();
×
281
      }
282
      return new DownloadsManager(this);
×
283
    }
284
  }
285
}
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

© 2026 Coveralls, Inc