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

box / box-java-sdk / #5076

07 Oct 2025 12:35PM UTC coverage: 37.132% (+0.007%) from 37.125%
#5076

push

github

web-flow
test: Change `Event.additionalDetails` field assertion in events test (box/box-codegen#858) (#1491)

18454 of 49699 relevant lines covered (37.13%)

0.37 hits per line

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

92.19
/src/main/java/com/box/sdkgen/managers/zipdownloads/ZipDownloadsManager.java
1
package com.box.sdkgen.managers.zipdownloads;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
4
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
5
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
6

7
import com.box.sdkgen.networking.auth.Authentication;
8
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
9
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
10
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
11
import com.box.sdkgen.networking.network.NetworkSession;
12
import com.box.sdkgen.schemas.zipdownload.ZipDownload;
13
import com.box.sdkgen.schemas.zipdownloadrequest.ZipDownloadRequest;
14
import com.box.sdkgen.schemas.zipdownloadstatus.ZipDownloadStatus;
15
import com.box.sdkgen.serialization.json.JsonManager;
16
import java.io.InputStream;
17
import java.util.Map;
18

19
public class ZipDownloadsManager {
20

21
  public Authentication auth;
22

23
  public NetworkSession networkSession;
24

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

29
  protected ZipDownloadsManager(Builder builder) {
1✔
30
    this.auth = builder.auth;
1✔
31
    this.networkSession = builder.networkSession;
1✔
32
  }
1✔
33

34
  /**
35
   * Creates a request to download multiple files and folders as a single `zip` archive file. This
36
   * API does not return the archive but instead performs all the checks to ensure that the user has
37
   * access to all the items, and then returns a `download_url` and a `status_url` that can be used
38
   * to download the archive.
39
   *
40
   * <p>The limit for an archive is either the Account's upload limit or 10,000 files, whichever is
41
   * met first.
42
   *
43
   * <p>**Note**: Downloading a large file can be affected by various factors such as distance,
44
   * network latency, bandwidth, and congestion, as well as packet loss ratio and current server
45
   * load. For these reasons we recommend that a maximum ZIP archive total size does not exceed
46
   * 25GB.
47
   *
48
   * @param requestBody Request body of createZipDownload method
49
   */
50
  public ZipDownload createZipDownload(ZipDownloadRequest requestBody) {
51
    return createZipDownload(requestBody, new CreateZipDownloadHeaders());
1✔
52
  }
53

54
  /**
55
   * Creates a request to download multiple files and folders as a single `zip` archive file. This
56
   * API does not return the archive but instead performs all the checks to ensure that the user has
57
   * access to all the items, and then returns a `download_url` and a `status_url` that can be used
58
   * to download the archive.
59
   *
60
   * <p>The limit for an archive is either the Account's upload limit or 10,000 files, whichever is
61
   * met first.
62
   *
63
   * <p>**Note**: Downloading a large file can be affected by various factors such as distance,
64
   * network latency, bandwidth, and congestion, as well as packet loss ratio and current server
65
   * load. For these reasons we recommend that a maximum ZIP archive total size does not exceed
66
   * 25GB.
67
   *
68
   * @param requestBody Request body of createZipDownload method
69
   * @param headers Headers of createZipDownload method
70
   */
71
  public ZipDownload createZipDownload(
72
      ZipDownloadRequest requestBody, CreateZipDownloadHeaders headers) {
73
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
74
    FetchResponse response =
1✔
75
        this.networkSession
76
            .getNetworkClient()
1✔
77
            .fetch(
1✔
78
                new FetchOptions.Builder(
79
                        String.join(
1✔
80
                            "",
81
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
82
                            "/2.0/zip_downloads"),
83
                        "POST")
84
                    .headers(headersMap)
1✔
85
                    .data(JsonManager.serialize(requestBody))
1✔
86
                    .contentType("application/json")
1✔
87
                    .responseFormat(ResponseFormat.JSON)
1✔
88
                    .auth(this.auth)
1✔
89
                    .networkSession(this.networkSession)
1✔
90
                    .build());
1✔
91
    return JsonManager.deserialize(response.getData(), ZipDownload.class);
1✔
92
  }
93

94
  /**
95
   * Returns the contents of a `zip` archive in binary format. This URL does not require any form of
96
   * authentication and could be used in a user's browser to download the archive to a user's
97
   * device.
98
   *
99
   * <p>By default, this URL is only valid for a few seconds from the creation of the request for
100
   * this archive. Once a download has started it can not be stopped and resumed, instead a new
101
   * request for a zip archive would need to be created.
102
   *
103
   * <p>The URL of this endpoint should not be considered as fixed. Instead, use the [Create zip
104
   * download](e://post_zip_downloads) API to request to create a `zip` archive, and then follow the
105
   * `download_url` field in the response to this endpoint.
106
   *
107
   * @param downloadUrl The URL that can be used to download created `zip` archive. Example:
108
   *     `https://dl.boxcloud.com/2.0/zip_downloads/29l00nfxDyHOt7RphI9zT_w==nDnZEDjY2S8iEWWCHEEiptFxwoWojjlibZjJ6geuE5xnXENDTPxzgbks_yY=/content`
109
   */
110
  public InputStream getZipDownloadContent(String downloadUrl) {
111
    return getZipDownloadContent(downloadUrl, new GetZipDownloadContentHeaders());
1✔
112
  }
113

114
  /**
115
   * Returns the contents of a `zip` archive in binary format. This URL does not require any form of
116
   * authentication and could be used in a user's browser to download the archive to a user's
117
   * device.
118
   *
119
   * <p>By default, this URL is only valid for a few seconds from the creation of the request for
120
   * this archive. Once a download has started it can not be stopped and resumed, instead a new
121
   * request for a zip archive would need to be created.
122
   *
123
   * <p>The URL of this endpoint should not be considered as fixed. Instead, use the [Create zip
124
   * download](e://post_zip_downloads) API to request to create a `zip` archive, and then follow the
125
   * `download_url` field in the response to this endpoint.
126
   *
127
   * @param downloadUrl The URL that can be used to download created `zip` archive. Example:
128
   *     `https://dl.boxcloud.com/2.0/zip_downloads/29l00nfxDyHOt7RphI9zT_w==nDnZEDjY2S8iEWWCHEEiptFxwoWojjlibZjJ6geuE5xnXENDTPxzgbks_yY=/content`
129
   * @param headers Headers of getZipDownloadContent method
130
   */
131
  public InputStream getZipDownloadContent(
132
      String downloadUrl, GetZipDownloadContentHeaders headers) {
133
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
134
    FetchResponse response =
1✔
135
        this.networkSession
136
            .getNetworkClient()
1✔
137
            .fetch(
1✔
138
                new FetchOptions.Builder(downloadUrl, "GET")
139
                    .headers(headersMap)
1✔
140
                    .responseFormat(ResponseFormat.BINARY)
1✔
141
                    .auth(this.auth)
1✔
142
                    .networkSession(this.networkSession)
1✔
143
                    .build());
1✔
144
    return response.getContent();
1✔
145
  }
146

147
  /**
148
   * Returns the download status of a `zip` archive, allowing an application to inspect the progress
149
   * of the download as well as the number of items that might have been skipped.
150
   *
151
   * <p>This endpoint can only be accessed once the download has started. Subsequently this endpoint
152
   * is valid for 12 hours from the start of the download.
153
   *
154
   * <p>The URL of this endpoint should not be considered as fixed. Instead, use the [Create zip
155
   * download](e://post_zip_downloads) API to request to create a `zip` archive, and then follow the
156
   * `status_url` field in the response to this endpoint.
157
   *
158
   * @param statusUrl The URL that can be used to get the status of the `zip` archive being
159
   *     downloaded. Example:
160
   *     `https://dl.boxcloud.com/2.0/zip_downloads/29l00nfxDyHOt7RphI9zT_w==nDnZEDjY2S8iEWWCHEEiptFxwoWojjlibZjJ6geuE5xnXENDTPxzgbks_yY=/status`
161
   */
162
  public ZipDownloadStatus getZipDownloadStatus(String statusUrl) {
163
    return getZipDownloadStatus(statusUrl, new GetZipDownloadStatusHeaders());
1✔
164
  }
165

166
  /**
167
   * Returns the download status of a `zip` archive, allowing an application to inspect the progress
168
   * of the download as well as the number of items that might have been skipped.
169
   *
170
   * <p>This endpoint can only be accessed once the download has started. Subsequently this endpoint
171
   * is valid for 12 hours from the start of the download.
172
   *
173
   * <p>The URL of this endpoint should not be considered as fixed. Instead, use the [Create zip
174
   * download](e://post_zip_downloads) API to request to create a `zip` archive, and then follow the
175
   * `status_url` field in the response to this endpoint.
176
   *
177
   * @param statusUrl The URL that can be used to get the status of the `zip` archive being
178
   *     downloaded. Example:
179
   *     `https://dl.boxcloud.com/2.0/zip_downloads/29l00nfxDyHOt7RphI9zT_w==nDnZEDjY2S8iEWWCHEEiptFxwoWojjlibZjJ6geuE5xnXENDTPxzgbks_yY=/status`
180
   * @param headers Headers of getZipDownloadStatus method
181
   */
182
  public ZipDownloadStatus getZipDownloadStatus(
183
      String statusUrl, GetZipDownloadStatusHeaders headers) {
184
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
185
    FetchResponse response =
1✔
186
        this.networkSession
187
            .getNetworkClient()
1✔
188
            .fetch(
1✔
189
                new FetchOptions.Builder(statusUrl, "GET")
190
                    .headers(headersMap)
1✔
191
                    .responseFormat(ResponseFormat.JSON)
1✔
192
                    .auth(this.auth)
1✔
193
                    .networkSession(this.networkSession)
1✔
194
                    .build());
1✔
195
    return JsonManager.deserialize(response.getData(), ZipDownloadStatus.class);
1✔
196
  }
197

198
  /**
199
   * Creates a zip and downloads its content
200
   *
201
   * @param requestBody Zip download request body
202
   */
203
  public InputStream downloadZip(ZipDownloadRequest requestBody) {
204
    return downloadZip(requestBody, new DownloadZipHeaders());
1✔
205
  }
206

207
  /**
208
   * Creates a zip and downloads its content
209
   *
210
   * @param requestBody Zip download request body
211
   * @param headers Headers of zip download method
212
   */
213
  public InputStream downloadZip(ZipDownloadRequest requestBody, DownloadZipHeaders headers) {
214
    ZipDownload zipDownloadSession =
1✔
215
        this.createZipDownload(
1✔
216
            new ZipDownloadRequest.Builder(requestBody.getItems())
1✔
217
                .downloadFileName(requestBody.getDownloadFileName())
1✔
218
                .build(),
1✔
219
            new CreateZipDownloadHeaders.Builder().extraHeaders(headers.getExtraHeaders()).build());
1✔
220
    return this.getZipDownloadContent(
1✔
221
        zipDownloadSession.getDownloadUrl(),
1✔
222
        new GetZipDownloadContentHeaders.Builder().extraHeaders(headers.getExtraHeaders()).build());
1✔
223
  }
224

225
  public Authentication getAuth() {
226
    return auth;
×
227
  }
228

229
  public NetworkSession getNetworkSession() {
230
    return networkSession;
×
231
  }
232

233
  public static class Builder {
234

235
    protected Authentication auth;
236

237
    protected NetworkSession networkSession;
238

239
    public Builder() {
1✔
240
      this.networkSession = new NetworkSession();
1✔
241
    }
1✔
242

243
    public Builder auth(Authentication auth) {
244
      this.auth = auth;
1✔
245
      return this;
1✔
246
    }
247

248
    public Builder networkSession(NetworkSession networkSession) {
249
      this.networkSession = networkSession;
1✔
250
      return this;
1✔
251
    }
252

253
    public ZipDownloadsManager build() {
254
      return new ZipDownloadsManager(this);
1✔
255
    }
256
  }
257
}
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