Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/ioStreamConstructor/afterOutputStreamFromTernary.java
Artemiy Sartakov 67e36d74a5 IOStreamConstructorInspection: added inspection (IDEA-171230)
Inspection suggests conversions:
1. FileInputStream -> Files.newInputStream
2. FileOutputStream -> Files.newOutputStream
in cases when FileInputStream can be replaced with InputStream.
Also, it reuses path variable after conversion when possible (path variable should be effectively final).

GitOrigin-RevId: 474dcaeeb5336fcc8330b4b3ed65d443042ecf2f
2022-01-25 07:01:39 +00:00

11 lines
324 B
Java

// "Replace with 'Files.newOutputStream'" "true"
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
class Foo {
void test(String str, boolean b) {
try (OutputStream os = (b ? (Files.newOutputStream(Path.of("foo"))) : (Files.newOutputStream(Path.of(str))))) {
} catch (IOException e) {}
}
}