extract field from auto closable (IDEA-125141)

This commit is contained in:
Anna Kozlova
2014-05-15 18:26:56 +04:00
parent 827e889fb0
commit b1b602553c
4 changed files with 66 additions and 12 deletions
@@ -0,0 +1,22 @@
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
class JavaClass {
static String readFirstLineFromFile() throws IOException {
try (BufferedReader br = createReader("any")) {
return b<caret>r.readLine();
}
}
private static BufferedReader createReader(String path) {
try {
return new BufferedReader(new FileReader(path));
} catch (FileNotFoundException e) {
// for example purposes #createReader shouldn't throw any checked exception
throw new RuntimeException(e);
}
}
}
@@ -0,0 +1,24 @@
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
class JavaClass {
private static BufferedReader br;
static String readFirstLineFromFile() throws IOException {
try (br = createReader("any")) {
return br.readLine();
}
}
private static BufferedReader createReader(String path) {
try {
return new BufferedReader(new FileReader(path));
} catch (FileNotFoundException e) {
// for example purposes #createReader shouldn't throw any checked exception
throw new RuntimeException(e);
}
}
}