From 087b0cd8749914201071c7ba24f39ceaa576ab85 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sat, 13 Apr 2013 19:25:05 +0200 Subject: [PATCH] Readers, not streams. --- spine-csharp/src/Atlas.cs | 15 +++++++-------- spine-csharp/src/SkeletonJson.cs | 11 +++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/spine-csharp/src/Atlas.cs b/spine-csharp/src/Atlas.cs index e2b54335b..fe9ba308c 100644 --- a/spine-csharp/src/Atlas.cs +++ b/spine-csharp/src/Atlas.cs @@ -39,20 +39,20 @@ namespace Spine { public Object Texture; public Atlas (String path, Object texture, int textureWidth, int textureHeight) { - using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) { + using (StreamReader reader = new StreamReader(path)) { try { - initialize(input, texture, textureWidth, textureHeight); + initialize(reader, texture, textureWidth, textureHeight); } catch (Exception ex) { throw new Exception("Error reading atlas file: " + path, ex); } } } - public Atlas (Stream input, Object texture, int textureWidth, int textureHeight) { - initialize(input, texture, textureWidth, textureHeight); + public Atlas (TextReader reader, Object texture, int textureWidth, int textureHeight) { + initialize(reader, texture, textureWidth, textureHeight); } - private void initialize (Stream input, Object texture, int textureWidth, int textureHeight) { + private void initialize (TextReader reader, Object texture, int textureWidth, int textureHeight) { TextureWidth = textureWidth; TextureHeight = textureHeight; Texture = texture; @@ -62,7 +62,6 @@ namespace Spine { float invTexHeight = 1f / textureHeight; String[] tuple = new String[4]; - StreamReader reader = new StreamReader(input); // Skip to first page entry. while (true) { String line = reader.ReadLine(); @@ -144,7 +143,7 @@ namespace Spine { } } - static String readValue (StreamReader reader) { + static String readValue (TextReader reader) { String line = reader.ReadLine(); int colon = line.IndexOf(':'); if (colon == -1) @@ -153,7 +152,7 @@ namespace Spine { } /** Returns the number of tuple values read (2 or 4). */ - static int readTuple (StreamReader reader, String[] tuple) { + static int readTuple (TextReader reader, String[] tuple) { String line = reader.ReadLine(); int colon = line.IndexOf(':'); if (colon == -1) diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index dd96c55f1..7e7bb4de5 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -52,20 +52,19 @@ namespace Spine { } public SkeletonData ReadSkeletonData (String path) { - using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) { - SkeletonData skeletonData = ReadSkeletonData(input); + using (StreamReader reader = new StreamReader(path)) { + SkeletonData skeletonData = ReadSkeletonData(reader); skeletonData.Name = Path.GetFileNameWithoutExtension(path); return skeletonData; } } - public SkeletonData ReadSkeletonData (Stream input) { - if (input == null) - throw new ArgumentNullException("json cannot be null."); + public SkeletonData ReadSkeletonData (TextReader reader) { + if (reader == null) throw new ArgumentNullException("reader cannot be null."); SkeletonData skeletonData = new SkeletonData(); - var root = Json.Deserialize(new StreamReader(input)) as Dictionary; + var root = Json.Deserialize(reader) as Dictionary; // Bones. foreach (Dictionary boneMap in (List)root["bones"]) {