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

tomdesair / tus-java-server / 30198707711

26 Jul 2026 10:41AM UTC coverage: 96.232% (+1.3%) from 94.883%
30198707711

Pull #105

github

web-flow
Merge 4b35d5c45 into fd04a6140
Pull Request #105: WIP feat: Implement IETF Resumable Uploads for HTTP (RUFH) Protocol

1300 of 1404 branches covered (92.59%)

Branch coverage included in aggregate %.

847 of 848 new or added lines in 47 files covered. (99.88%)

4 existing lines in 2 files now uncovered.

2786 of 2842 relevant lines covered (98.03%)

6.4 hits per line

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

91.67
/src/main/java/me/desair/tus/server/upload/UploadStorageService.java
1
package me.desair.tus.server.upload;
2

3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.OutputStream;
6
import me.desair.tus.server.checksum.ChecksumAlgorithm;
7
import me.desair.tus.server.exception.TusException;
8
import me.desair.tus.server.exception.UploadNotFoundException;
9
import me.desair.tus.server.upload.concatenation.UploadConcatenationService;
10

11
/** Interface to a service that is able to store the (partially) uploaded files. */
12
public interface UploadStorageService {
13

14
  /**
15
   * Method to retrieve the upload info by its upload URL.
16
   *
17
   * @param uploadUrl The URL corresponding to this upload. This parameter can be null.
18
   * @param ownerKey A key representing the owner of the upload
19
   * @return The upload info matching the given URL, or null when not found.
20
   */
21
  UploadInfo getUploadInfo(String uploadUrl, String ownerKey) throws IOException;
22

23
  /**
24
   * Method to retrieve the upload info by its ID.
25
   *
26
   * @param id The ID of the upload
27
   * @return The matching upload info
28
   * @throws IOException When the service is not able to retrieve the upload information
29
   */
30
  UploadInfo getUploadInfo(UploadId id) throws IOException;
31

32
  /**
33
   * The URI which is configured as the upload endpoint.
34
   *
35
   * @return The URI
36
   */
37
  String getUploadUri();
38

39
  /**
40
   * Append the bytes in the give {@link InputStream} to the upload with the given ID starting at
41
   * the provided offset. This method also updates the {@link UploadInfo} corresponding to this
42
   * upload. The Upload Storage server should not exceed its max upload size when writing bytes.
43
   *
44
   * @param upload The ID of the upload
45
   * @param inputStream The input stream containing the bytes to append
46
   * @return The new {@link UploadInfo} for this upload
47
   */
48
  UploadInfo append(UploadInfo upload, InputStream inputStream) throws IOException, TusException;
49

50
  /**
51
   * Limit the maximum upload size to the given value.
52
   *
53
   * @param maxUploadSize The maximum upload limit to set
54
   */
55
  void setMaxUploadSize(Long maxUploadSize);
56

57
  /**
58
   * Get the maximum upload size configured on this storage service.
59
   *
60
   * @return The maximum upload size or zero if no maximum
61
   */
62
  long getMaxUploadSize();
63

64
  /**
65
   * Limit the maximum append payload size to the given value in bytes.
66
   *
67
   * @param maxAppendSize The maximum append limit to set
68
   */
69
  default void setMaxAppendSize(Long maxAppendSize) {
70
    // Default no-op for third-party implementations
NEW
71
  }
×
72

73
  /**
74
   * Get the maximum append payload size configured on this storage service. If not explicitly set,
75
   * defaults to the maximum upload size limit if set.
76
   *
77
   * @return The maximum append size in bytes, or null if no maximum append limit applies
78
   */
79
  default Long getMaxAppendSize() {
80
    long maxUpload = getMaxUploadSize();
3✔
81
    return maxUpload > 0 ? maxUpload : null;
9✔
82
  }
83

84
  /**
85
   * Create an upload location with the given upload information.
86
   *
87
   * @param info The Upload information to use to create the new upload
88
   * @param ownerKey A key representing the owner of the upload
89
   * @return An {@link UploadInfo} object containing the information used to create the upload and
90
   *     its unique ID
91
   */
92
  UploadInfo create(UploadInfo info, String ownerKey) throws IOException;
93

94
  /**
95
   * Update the upload information for the provided ID.
96
   *
97
   * @param uploadInfo The upload info object containing the ID and information to update
98
   */
99
  void update(UploadInfo uploadInfo) throws IOException, UploadNotFoundException;
100

101
  /**
102
   * Get the uploaded bytes corresponding to the given upload URL as a stream.
103
   *
104
   * @param uploadUri The URI
105
   * @param ownerKey The owner key of this upload
106
   * @return an {@link OutputStream} containing the bytes of the upload
107
   */
108
  InputStream getUploadedBytes(String uploadUri, String ownerKey)
109
      throws IOException, UploadNotFoundException;
110

111
  /**
112
   * Get the uploaded bytes corresponding to the given upload ID as a stream.
113
   *
114
   * @param id the ID of the upload
115
   * @return an {@link OutputStream} containing the bytes of the upload
116
   * @throws IOException When retrieving the bytes from the storage layer fails
117
   * @throws UploadNotFoundException When the proved id is not linked to an upload
118
   */
119
  InputStream getUploadedBytes(UploadId id) throws IOException, UploadNotFoundException;
120

121
  /**
122
   * Copy the uploaded bytes to the given output stream.
123
   *
124
   * @param info The upload of which we should copy the bytes
125
   * @param outputStream The output stream where we have to copy the bytes to
126
   */
127
  void copyUploadTo(UploadInfo info, OutputStream outputStream)
128
      throws UploadNotFoundException, IOException;
129

130
  /**
131
   * Clean up any upload data that is expired according to the configured expiration time.
132
   *
133
   * @param uploadLockingService An {@link UploadLockingService} that can be used to check and lock
134
   *     uploads
135
   */
136
  void cleanupExpiredUploads(UploadLockingService uploadLockingService) throws IOException;
137

138
  /**
139
   * Remove the given last amount of bytes from the uploaded data.
140
   *
141
   * @param uploadInfo Upload of which to remove the bytes
142
   * @param byteCount The number of bytes to remove at the end
143
   */
144
  void removeLastNumberOfBytes(UploadInfo uploadInfo, long byteCount)
145
      throws UploadNotFoundException, IOException;
146

147
  /**
148
   * Terminate completed and unfinished uploads allowing the Server to free up used resources.
149
   *
150
   * @param uploadInfo The upload to terminate
151
   */
152
  void terminateUpload(UploadInfo uploadInfo) throws UploadNotFoundException, IOException;
153

154
  /**
155
   * Get the expiration period of an upload in milliseconds.
156
   *
157
   * @return The number of milliseconds before an upload expires, or null if it cannot expire
158
   */
159
  Long getUploadExpirationPeriod();
160

161
  /**
162
   * Set the expiration period after which an in-progress upload expires.
163
   *
164
   * @param uploadExpirationPeriod The period in milliseconds
165
   */
166
  void setUploadExpirationPeriod(Long uploadExpirationPeriod);
167

168
  /**
169
   * Set the {@link UploadConcatenationService} that this upload storage service should use.
170
   *
171
   * @param concatenationService The UploadConcatenationService implementation to use
172
   */
173
  void setUploadConcatenationService(UploadConcatenationService concatenationService);
174

175
  /**
176
   * Return the {@link UploadConcatenationService} implementation that this upload service is using.
177
   *
178
   * @return The UploadConcatenationService that is being used
179
   */
180
  UploadConcatenationService getUploadConcatenationService();
181

182
  /**
183
   * Set an instance if IdFactory to be used for creating identities and extracting them from
184
   * uploadUris.
185
   *
186
   * @param idFactory The {@link UploadIdFactory} to use within this storage service
187
   */
188
  void setIdFactory(UploadIdFactory idFactory);
189

190
  /**
191
   * Set whether duplicate file processing based on checksum is enabled.
192
   *
193
   * @param enabled True if enabled, false otherwise
194
   */
195
  default void setUploadDeduplicationEnabled(boolean enabled) {
196
    // No-op for backward compatibility
197
  }
1✔
198

199
  /**
200
   * Check if duplicate file processing based on checksum is enabled.
201
   *
202
   * @return True if enabled, false otherwise
203
   */
204
  default boolean isUploadDeduplicationEnabled() {
205
    return false;
2✔
206
  }
207

208
  /**
209
   * Look up an existing completed upload based on a checksum value and algorithm.
210
   *
211
   * @param checksum The checksum value to search for
212
   * @param algorithm The checksum algorithm used
213
   * @return The UploadInfo of the existing completed upload, or null if not found
214
   */
215
  default UploadInfo getUploadInfoByChecksum(String checksum, ChecksumAlgorithm algorithm)
216
      throws IOException {
217
    return null;
2✔
218
  }
219

220
  /**
221
   * Get the minimum append size limit in bytes for a single upload append or creation request.
222
   *
223
   * @return The minimum append size in bytes, or null if no minimum append size limit applies
224
   */
225
  default Long getMinAppendSize() {
226
    return null;
2✔
227
  }
228

229
  /**
230
   * Set the minimum append size limit in bytes for a single upload append or creation request.
231
   *
232
   * @param minAppendSize The minimum append size in bytes, or null for no limit
233
   */
234
  default void setMinAppendSize(Long minAppendSize) {
235
    // No-op for backward compatibility
236
  }
1✔
237

238
  /**
239
   * Get the minimum total upload representation size in bytes.
240
   *
241
   * @return The minimum size in bytes, or null if no minimum size limit applies
242
   */
243
  default Long getMinSize() {
244
    return null;
2✔
245
  }
246

247
  /**
248
   * Set the minimum total upload representation size in bytes.
249
   *
250
   * @param minSize The minimum size in bytes, or null for no limit
251
   */
252
  default void setMinSize(Long minSize) {
253
    // No-op for backward compatibility
254
  }
1✔
255
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc