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

tomdesair / tus-java-server / 27438081142

12 Jun 2026 07:26PM UTC coverage: 93.731% (-1.3%) from 95.005%
27438081142

Pull #79

github

web-flow
Merge 7d044afe0 into a7a0299f3
Pull Request #79: Implement File Deduplication by Hash

561 of 640 branches covered (87.66%)

Branch coverage included in aggregate %.

143 of 159 new or added lines in 8 files covered. (89.94%)

7 existing lines in 1 file now uncovered.

1607 of 1673 relevant lines covered (96.05%)

6.06 hits per line

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

0.0
/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
   * Create an upload location with the given upload information.
66
   *
67
   * @param info The Upload information to use to create the new upload
68
   * @param ownerKey A key representing the owner of the upload
69
   * @return An {@link UploadInfo} object containing the information used to create the upload and
70
   *     its unique ID
71
   */
72
  UploadInfo create(UploadInfo info, String ownerKey) throws IOException;
73

74
  /**
75
   * Update the upload information for the provided ID.
76
   *
77
   * @param uploadInfo The upload info object containing the ID and information to update
78
   */
79
  void update(UploadInfo uploadInfo) throws IOException, UploadNotFoundException;
80

81
  /**
82
   * Get the uploaded bytes corresponding to the given upload URL as a stream.
83
   *
84
   * @param uploadUri The URI
85
   * @param ownerKey The owner key of this upload
86
   * @return an {@link OutputStream} containing the bytes of the upload
87
   */
88
  InputStream getUploadedBytes(String uploadUri, String ownerKey)
89
      throws IOException, UploadNotFoundException;
90

91
  /**
92
   * Get the uploaded bytes corresponding to the given upload ID as a stream.
93
   *
94
   * @param id the ID of the upload
95
   * @return an {@link OutputStream} containing the bytes of the upload
96
   * @throws IOException When retrieving the bytes from the storage layer fails
97
   * @throws UploadNotFoundException When the proved id is not linked to an upload
98
   */
99
  InputStream getUploadedBytes(UploadId id) throws IOException, UploadNotFoundException;
100

101
  /**
102
   * Copy the uploaded bytes to the given output stream.
103
   *
104
   * @param info The upload of which we should copy the bytes
105
   * @param outputStream The output stream where we have to copy the bytes to
106
   */
107
  void copyUploadTo(UploadInfo info, OutputStream outputStream)
108
      throws UploadNotFoundException, IOException;
109

110
  /**
111
   * Clean up any upload data that is expired according to the configured expiration time.
112
   *
113
   * @param uploadLockingService An {@link UploadLockingService} that can be used to check and lock
114
   *     uploads
115
   */
116
  void cleanupExpiredUploads(UploadLockingService uploadLockingService) throws IOException;
117

118
  /**
119
   * Remove the given last amount of bytes from the uploaded data.
120
   *
121
   * @param uploadInfo Upload of which to remove the bytes
122
   * @param byteCount The number of bytes to remove at the end
123
   */
124
  void removeLastNumberOfBytes(UploadInfo uploadInfo, long byteCount)
125
      throws UploadNotFoundException, IOException;
126

127
  /**
128
   * Terminate completed and unfinished uploads allowing the Server to free up used resources.
129
   *
130
   * @param uploadInfo The upload to terminate
131
   */
132
  void terminateUpload(UploadInfo uploadInfo) throws UploadNotFoundException, IOException;
133

134
  /**
135
   * Get the expiration period of an upload in milliseconds.
136
   *
137
   * @return The number of milliseconds before an upload expires, or null if it cannot expire
138
   */
139
  Long getUploadExpirationPeriod();
140

141
  /**
142
   * Set the expiration period after which an in-progress upload expires.
143
   *
144
   * @param uploadExpirationPeriod The period in milliseconds
145
   */
146
  void setUploadExpirationPeriod(Long uploadExpirationPeriod);
147

148
  /**
149
   * Set the {@link UploadConcatenationService} that this upload storage service should use.
150
   *
151
   * @param concatenationService The UploadConcatenationService implementation to use
152
   */
153
  void setUploadConcatenationService(UploadConcatenationService concatenationService);
154

155
  /**
156
   * Return the {@link UploadConcatenationService} implementation that this upload service is using.
157
   *
158
   * @return The UploadConcatenationService that is being used
159
   */
160
  UploadConcatenationService getUploadConcatenationService();
161

162
  /**
163
   * Set an instance if IdFactory to be used for creating identities and extracting them from
164
   * uploadUris.
165
   *
166
   * @param idFactory The {@link UploadIdFactory} to use within this storage service
167
   */
168
  void setIdFactory(UploadIdFactory idFactory);
169

170
  /**
171
   * Set whether duplicate file processing based on checksum is enabled.
172
   *
173
   * @param enabled True if enabled, false otherwise
174
   */
175
  default void setUploadDeduplicationEnabled(boolean enabled) {
176
    // No-op for backward compatibility
NEW
177
  }
×
178

179
  /**
180
   * Check if duplicate file processing based on checksum is enabled.
181
   *
182
   * @return True if enabled, false otherwise
183
   */
184
  default boolean isUploadDeduplicationEnabled() {
NEW
185
    return false;
×
186
  }
187

188
  /**
189
   * Look up an existing completed upload based on a checksum value and algorithm.
190
   *
191
   * @param checksum The checksum value to search for
192
   * @param algorithm The checksum algorithm used
193
   * @return The UploadInfo of the existing completed upload, or null if not found
194
   */
195
  default UploadInfo getUploadInfoByChecksum(String checksum, ChecksumAlgorithm algorithm)
196
      throws IOException {
NEW
197
    return null;
×
198
  }
199
}
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