diff --git a/core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/Mimetype.java b/core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/Mimetype.java index 887e21182aee..8c50fa7df290 100644 --- a/core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/Mimetype.java +++ b/core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/Mimetype.java @@ -116,10 +116,6 @@ public static Mimetype getInstance() { * to find the corresponding mime type. If the file has no extension, or the extension is not * available in the listing contained in this class, the default mimetype * application/octet-stream is returned. - *

- * A file extension is one or more characters that occur after the last period (.) in the file's name. - * If a file has no extension, - * Guesses the mimetype of file data based on the file's extension. * * @param path the file whose extension may match a known mimetype. * @return the file's mimetype based on its extension, or a default value of @@ -132,7 +128,7 @@ public String getMimetype(Path path) { if (file != null) { return getMimetype(file.toString()); } - return null; + return MIMETYPE_OCTET_STREAM; } /** @@ -140,10 +136,6 @@ public String getMimetype(Path path) { * to find the corresponding mime type. If the file has no extension, or the extension is not * available in the listing contained in this class, the default mimetype * application/octet-stream is returned. - *

- * A file extension is one or more characters that occur after the last period (.) in the file's name. - * If a file has no extension, - * Guesses the mimetype of file data based on the file's extension. * * @param file the file whose extension may match a known mimetype. * @return the file's mimetype based on its extension, or a default value of @@ -159,10 +151,6 @@ public String getMimetype(File file) { * no extension, or the extension is not available in the listing contained * in this class, the default mimetype application/octet-stream * is returned. - *

- * A file extension is one or more characters that occur after the last - * period (.) in the file's name. If a file has no extension, Guesses the - * mimetype of file data based on the file's extension. * * @param fileName The name of the file whose extension may match a known * mimetype. diff --git a/core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/util/MimetypeTest.java b/core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/util/MimetypeTest.java index 9f94d72e0032..a4dbd7df4611 100644 --- a/core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/util/MimetypeTest.java +++ b/core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/util/MimetypeTest.java @@ -16,7 +16,10 @@ package software.amazon.awssdk.core.internal.util; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.nio.file.Path; import org.junit.BeforeClass; import org.junit.Test; @@ -48,4 +51,11 @@ public void unknownExtensions_defaulttoBeStream() throws Exception { public void noExtensions_defaulttoBeStream() throws Exception { assertThat(mimetype.getMimetype("test")).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM); } + + @Test + public void pathWithoutFileName_defaulttoBeStream() throws Exception { + Path mockPath = mock(Path.class); + when(mockPath.getFileName()).thenReturn(null); + assertThat(mimetype.getMimetype(mockPath)).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM); + } }