Explorar o código

Readers, not streams.

NathanSweet %!s(int64=12) %!d(string=hai) anos
pai
achega
087b0cd874
Modificáronse 2 ficheiros con 12 adicións e 14 borrados
  1. 7 8
      spine-csharp/src/Atlas.cs
  2. 5 6
      spine-csharp/src/SkeletonJson.cs

+ 7 - 8
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)

+ 5 - 6
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<String, Object>;
+			var root = Json.Deserialize(reader) as Dictionary<String, Object>;
 
 			// Bones.
 			foreach (Dictionary<String, Object> boneMap in (List<Object>)root["bones"]) {