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

box / box-java-sdk / #6243

10 Feb 2026 05:27PM UTC coverage: 18.192% (-17.5%) from 35.714%
#6243

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%)

2147 existing lines in 545 files now uncovered.

7388 of 40611 relevant lines covered (18.19%)

0.21 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/uploads/UploadsManager.java
1
package com.box.sdkgen.managers.uploads;
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

9
import com.box.sdkgen.box.errors.BoxSDKError;
10
import com.box.sdkgen.networking.auth.Authentication;
11
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
12
import com.box.sdkgen.networking.fetchoptions.MultipartItem;
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 com.box.sdkgen.schemas.files.Files;
17
import com.box.sdkgen.schemas.uploadurl.UploadUrl;
18
import com.box.sdkgen.serialization.json.JsonManager;
19
import java.util.Arrays;
20
import java.util.Map;
21

22
public class UploadsManager {
23

24
  public Authentication auth;
25

26
  public NetworkSession networkSession;
27

28
  public UploadsManager() {
×
29
    this.networkSession = new NetworkSession();
×
30
  }
×
31

32
  protected UploadsManager(Builder builder) {
×
33
    this.auth = builder.auth;
×
34
    this.networkSession = builder.networkSession;
×
35
  }
×
36

37
  /**
38
   * Update a file's content. For file sizes over 50MB we recommend using the Chunk Upload APIs.
39
   *
40
   * <p>The `attributes` part of the body must come **before** the `file` part. Requests that do not
41
   * follow this format when uploading the file will receive a HTTP `400` error with a
42
   * `metadata_after_file_contents` error code.
43
   *
44
   * @param fileId The unique identifier that represents a file.
45
   *     <p>The ID for any file can be determined by visiting a file in the web application and
46
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
47
   *     `file_id` is `123`. Example: "12345"
48
   * @param requestBody Request body of uploadFileVersion method
49
   */
50
  public Files uploadFileVersion(String fileId, UploadFileVersionRequestBody requestBody) {
51
    return uploadFileVersion(
×
52
        fileId, requestBody, new UploadFileVersionQueryParams(), new UploadFileVersionHeaders());
53
  }
54

55
  /**
56
   * Update a file's content. For file sizes over 50MB we recommend using the Chunk Upload APIs.
57
   *
58
   * <p>The `attributes` part of the body must come **before** the `file` part. Requests that do not
59
   * follow this format when uploading the file will receive a HTTP `400` error with a
60
   * `metadata_after_file_contents` error code.
61
   *
62
   * @param fileId The unique identifier that represents a file.
63
   *     <p>The ID for any file can be determined by visiting a file in the web application and
64
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
65
   *     `file_id` is `123`. Example: "12345"
66
   * @param requestBody Request body of uploadFileVersion method
67
   * @param queryParams Query parameters of uploadFileVersion method
68
   */
69
  public Files uploadFileVersion(
70
      String fileId,
71
      UploadFileVersionRequestBody requestBody,
72
      UploadFileVersionQueryParams queryParams) {
73
    return uploadFileVersion(fileId, requestBody, queryParams, new UploadFileVersionHeaders());
×
74
  }
75

76
  /**
77
   * Update a file's content. For file sizes over 50MB we recommend using the Chunk Upload APIs.
78
   *
79
   * <p>The `attributes` part of the body must come **before** the `file` part. Requests that do not
80
   * follow this format when uploading the file will receive a HTTP `400` error with a
81
   * `metadata_after_file_contents` error code.
82
   *
83
   * @param fileId The unique identifier that represents a file.
84
   *     <p>The ID for any file can be determined by visiting a file in the web application and
85
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
86
   *     `file_id` is `123`. Example: "12345"
87
   * @param requestBody Request body of uploadFileVersion method
88
   * @param headers Headers of uploadFileVersion method
89
   */
90
  public Files uploadFileVersion(
91
      String fileId, UploadFileVersionRequestBody requestBody, UploadFileVersionHeaders headers) {
92
    return uploadFileVersion(fileId, requestBody, new UploadFileVersionQueryParams(), headers);
×
93
  }
94

95
  /**
96
   * Update a file's content. For file sizes over 50MB we recommend using the Chunk Upload APIs.
97
   *
98
   * <p>The `attributes` part of the body must come **before** the `file` part. Requests that do not
99
   * follow this format when uploading the file will receive a HTTP `400` error with a
100
   * `metadata_after_file_contents` error code.
101
   *
102
   * @param fileId The unique identifier that represents a file.
103
   *     <p>The ID for any file can be determined by visiting a file in the web application and
104
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
105
   *     `file_id` is `123`. Example: "12345"
106
   * @param requestBody Request body of uploadFileVersion method
107
   * @param queryParams Query parameters of uploadFileVersion method
108
   * @param headers Headers of uploadFileVersion method
109
   */
110
  public Files uploadFileVersion(
111
      String fileId,
112
      UploadFileVersionRequestBody requestBody,
113
      UploadFileVersionQueryParams queryParams,
114
      UploadFileVersionHeaders headers) {
115
    Map<String, String> queryParamsMap =
×
116
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
×
117
    Map<String, String> headersMap =
×
118
        prepareParams(
×
119
            mergeMaps(
×
120
                mapOf(
×
121
                    entryOf("if-match", convertToString(headers.getIfMatch())),
×
122
                    entryOf("content-md5", convertToString(headers.getContentMd5()))),
×
123
                headers.getExtraHeaders()));
×
124
    FetchResponse response =
×
125
        this.networkSession
126
            .getNetworkClient()
×
127
            .fetch(
×
128
                new FetchOptions.Builder(
129
                        String.join(
×
130
                            "",
131
                            this.networkSession.getBaseUrls().getUploadUrl(),
×
132
                            "/2.0/files/",
133
                            convertToString(fileId),
×
134
                            "/content"),
135
                        "POST")
136
                    .params(queryParamsMap)
×
137
                    .headers(headersMap)
×
138
                    .multipartData(
×
139
                        Arrays.asList(
×
140
                            new MultipartItem.Builder("attributes")
141
                                .data(JsonManager.serialize(requestBody.getAttributes()))
×
142
                                .build(),
×
143
                            new MultipartItem.Builder("file")
144
                                .fileStream(requestBody.getFile())
×
145
                                .fileName(requestBody.getFileFileName())
×
146
                                .contentType(requestBody.getFileContentType())
×
147
                                .build()))
×
148
                    .contentType("multipart/form-data")
×
149
                    .responseFormat(ResponseFormat.JSON)
×
150
                    .auth(this.auth)
×
151
                    .networkSession(this.networkSession)
×
152
                    .build());
×
153
    return JsonManager.deserialize(response.getData(), Files.class);
×
154
  }
155

156
  /**
157
   * Performs a check to verify that a file will be accepted by Box before you upload the entire
158
   * file.
159
   */
160
  public UploadUrl preflightFileUploadCheck() {
161
    return preflightFileUploadCheck(
×
162
        new PreflightFileUploadCheckRequestBody(), new PreflightFileUploadCheckHeaders());
163
  }
164

165
  /**
166
   * Performs a check to verify that a file will be accepted by Box before you upload the entire
167
   * file.
168
   *
169
   * @param requestBody Request body of preflightFileUploadCheck method
170
   */
171
  public UploadUrl preflightFileUploadCheck(PreflightFileUploadCheckRequestBody requestBody) {
172
    return preflightFileUploadCheck(requestBody, new PreflightFileUploadCheckHeaders());
×
173
  }
174

175
  /**
176
   * Performs a check to verify that a file will be accepted by Box before you upload the entire
177
   * file.
178
   *
179
   * @param headers Headers of preflightFileUploadCheck method
180
   */
181
  public UploadUrl preflightFileUploadCheck(PreflightFileUploadCheckHeaders headers) {
182
    return preflightFileUploadCheck(new PreflightFileUploadCheckRequestBody(), headers);
×
183
  }
184

185
  /**
186
   * Performs a check to verify that a file will be accepted by Box before you upload the entire
187
   * file.
188
   *
189
   * @param requestBody Request body of preflightFileUploadCheck method
190
   * @param headers Headers of preflightFileUploadCheck method
191
   */
192
  public UploadUrl preflightFileUploadCheck(
193
      PreflightFileUploadCheckRequestBody requestBody, PreflightFileUploadCheckHeaders headers) {
194
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
195
    FetchResponse response =
×
196
        this.networkSession
197
            .getNetworkClient()
×
198
            .fetch(
×
199
                new FetchOptions.Builder(
200
                        String.join(
×
201
                            "",
202
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
203
                            "/2.0/files/content"),
204
                        "OPTIONS")
205
                    .headers(headersMap)
×
206
                    .data(JsonManager.serialize(requestBody))
×
207
                    .contentType("application/json")
×
208
                    .responseFormat(ResponseFormat.JSON)
×
209
                    .auth(this.auth)
×
210
                    .networkSession(this.networkSession)
×
211
                    .build());
×
212
    return JsonManager.deserialize(response.getData(), UploadUrl.class);
×
213
  }
214

215
  /**
216
   * Uploads a small file to Box. For file sizes over 50MB we recommend using the Chunk Upload APIs.
217
   *
218
   * <p>The `attributes` part of the body must come **before** the `file` part. Requests that do not
219
   * follow this format when uploading the file will receive a HTTP `400` error with a
220
   * `metadata_after_file_contents` error code.
221
   *
222
   * @param requestBody Request body of uploadFile method
223
   */
224
  public Files uploadFile(UploadFileRequestBody requestBody) {
225
    return uploadFile(requestBody, new UploadFileQueryParams(), new UploadFileHeaders());
×
226
  }
227

228
  /**
229
   * Uploads a small file to Box. For file sizes over 50MB we recommend using the Chunk Upload APIs.
230
   *
231
   * <p>The `attributes` part of the body must come **before** the `file` part. Requests that do not
232
   * follow this format when uploading the file will receive a HTTP `400` error with a
233
   * `metadata_after_file_contents` error code.
234
   *
235
   * @param requestBody Request body of uploadFile method
236
   * @param queryParams Query parameters of uploadFile method
237
   */
238
  public Files uploadFile(UploadFileRequestBody requestBody, UploadFileQueryParams queryParams) {
239
    return uploadFile(requestBody, queryParams, new UploadFileHeaders());
×
240
  }
241

242
  /**
243
   * Uploads a small file to Box. For file sizes over 50MB we recommend using the Chunk Upload APIs.
244
   *
245
   * <p>The `attributes` part of the body must come **before** the `file` part. Requests that do not
246
   * follow this format when uploading the file will receive a HTTP `400` error with a
247
   * `metadata_after_file_contents` error code.
248
   *
249
   * @param requestBody Request body of uploadFile method
250
   * @param headers Headers of uploadFile method
251
   */
252
  public Files uploadFile(UploadFileRequestBody requestBody, UploadFileHeaders headers) {
253
    return uploadFile(requestBody, new UploadFileQueryParams(), headers);
×
254
  }
255

256
  /**
257
   * Uploads a small file to Box. For file sizes over 50MB we recommend using the Chunk Upload APIs.
258
   *
259
   * <p>The `attributes` part of the body must come **before** the `file` part. Requests that do not
260
   * follow this format when uploading the file will receive a HTTP `400` error with a
261
   * `metadata_after_file_contents` error code.
262
   *
263
   * @param requestBody Request body of uploadFile method
264
   * @param queryParams Query parameters of uploadFile method
265
   * @param headers Headers of uploadFile method
266
   */
267
  public Files uploadFile(
268
      UploadFileRequestBody requestBody,
269
      UploadFileQueryParams queryParams,
270
      UploadFileHeaders headers) {
271
    Map<String, String> queryParamsMap =
×
272
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
×
273
    Map<String, String> headersMap =
×
274
        prepareParams(
×
275
            mergeMaps(
×
276
                mapOf(entryOf("content-md5", convertToString(headers.getContentMd5()))),
×
277
                headers.getExtraHeaders()));
×
278
    FetchResponse response =
×
279
        this.networkSession
280
            .getNetworkClient()
×
281
            .fetch(
×
282
                new FetchOptions.Builder(
283
                        String.join(
×
284
                            "",
285
                            this.networkSession.getBaseUrls().getUploadUrl(),
×
286
                            "/2.0/files/content"),
287
                        "POST")
288
                    .params(queryParamsMap)
×
289
                    .headers(headersMap)
×
290
                    .multipartData(
×
291
                        Arrays.asList(
×
292
                            new MultipartItem.Builder("attributes")
293
                                .data(JsonManager.serialize(requestBody.getAttributes()))
×
294
                                .build(),
×
295
                            new MultipartItem.Builder("file")
296
                                .fileStream(requestBody.getFile())
×
297
                                .fileName(requestBody.getFileFileName())
×
298
                                .contentType(requestBody.getFileContentType())
×
299
                                .build()))
×
300
                    .contentType("multipart/form-data")
×
301
                    .responseFormat(ResponseFormat.JSON)
×
302
                    .auth(this.auth)
×
303
                    .networkSession(this.networkSession)
×
304
                    .build());
×
305
    return JsonManager.deserialize(response.getData(), Files.class);
×
306
  }
307

308
  /**
309
   * Upload a file with a preflight check
310
   *
311
   * @param requestBody The requestBody parameter
312
   */
313
  public Files uploadWithPreflightCheck(UploadWithPreflightCheckRequestBody requestBody) {
314
    return uploadWithPreflightCheck(
×
315
        requestBody,
316
        new UploadWithPreflightCheckQueryParams(),
317
        new UploadWithPreflightCheckHeaders());
318
  }
319

320
  /**
321
   * Upload a file with a preflight check
322
   *
323
   * @param requestBody The requestBody parameter
324
   * @param queryParams Query parameters of uploadFile method
325
   */
326
  public Files uploadWithPreflightCheck(
327
      UploadWithPreflightCheckRequestBody requestBody,
328
      UploadWithPreflightCheckQueryParams queryParams) {
329
    return uploadWithPreflightCheck(
×
330
        requestBody, queryParams, new UploadWithPreflightCheckHeaders());
331
  }
332

333
  /**
334
   * Upload a file with a preflight check
335
   *
336
   * @param requestBody The requestBody parameter
337
   * @param headers Headers of uploadFile method
338
   */
339
  public Files uploadWithPreflightCheck(
340
      UploadWithPreflightCheckRequestBody requestBody, UploadWithPreflightCheckHeaders headers) {
341
    return uploadWithPreflightCheck(
×
342
        requestBody, new UploadWithPreflightCheckQueryParams(), headers);
343
  }
344

345
  /**
346
   * Upload a file with a preflight check
347
   *
348
   * @param requestBody The requestBody parameter
349
   * @param queryParams Query parameters of uploadFile method
350
   * @param headers Headers of uploadFile method
351
   */
352
  public Files uploadWithPreflightCheck(
353
      UploadWithPreflightCheckRequestBody requestBody,
354
      UploadWithPreflightCheckQueryParams queryParams,
355
      UploadWithPreflightCheckHeaders headers) {
356
    Map<String, String> queryParamsMap =
×
357
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
×
358
    Map<String, String> headersMap =
×
359
        prepareParams(
×
360
            mergeMaps(
×
361
                mapOf(entryOf("content-md5", convertToString(headers.getContentMd5()))),
×
362
                headers.getExtraHeaders()));
×
363
    UploadUrl preflightUploadUrl =
×
364
        this.preflightFileUploadCheck(
×
365
            new PreflightFileUploadCheckRequestBody.Builder()
366
                .name(requestBody.getAttributes().getName())
×
367
                .size(requestBody.getAttributes().getSize())
×
368
                .parent(
×
369
                    new PreflightFileUploadCheckRequestBodyParentField.Builder()
370
                        .id(requestBody.getAttributes().getParent().getId())
×
371
                        .build())
×
372
                .build(),
×
373
            new PreflightFileUploadCheckHeaders.Builder()
374
                .extraHeaders(headers.getExtraHeaders())
×
375
                .build());
×
376
    if (preflightUploadUrl.getUploadUrl() == null
×
377
        || !(preflightUploadUrl.getUploadUrl().contains("http"))) {
×
378
      throw new BoxSDKError("Unable to get preflight upload URL");
×
379
    }
380
    FetchResponse response =
×
381
        this.networkSession
382
            .getNetworkClient()
×
383
            .fetch(
×
384
                new FetchOptions.Builder(preflightUploadUrl.getUploadUrl(), "POST")
×
385
                    .params(queryParamsMap)
×
386
                    .headers(headersMap)
×
387
                    .multipartData(
×
388
                        Arrays.asList(
×
389
                            new MultipartItem.Builder("attributes")
390
                                .data(JsonManager.serialize(requestBody.getAttributes()))
×
391
                                .build(),
×
392
                            new MultipartItem.Builder("file")
393
                                .fileStream(requestBody.getFile())
×
394
                                .fileName(requestBody.getFileFileName())
×
395
                                .contentType(requestBody.getFileContentType())
×
396
                                .build()))
×
397
                    .contentType("multipart/form-data")
×
398
                    .responseFormat(ResponseFormat.JSON)
×
399
                    .auth(this.auth)
×
400
                    .networkSession(this.networkSession)
×
401
                    .build());
×
402
    return JsonManager.deserialize(response.getData(), Files.class);
×
403
  }
404

405
  public Authentication getAuth() {
406
    return auth;
×
407
  }
408

409
  public NetworkSession getNetworkSession() {
410
    return networkSession;
×
411
  }
412

413
  public static class Builder {
414

415
    protected Authentication auth;
416

417
    protected NetworkSession networkSession;
418

NEW
419
    public Builder() {}
×
420

421
    public Builder auth(Authentication auth) {
UNCOV
422
      this.auth = auth;
×
UNCOV
423
      return this;
×
424
    }
425

426
    public Builder networkSession(NetworkSession networkSession) {
UNCOV
427
      this.networkSession = networkSession;
×
UNCOV
428
      return this;
×
429
    }
430

431
    public UploadsManager build() {
NEW
432
      if (this.networkSession == null) {
×
NEW
433
        this.networkSession = new NetworkSession();
×
434
      }
435
      return new UploadsManager(this);
×
436
    }
437
  }
438
}
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