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

View File

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

View File

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