Skip to content

Commit

Permalink
Merge pull request #8835 from GlobalDataverseCommunityConsortium/GDCC…
Browse files Browse the repository at this point in the history
…/7527-fix-redetect

GDCC/7527-fix-redetect
  • Loading branch information
sekmiller committed Sep 19, 2022
2 parents 1c72fbe + 77eea56 commit 454f3f1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import edu.harvard.iq.dataverse.export.ExportException;
import edu.harvard.iq.dataverse.export.ExportService;
import edu.harvard.iq.dataverse.util.EjbUtil;
import edu.harvard.iq.dataverse.util.FileTypeDetection;
import edu.harvard.iq.dataverse.util.FileUtil;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -62,7 +63,7 @@ public DataFile execute(CommandContext ctxt) throws CommandException {
}

logger.fine("target file: " + localFile);
String newlyDetectedContentType = FileTypeDetection.determineFileType(localFile);
String newlyDetectedContentType = FileUtil.determineFileType(localFile, fileToRedetect.getDisplayName());
fileToRedetect.setContentType(newlyDetectedContentType);
} catch (IOException ex) {
throw new CommandException("Exception while attempting to get the bytes of the file during file type redetection: " + ex.getLocalizedMessage(), this);
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/edu/harvard/iq/dataverse/util/FileTypeDetection.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ public static String determineFileType(File f, String fileName) throws IOExcepti
}
}

if(fileType==null) {
fileType = MIME_TYPE_UNDETERMINED_DEFAULT;
}
logger.fine("returning fileType "+fileType);
return fileType;
}
Expand Down

This file was deleted.

12 changes: 12 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/util/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ public void testDetermineFileTypeByExtension() {
fail("File does not exist: " + file.toPath().toString());
}
}

@Test
public void testDetermineFileTypeFromName() {
//Verify that name of the local file isn't used in determining the type (as we often use *.tmp when the real name has a different extension)
try {
File file = File.createTempFile("empty", "png");
assertEquals("text/plain", FileUtil.determineFileType(file, "something.txt"));
} catch (IOException ex) {
Logger.getLogger(FileUtilTest.class.getName()).log(Level.SEVERE, null, ex);
}

}

@Test
public void testDetermineFileTypeByName() {
Expand Down

0 comments on commit 454f3f1

Please sign in to comment.