Skip to content
Permalink
Browse files
CONFIGURATION-805 - Use try with resource (#114)
  • Loading branch information
arturobernalg committed Jun 26, 2021
1 parent 12959f6 commit 6adf321ba1eeacef853501880b0f033ebbd2face
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 40 deletions.
@@ -1325,20 +1325,10 @@ public void testSaveDelimiterParsingDisabled()
@Test
public void testSaveToStream() throws ConfigurationException, IOException
{
FileOutputStream out = null;
final FileHandler handler = new FileHandler(conf);
try
{
out = new FileOutputStream(testSaveConf);
try (FileOutputStream out = new FileOutputStream(testSaveConf)) {
handler.save(out, "UTF8");
}
finally
{
if(out != null)
{
out.close();
}
}

checkSavedConfig(testSaveConf);
}
@@ -148,31 +148,12 @@ private static String readReader(final Reader in) throws IOException
*/
private static String readFile(final File f)
{
Reader in = null;
try
{
in = new FileReader(f);
try (Reader in = new FileReader(f)) {
return readReader(in);
}
catch (final IOException ioex)
{
} catch (final IOException ioex) {
fail("Could not read file: " + ioex);
return null; // cannot happen
}
finally
{
if (in != null)
{
try
{
in.close();
}
catch (final IOException ioex)
{
// ignore
}
}
}
}

/**
@@ -726,16 +707,10 @@ public void testSaveToWriterNoContent() throws ConfigurationException
public void testSaveToStream() throws ConfigurationException, IOException
{
final File file = folder.newFile();
final FileOutputStream out = new FileOutputStream(file);
final FileHandler handler = new FileHandler(new FileBasedTestImpl());
try
{
try (FileOutputStream out = new FileOutputStream(file)) {
final FileHandler handler = new FileHandler(new FileBasedTestImpl());
handler.save(out);
}
finally
{
out.close();
}
assertEquals("Wrong content", CONTENT, readFile(file));
}

0 comments on commit 6adf321

Please sign in to comment.