Skip to content

Commit

Permalink
fix: Checkstyle warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdesair committed Jul 24, 2023
1 parent 21035b6 commit 1c4adf1
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 29 deletions.
5 changes: 5 additions & 0 deletions src/main/java/me/desair/tus/server/HttpMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum HttpMethod {
TRACE,
PATCH;

/** Get the {@link HttpMethod} instance that matches the provided name. */
public static HttpMethod forName(String name) {
for (HttpMethod method : HttpMethod.values()) {
if (StringUtils.equalsIgnoreCase(method.name(), name)) {
Expand All @@ -33,6 +34,10 @@ public static HttpMethod forName(String name) {
return null;
}

/**
* Get the {@link HttpMethod} instance of this request if it is present in the provided
* supportedHttpMethods set.
*/
public static HttpMethod getMethodIfSupported(
HttpServletRequest request, Set<HttpMethod> supportedHttpMethods) {
Validate.notNull(request, "The HttpServletRequest cannot be null");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/me/desair/tus/server/TusExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import me.desair.tus.server.util.TusServletRequest;
import me.desair.tus.server.util.TusServletResponse;

/** Interface that represents an extension in the tus protocol */
/** Interface that represents an extension in the tus protocol. */
public interface TusExtension {

/**
* The name of the Tus extension that can be used to disable or enable the extension
* The name of the Tus extension that can be used to disable or enable the extension.
*
* @return The name of the extension
*/
String getName();

/**
* Validate the given request
* Validate the given request.
*
* @param method The HTTP method of this request (taking into account overrides)
* @param servletRequest The HTTP request
Expand All @@ -36,7 +36,7 @@ void validate(
throws TusException, IOException;

/**
* Process the given request
* Process the given request.
*
* @param method The HTTP method of this request (taking into account overrides)
* @param servletRequest The HTTP request
Expand Down Expand Up @@ -75,7 +75,7 @@ void handleError(
throws IOException, TusException;

/**
* The minimal list of HTTP methods that this extension needs to function properly
* The minimal list of HTTP methods that this extension needs to function properly.
*
* @return The list of HTTP methods required by this extension
*/
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/me/desair/tus/server/TusFileUploadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class TusFileUploadService {
private boolean isThreadLocalCacheEnabled = false;
private boolean isChunkedTransferDecodingEnabled = false;

/** Constructor. */
public TusFileUploadService() {
String storagePath = FileUtils.getTempDirectoryPath() + File.separator + "tus";
this.uploadStorageService = new DiskStorageService(idFactory, storagePath);
Expand Down Expand Up @@ -104,9 +105,9 @@ public TusFileUploadService withMaxUploadSize(Long maxUploadSize) {
*/
public TusFileUploadService withUploadIdFactory(UploadIdFactory uploadIdFactory) {
Validate.notNull(uploadIdFactory, "The UploadIdFactory cannot be null");
String previousUploadURI = this.idFactory.getUploadUri();
String previousUploadUri = this.idFactory.getUploadUri();
this.idFactory = uploadIdFactory;
this.idFactory.setUploadUri(previousUploadURI);
this.idFactory.setUploadUri(previousUploadUri);
this.uploadStorageService.setIdFactory(this.idFactory);
this.uploadLockingService.setIdFactory(this.idFactory);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
public class TusResumableValidator implements RequestValidator {

/** Validate tus protocol version. */
public void validate(
HttpMethod method,
HttpServletRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import me.desair.tus.server.util.TusServletRequest;
import me.desair.tus.server.util.TusServletResponse;

/** Send the uploaded bytes of finished uploads */
/** Send the uploaded bytes of finished uploads. */
public class DownloadGetRequestHandler extends AbstractRequestHandler {

private static final String CONTENT_DISPOSITION_FORMAT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

/**
* Exception thrown when accessing an upload that is still in progress and this is not supported by
* the operation
* the operation.
*/
public class UploadInProgressException extends TusException {
/** Constructor. */
public UploadInProgressException(String message) {
// 422 Unprocessable Entity
// The request was well-formed but was unable to be followed due to semantic errors.
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/me/desair/tus/server/upload/UploadInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import jakarta.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import me.desair.tus.server.util.Utils;
import org.apache.commons.codec.Charsets;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class UploadInfo implements Serializable {
private List<String> concatenationPartIds;
private String uploadConcatHeaderValue;

/** Default constructor to use if an upload is created without HTTP request */
/** Default constructor to use if an upload is created without HTTP request. */
public UploadInfo() {
creationTimestamp = getCurrentTime();
offset = 0L;
Expand All @@ -45,7 +45,7 @@ public UploadInfo() {
}

/**
* Constructor to use if the upload is created using an HTTP request (which is usually the case)
* Constructor to use if the upload is created using an HTTP request (which is usually the case).
*
* @param servletRequest The HTTP request that creates the new upload
*/
Expand Down Expand Up @@ -131,7 +131,7 @@ public Map<String, String> getMetadata() {
}

/**
* Did the client provide any metadata when creating this upload?
* Check if the client provided any metadata when creating this upload.
*
* @return True if metadata is present, false otherwise
*/
Expand Down Expand Up @@ -160,7 +160,7 @@ public void setLength(Long length) {
}

/**
* Did the client already provide a total upload length?
* Check if the client already provided a total upload length.
*
* @return True if the total upload length is known, false otherwise
*/
Expand All @@ -170,7 +170,7 @@ public boolean hasLength() {

/**
* An upload is still in progress: - as long as we did not receive information on the total length
* (see {@link UploadInfo#getLength()}) - the total length does not match the current offset
* (see {@link UploadInfo#getLength()}) - the total length does not match the current offset.
*
* @return true if the upload is still in progress, false otherwise
*/
Expand All @@ -180,7 +180,7 @@ public boolean isUploadInProgress() {

/**
* Set the unique identifier of this upload process The unique identifier is represented by a
* {@link UploadId} instance
* {@link UploadId} instance.
*
* @param id The unique identifier to use
*/
Expand All @@ -190,7 +190,7 @@ public void setId(UploadId id) {

/**
* Get the unique identifier of this upload process The unique identifier is represented by a
* {@link UploadId} instance
* {@link UploadId} instance.
*
* @return The unique upload identifier of this upload
*/
Expand Down Expand Up @@ -222,7 +222,7 @@ public String getOwnerKey() {

/**
* Indicates the timestamp after which the upload expires in milliseconds since January 1, 1970,
* 00:00:00 GMT
* 00:00:00 GMT.
*
* @return The expiration timestamp in milliseconds
*/
Expand All @@ -241,7 +241,7 @@ public void updateExpiration(long expirationPeriod) {

/**
* The timestamp this upload was created in number of milliseconds since January 1, 1970, 00:00:00
* GMT
* GMT.
*
* @return Creation timestamp of this upload object
*/
Expand Down Expand Up @@ -301,7 +301,7 @@ public List<String> getConcatenationPartIds() {
}

/**
* Set the original value of the "Upload-Concat" HTTP header that was provided by the client
* Set the original value of the "Upload-Concat" HTTP header that was provided by the client.
*
* @param uploadConcatHeaderValue The original value of the "Upload-Concat" HTTP header
*/
Expand All @@ -310,7 +310,7 @@ public void setUploadConcatHeaderValue(String uploadConcatHeaderValue) {
}

/**
* Get the original value of the "Upload-Concat" HTTP header that was provided by the client
* Get the original value of the "Upload-Concat" HTTP header that was provided by the client.
*
* @return The original value of the "Upload-Concat" HTTP header
*/
Expand Down Expand Up @@ -354,7 +354,7 @@ public String getFileMimeType() {
}

/**
* Check if this upload is expired
* Check if this upload is expired.
*
* @return True if the upload is expired, false otherwise
*/
Expand Down Expand Up @@ -404,7 +404,7 @@ public int hashCode() {
.toHashCode();
}

/** Get the current time in the number of milliseconds since January 1, 1970, 00:00:00 GMT */
/** Get the current time in the number of milliseconds since January 1, 1970, 00:00:00 GMT. */
protected long getCurrentTime() {
return new Date().getTime();
}
Expand All @@ -421,7 +421,7 @@ private String decode(String encodedValue) {
if (encodedValue == null) {
return null;
} else {
return new String(Base64.decodeBase64(encodedValue), Charsets.UTF_8);
return new String(Base64.decodeBase64(encodedValue), StandardCharsets.UTF_8);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class FileBasedLock implements UploadLock {
private FileChannel fileChannel = null;
protected Path lockPath;

/** Constructor. */
public FileBasedLock(String uploadUri, Path lockPath)
throws UploadAlreadyLockedException, IOException {
Validate.notBlank(uploadUri, "The upload URI cannot be blank");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Abstract {@link me.desair.tus.server.RequestHandler} implementation that contains the common
* functionality
* functionality.
*/
public abstract class AbstractRequestHandler implements RequestHandler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import me.desair.tus.server.exception.TusException;
import me.desair.tus.server.upload.UploadStorageService;

/** Abstract class to implement a tus extension using validators and request handlers. */
public abstract class AbstractTusExtension implements TusExtension {

private List<RequestValidator> requestValidators = new LinkedList<>();
private List<RequestHandler> requestHandlers = new LinkedList<>();

public AbstractTusExtension() {
protected AbstractTusExtension() {
initValidators(requestValidators);
initRequestHandlers(requestHandlers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

/** Test cases for the {@link TusFileUploadService}. */
public class ITTusFileUploadService {

protected static final String UPLOAD_URI = "/test/upload";
Expand Down Expand Up @@ -1241,7 +1242,7 @@ public void testConcatenationUnfinished() throws Exception {
}

@Test
public void testChunkedDecodingDisabledAndRegexUploadURI() throws Exception {
public void testChunkedDecodingDisabledAndRegexUploadUri() throws Exception {
String chunkedContent =
"1B;test=value\r\nThis upload looks chunked, \r\n" + "D\r\nbut it's not!\r\n" + "\r\n0\r\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@

import me.desair.tus.server.HttpMethod;
import me.desair.tus.server.exception.UnsupportedMethodException;
import me.desair.tus.server.upload.UploadIdFactory;
import me.desair.tus.server.upload.UploadStorageService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;

/** Test cases for the {@link HttpMethodValidator}. */
public class HttpMethodValidatorTest {

private MockHttpServletRequest servletRequest;
private HttpMethodValidator validator;
private UploadStorageService uploadStorageService;
private UploadIdFactory idFactory;

@Before
public void setUp() {
Expand Down

0 comments on commit 1c4adf1

Please sign in to comment.