Use try-with-resources to close reader / writer
This commit is contained in:
parent
de09122ba4
commit
402a89eb03
|
@ -32,8 +32,7 @@ public class SingleLineSqlScriptExtractor implements SqlScriptCommandExtractor {
|
|||
public List<String> extractCommands(Reader reader, Dialect dialect) {
|
||||
final List<String> statementList = new LinkedList<>();
|
||||
|
||||
final BufferedReader bufferedReader = new BufferedReader( reader );
|
||||
try {
|
||||
try (final BufferedReader bufferedReader = new BufferedReader( reader )) {
|
||||
for ( String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine() ) {
|
||||
final String trimmedLine = line.trim();
|
||||
|
||||
|
|
|
@ -51,23 +51,20 @@ public class AntlrHelper {
|
|||
tmpFile.getParentFile().mkdirs();
|
||||
tmpFile.createNewFile();
|
||||
|
||||
final BufferedReader reader = new BufferedReader( new FileReader( generatedJavaFile ) );
|
||||
final BufferedWriter writer = new BufferedWriter( new FileWriter( tmpFile ) );
|
||||
try (final BufferedReader reader = new BufferedReader( new FileReader( generatedJavaFile ) );
|
||||
final BufferedWriter writer = new BufferedWriter( new FileWriter( tmpFile ) )) {
|
||||
|
||||
boolean found = false;
|
||||
String currentLine;
|
||||
boolean found = false;
|
||||
String currentLine;
|
||||
|
||||
while ( ( currentLine = reader.readLine() ) != null ) {
|
||||
if ( ! found && currentLine.startsWith( "// Generated from" ) ) {
|
||||
found = true;
|
||||
continue;
|
||||
while ((currentLine = reader.readLine()) != null) {
|
||||
if (!found && currentLine.startsWith("// Generated from")) {
|
||||
found = true;
|
||||
continue;
|
||||
}
|
||||
writer.write(currentLine + System.lineSeparator());
|
||||
}
|
||||
writer.write( currentLine + System.lineSeparator() );
|
||||
}
|
||||
|
||||
writer.close();
|
||||
reader.close();
|
||||
|
||||
generatedJavaFile.delete();
|
||||
tmpFile.renameTo( generatedJavaFile );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue