Migrate to java.nio.file.createTempFile (#15469)

Use function from nio package as it uses more restrictive file
permissions.

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
pull/15568/head
Holger Friedrich 2023-09-09 11:10:32 +02:00 committed by GitHub
parent 5e7cbea21f
commit 14c3c0cd63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -143,7 +143,7 @@ class PullJob implements Runnable {
File tmpTargetFile; File tmpTargetFile;
try { try {
tmpTargetFile = File.createTempFile(TMP_FILE_PREFIX, null); tmpTargetFile = Files.createTempFile(TMP_FILE_PREFIX, null).toFile();
} catch (IOException e) { } catch (IOException e) {
logger.warn("Not able to create temporary file for downloading iCal. Error message is: {}", e.getMessage()); logger.warn("Not able to create temporary file for downloading iCal. Error message is: {}", e.getMessage());
return; return;

View File

@ -17,6 +17,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import org.openhab.core.audio.AudioException; import org.openhab.core.audio.AudioException;
import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioFormat;
@ -130,7 +131,7 @@ class MacTTSAudioStream extends FixedLengthAudioStream implements Disposable {
private String generateOutputFilename() throws AudioException { private String generateOutputFilename() throws AudioException {
File tempFile; File tempFile;
try { try {
tempFile = File.createTempFile(Integer.toString(text.hashCode()), ".wav"); tempFile = Files.createTempFile(Integer.toString(text.hashCode()), ".wav").toFile();
tempFile.deleteOnExit(); tempFile.deleteOnExit();
} catch (IOException e) { } catch (IOException e) {
throw new AudioException("Unable to create temp file.", e); throw new AudioException("Unable to create temp file.", e);

View File

@ -17,6 +17,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -92,7 +93,7 @@ class PicoTTSAudioStream extends FixedLengthAudioStream implements Disposable {
*/ */
private String generateOutputFilename() throws AudioException { private String generateOutputFilename() throws AudioException {
try { try {
File tempFile = File.createTempFile(Integer.toString(text.hashCode()), ".wav"); File tempFile = Files.createTempFile(Integer.toString(text.hashCode()), ".wav").toFile();
tempFile.deleteOnExit(); tempFile.deleteOnExit();
return tempFile.getAbsolutePath(); return tempFile.getAbsolutePath();
} catch (IOException e) { } catch (IOException e) {