OSDN Git Service

Fixed 1053 again, FileHandle readBytes allocation.
authorNathanSweet <nathan.sweet@gmail.com>
Tue, 18 Sep 2012 09:14:44 +0000 (02:14 -0700)
committerNathanSweet <nathan.sweet@gmail.com>
Tue, 18 Sep 2012 09:14:44 +0000 (02:14 -0700)
gdx/src/com/badlogic/gdx/files/FileHandle.java

index 71c9652..23b1829 100644 (file)
 \r
 package com.badlogic.gdx.files;\r
 \r
+import com.badlogic.gdx.Files;\r
+import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
+\r
 import java.io.BufferedInputStream;\r
 import java.io.BufferedReader;\r
 import java.io.File;\r
@@ -30,11 +35,6 @@ import java.io.Reader;
 import java.io.UnsupportedEncodingException;\r
 import java.io.Writer;\r
 \r
-import com.badlogic.gdx.Files;\r
-import com.badlogic.gdx.Files.FileType;\r
-import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.utils.GdxRuntimeException;\r
-\r
 /** Represents a file or directory on the filesystem, classpath, Android SD card, or Android assets directory. FileHandles are\r
  * created via a {@link Files} instance.\r
  * @author mzechner\r
@@ -222,11 +222,14 @@ public class FileHandle {
                                int count = input.read(buffer, position, buffer.length - position);\r
                                if (count == -1) break;\r
                                position += count;\r
-                               if (count == 0 && position == buffer.length) {\r
+                               if (position == buffer.length) {\r
+                                       int b = input.read();\r
+                                       if (b == -1) break;\r
                                        // Grow buffer.\r
                                        byte[] newBuffer = new byte[buffer.length * 2];\r
                                        System.arraycopy(buffer, 0, newBuffer, 0, position);\r
                                        buffer = newBuffer;\r
+                                       buffer[position++] = (byte)b;\r
                                }\r
                        }\r
                } catch (IOException ex) {\r