Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed copyFile method as it is not being used anywhere; used try-wi… #9509

Merged
merged 1 commit into from Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 5 additions & 36 deletions src/main/java/edu/harvard/iq/dataverse/util/FileUtil.java
Expand Up @@ -246,26 +246,6 @@ public class FileUtil implements java.io.Serializable {
public FileUtil() {
}

public static void copyFile(File inputFile, File outputFile) throws IOException {
FileChannel in = null;
WritableByteChannel out = null;

try {
in = new FileInputStream(inputFile).getChannel();
out = new FileOutputStream(outputFile).getChannel();
long bytesPerIteration = 50000;
long start = 0;
while ( start < in.size() ) {
in.transferTo(start, bytesPerIteration, out);
start += bytesPerIteration;
}

} finally {
if (in != null) { in.close(); }
if (out != null) { out.close(); }
}
}


public static String getFileExtension(String fileName){
String ext = null;
Expand Down Expand Up @@ -602,12 +582,11 @@ public static String lookupFileTypeFromPropertiesFile(String fileName) {
* -- L.A. 4.0 alpha
*/
private static boolean isFITSFile(File file) {
BufferedInputStream ins = null;

try {
ins = new BufferedInputStream(new FileInputStream(file));
try (BufferedInputStream ins = new BufferedInputStream(new FileInputStream(file))) {
return isFITSFile(ins);
} catch (IOException ex) {
logger.fine("IOException: "+ ex.getMessage());
}

return false;
Expand Down Expand Up @@ -648,8 +627,7 @@ private static boolean isFITSFile(InputStream ins) {
private static boolean isGraphMLFile(File file) {
boolean isGraphML = false;
logger.fine("begin isGraphMLFile()");
try{
FileReader fileReader = new FileReader(file);
try(FileReader fileReader = new FileReader(file)){
javax.xml.stream.XMLInputFactory xmlif = javax.xml.stream.XMLInputFactory.newInstance();
xmlif.setProperty("javax.xml.stream.isCoalescing", java.lang.Boolean.TRUE);

Expand Down Expand Up @@ -889,7 +867,6 @@ public static CreateDataFileResult createDataFiles(DatasetVersion version, Input
// a regular FITS file:
if (finalType.equals("application/fits-gzipped")) {

InputStream uncompressedIn = null;
String finalFileName = fileName;
// if the file name had the ".gz" extension, remove it,
// since we are going to uncompress it:
Expand All @@ -898,20 +875,12 @@ public static CreateDataFileResult createDataFiles(DatasetVersion version, Input
}

DataFile datafile = null;
try {
uncompressedIn = new GZIPInputStream(new FileInputStream(tempFile.toFile()));
try (InputStream uncompressedIn = new GZIPInputStream(new FileInputStream(tempFile.toFile()))){
File unZippedTempFile = saveInputStreamInTempFile(uncompressedIn, fileSizeLimit);
datafile = createSingleDataFile(version, unZippedTempFile, finalFileName, MIME_TYPE_UNDETERMINED_DEFAULT, systemConfig.getFileFixityChecksumAlgorithm());
} catch (IOException | FileExceedsMaxSizeException ioex) {
datafile = null;
} finally {
if (uncompressedIn != null) {
try {
uncompressedIn.close();
} catch (IOException e) {
}
}
}
}

// If we were able to produce an uncompressed file, we'll use it
// to create and return a final DataFile; if not, we're not going
Expand Down