Using try-with-resources more consistently

This commit is contained in:
Joakim Erdfelt 2013-08-18 08:27:45 -07:00 committed by Greg Wilkins
parent 07636dbe62
commit 4e1a62b5c5
3 changed files with 12 additions and 42 deletions

View File

@ -27,8 +27,6 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.net.URL;
import java.text.CollationKey;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -292,16 +290,6 @@ public class Config
}
}
private void close(InputStream stream)
{
FS.close(stream);
}
private void close(Reader reader)
{
FS.close(reader);
}
public static boolean isDebug()
{
return DEBUG;
@ -548,7 +536,10 @@ public class Config
*/
public void parse(CharSequence buf) throws IOException
{
parse(new StringReader(buf.toString()));
try (StringReader reader = new StringReader(buf.toString()))
{
parse(reader);
}
}
/**
@ -559,28 +550,18 @@ public class Config
*/
public void parse(InputStream stream) throws IOException
{
InputStreamReader reader = null;
try
try (InputStreamReader reader = new InputStreamReader(stream))
{
reader = new InputStreamReader(stream);
parse(reader);
}
finally
{
close(reader);
}
}
/**
*/
public void parse(Reader reader) throws IOException
{
BufferedReader buf = null;
try
try(BufferedReader buf = new BufferedReader(reader))
{
buf = new BufferedReader(reader);
List<String> options = new ArrayList<String>();
options.add(DEFAULT_SECTION);
_classpaths.put(DEFAULT_SECTION,new Classpath());
@ -853,10 +834,6 @@ public class Config
}
}
}
finally
{
close(buf);
}
}
private List<String> processDynamicSectionIdentifier(String dynamicPathId,List<String> sections) throws IOException
@ -933,8 +910,8 @@ public class Config
}
finally
{
close(reader);
close(stream);
FS.close(reader);
FS.close(stream);
}
}

View File

@ -102,7 +102,7 @@ public class JarVersion
}
finally
{
Main.close(stream);
FS.close(stream);
}
}

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.start;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@ -50,7 +49,6 @@ import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import org.eclipse.jetty.start.StartIni.IncludeListener;
@ -525,7 +523,7 @@ public class Main implements IncludeListener
}
finally
{
close(buf);
FS.close(buf);
}
System.exit(EXIT_USAGE);
}
@ -583,11 +581,6 @@ public class Main implements IncludeListener
main.invoke(null,method_params);
}
public static void close(Closeable c)
{
FS.close(c);
}
public void start(List<String> xmls) throws IOException, InterruptedException
{
// Load potential Config (start.config)
@ -1020,7 +1013,7 @@ public class Main implements IncludeListener
}
finally
{
close(cfgstream);
FS.close(cfgstream);
}
}
@ -1068,7 +1061,7 @@ public class Main implements IncludeListener
}
finally
{
close(cfgstream);
FS.close(cfgstream);
}
}