Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ public FileMimeTypeValidator(FileService fileService, DescriptorParserFacadeFact
}

public void validateFileType(String spaceGuid, String appArchiveId, Consumer<String> stepLogger) {
try (InputStream fileInputStream = fileService.openInputStream(spaceGuid, appArchiveId);
InputStream inputStreamToValidate = (fileInputStream instanceof DBInputStream)
? fileInputStream
: new BufferedInputStream(fileInputStream)) {
validateInputStreamMimeType(inputStreamToValidate, stepLogger);
try (InputStream fileInputStream = getInputStreamToValidate(fileService.openInputStream(spaceGuid, appArchiveId))) {
validateInputStreamMimeType(fileInputStream, stepLogger);
} catch (FileStorageException | IOException e) {
throw new SLException(e);
}
}

private InputStream getInputStreamToValidate(InputStream stream) {
return (stream instanceof DBInputStream) ? stream : new BufferedInputStream(stream);
}

private void validateInputStreamMimeType(InputStream uploadedFileInputStream, Consumer<String> stepLogger) throws IOException {
String detectedType = getFileMimeType(uploadedFileInputStream);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void rollback(Connection connection) throws SQLException {
}

public static void setAutoCommitSafely(Connection connection) throws SQLException {
if (connection != null) {
if (connection != null && !connection.isClosed()) {
connection.setAutoCommit(true);
}
}
Expand Down
Loading