From 1fa1f5427272bd60ce5db201b1a1673067e72a38 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sat, 27 Mar 2021 18:34:00 +0100 Subject: [PATCH] [picotts] Add null annotations (#10392) Signed-off-by: Wouter Born --- .../voice/picotts/internal/PicoTTSAudioStream.java | 12 +++++++----- .../voice/picotts/internal/PicoTTSService.java | 9 ++++++--- .../openhab/voice/picotts/internal/PicoTTSVoice.java | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSAudioStream.java b/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSAudioStream.java index 681e033362d09..73986df1b3d96 100644 --- a/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSAudioStream.java +++ b/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSAudioStream.java @@ -18,6 +18,8 @@ import java.io.IOException; import java.io.InputStream; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.audio.AudioException; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; @@ -29,6 +31,7 @@ * * @author Florian Schmidt - Initial Contribution */ +@NonNullByDefault class PicoTTSAudioStream extends FixedLengthAudioStream { private final Voice voice; private final String text; @@ -36,7 +39,7 @@ class PicoTTSAudioStream extends FixedLengthAudioStream { private final InputStream inputStream; private long length; - private File file; + private @Nullable File file; public PicoTTSAudioStream(String text, Voice voice, AudioFormat audioFormat) throws AudioException { this.text = text; @@ -57,7 +60,8 @@ private InputStream createInputStream() throws AudioException { try { Process process = Runtime.getRuntime().exec(command); process.waitFor(); - file = new File(outputFile); + File file = new File(outputFile); + this.file = file; this.length = file.length(); return getFileInputStream(file); } catch (IOException e) { @@ -68,9 +72,6 @@ private InputStream createInputStream() throws AudioException { } private InputStream getFileInputStream(File file) throws AudioException { - if (file == null) { - throw new IllegalArgumentException("file must not be null"); - } if (file.exists()) { try { return new FileInputStream(file); @@ -119,6 +120,7 @@ public long length() { @Override public InputStream getClonedStream() throws AudioException { + File file = this.file; if (file != null) { return getFileInputStream(file); } else { diff --git a/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSService.java b/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSService.java index f0081be4378e2..10a62b25d4c9e 100644 --- a/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSService.java +++ b/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSService.java @@ -18,6 +18,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.audio.AudioException; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; @@ -30,6 +32,7 @@ * @author Florian Schmidt - Initial Contribution */ @Component +@NonNullByDefault public class PicoTTSService implements TTSService { private final Set voices = Stream .of(new PicoTTSVoice("de-DE"), new PicoTTSVoice("en-US"), new PicoTTSVoice("en-GB"), @@ -51,8 +54,8 @@ public Set getSupportedFormats() { @Override public AudioStream synthesize(String text, Voice voice, AudioFormat requestedFormat) throws TTSException { - if (text == null || text.isEmpty()) { - throw new TTSException("The passed text can not be null or empty"); + if (text.isEmpty()) { + throw new TTSException("The passed text can not be empty"); } if (!this.voices.contains(voice)) { @@ -80,7 +83,7 @@ public String getId() { } @Override - public String getLabel(Locale locale) { + public String getLabel(@Nullable Locale locale) { return "PicoTTS"; } } diff --git a/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSVoice.java b/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSVoice.java index afe9bfeef9183..fd6e9fe24f10b 100644 --- a/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSVoice.java +++ b/bundles/org.openhab.voice.picotts/src/main/java/org/openhab/voice/picotts/internal/PicoTTSVoice.java @@ -14,6 +14,7 @@ import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.voice.Voice; /** @@ -21,6 +22,7 @@ * * @author Florian Schmidt - Initial Contribution */ +@NonNullByDefault public class PicoTTSVoice implements Voice { private final String languageTag;