diff options
author | Tor Norbye <tnorbye@google.com> | 2013-01-03 14:38:31 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-01-03 14:38:31 -0800 |
commit | 540f9f3a4c98fe30beec57fa6d2730328a3f5226 (patch) | |
tree | 69ea56194c9875b21bae43205165d5a0f7e98ee5 /eclipse/plugins | |
parent | 025883c34883118e6e50700a83f5af0c6fac88d2 (diff) | |
download | sdk-540f9f3a4c98fe30beec57fa6d2730328a3f5226.zip sdk-540f9f3a4c98fe30beec57fa6d2730328a3f5226.tar.gz sdk-540f9f3a4c98fe30beec57fa6d2730328a3f5226.tar.bz2 |
Ensure streams are closed after parsing
Just read in full contents of XML file up front
such that the stream can be closed. Also switch
from InputStream to Reader since that's the native
format KXml wants anyway (inside setInput() it creates
one from the input stream if it doesn't already have
one)
Change-Id: I69e1602702ac771d29f988169cb7adafefc0198c
Diffstat (limited to 'eclipse/plugins')
2 files changed, 12 insertions, 8 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java index b261a5f..74c033c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java @@ -51,14 +51,17 @@ import com.android.ide.eclipse.adt.internal.resources.manager.ProjectClassLoader import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources; import com.android.resources.ResourceType; import com.android.util.Pair; +import com.google.common.base.Charsets; +import com.google.common.io.Files; import org.eclipse.core.resources.IProject; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringReader; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -462,12 +465,15 @@ public final class ProjectCallback extends LegacyCallback { ContextPullParser parser = new ContextPullParser(this, xml); try { parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - parser.setInput(new FileInputStream(xml), "UTF-8"); //$NON-NLS-1$ + String xmlText = Files.toString(xml, Charsets.UTF_8); + parser.setInput(new StringReader(xmlText)); return parser; } catch (XmlPullParserException e) { AdtPlugin.log(e, null); } catch (FileNotFoundException e) { // Shouldn't happen since we check isFile() above + } catch (IOException e) { + AdtPlugin.log(e, null); } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java index 0669f9e..fdc5fed 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java @@ -54,6 +54,7 @@ import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.sdklib.IAndroidTarget; import com.android.sdklib.devices.Device; +import com.google.common.base.Charsets; import com.google.common.io.Files; import org.eclipse.core.resources.IProject; @@ -61,10 +62,9 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; +import java.io.StringReader; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -380,16 +380,14 @@ public class RenderService { File layoutFile = new File(contextLayout.getValue()); if (layoutFile.isFile()) { try { - byte[] bytes = Files.toByteArray(layoutFile); - // Get the name of the layout actually being edited, without the extension // as it's what IXmlPullParser.getParser(String) will receive. String queryLayoutName = mEditor.getLayoutResourceName(); mProjectCallback.setLayoutParser(queryLayoutName, modelParser); topParser = new ContextPullParser(mProjectCallback, layoutFile); topParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - InputStream inputStream = new ByteArrayInputStream(bytes); - topParser.setInput(inputStream, "UTF-8"); //$NON-NLS-1$ + String xmlText = Files.toString(layoutFile, Charsets.UTF_8); + topParser.setInput(new StringReader(xmlText)); } catch (IOException e) { AdtPlugin.log(e, null); } catch (XmlPullParserException e) { |