Use Writer, always close FileWriter exactly once

This commit is contained in:
Daniel Martí 2015-09-10 19:24:52 -07:00
parent 6793780d4f
commit 27f212f3ec

View File

@ -345,12 +345,11 @@ public class LocalRepoManager {
serializer = XmlPullParserFactory.newInstance().newSerializer(); serializer = XmlPullParserFactory.newInstance().newSerializer();
} }
public void build(FileWriter output) throws IOException, LocalRepoKeyStore.InitException { public void build(Writer output) throws IOException, LocalRepoKeyStore.InitException {
serializer.setOutput(output); serializer.setOutput(output);
serializer.startDocument(null, null); serializer.startDocument(null, null);
tagFdroid(); tagFdroid();
serializer.endDocument(); serializer.endDocument();
output.close();
} }
private void tagFdroid() throws IOException, LocalRepoKeyStore.InitException { private void tagFdroid() throws IOException, LocalRepoKeyStore.InitException {
@ -486,8 +485,7 @@ public class LocalRepoManager {
public void writeIndexJar() throws IOException { public void writeIndexJar() throws IOException {
FileWriter writer; FileWriter writer = null;
try { try {
writer = new FileWriter(xmlIndex); writer = new FileWriter(xmlIndex);
new IndexXmlBuilder(context, apps).build(writer); new IndexXmlBuilder(context, apps).build(writer);
@ -495,6 +493,8 @@ public class LocalRepoManager {
Log.e(TAG, "Could not write index jar", e); Log.e(TAG, "Could not write index jar", e);
Toast.makeText(context, R.string.failed_to_create_index, Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.failed_to_create_index, Toast.LENGTH_LONG).show();
return; return;
} finally {
Utils.closeQuietly(writer);
} }
BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(xmlIndexJarUnsigned)); BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(xmlIndexJarUnsigned));
@ -515,7 +515,6 @@ public class LocalRepoManager {
bi.close(); bi.close();
jo.close(); jo.close();
bo.close(); bo.close();
writer.close();
try { try {
LocalRepoKeyStore.get(context).signZip(xmlIndexJarUnsigned, xmlIndexJar); LocalRepoKeyStore.get(context).signZip(xmlIndexJarUnsigned, xmlIndexJar);