-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to move method out of GeometryUtils
- Loading branch information
1 parent
873e607
commit 0f4a084
Showing
2 changed files
with
34 additions
and
25 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
indexer/src/main/java/au/org/aodn/esindexer/utils/FileUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package au.org.aodn.esindexer.utils; | ||
|
||
import org.springframework.core.io.ClassPathResource; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class FileUtils { | ||
public static File saveResourceToTemp(String resourceName, String filename) { | ||
String tempDir = System.getProperty("java.io.tmpdir"); | ||
ClassPathResource resource = new ClassPathResource(resourceName); | ||
|
||
File tempFile = new File(tempDir, filename); | ||
try(InputStream input = resource.getInputStream()) { | ||
tempFile.deleteOnExit(); // Ensure the file is deleted when the JVM exits | ||
|
||
// Write the InputStream to the temporary file | ||
try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { | ||
byte[] buffer = new byte[1024]; | ||
int bytesRead; | ||
while ((bytesRead = input.read(buffer)) != -1) { | ||
outputStream.write(buffer, 0, bytesRead); | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return tempFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters