OSDN Git Service

[added] FileHandle.FileType.Classpath so that Internal is not overloaded.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 17 Nov 2010 11:05:29 +0000 (11:05 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 17 Nov 2010 11:05:29 +0000 (11:05 +0000)
[fixed] A bunch of file related bugs.

backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFileHandle.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFiles.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFileHandle.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFiles.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFileHandle.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFiles.java
gdx/src/com/badlogic/gdx/Files.java
gdx/src/com/badlogic/gdx/files/FileHandle.java
gdx/src/com/badlogic/gdx/files/FileHandleStream.java
gdx/src/com/badlogic/gdx/graphics/BitmapFont.java

index 7b7de99..70aa349 100644 (file)
@@ -23,6 +23,7 @@ import java.io.OutputStream;
 \r
 import android.content.res.AssetManager;\r
 \r
+import com.badlogic.gdx.Gdx;\r
 import com.badlogic.gdx.Files.FileType;\r
 import com.badlogic.gdx.files.FileHandle;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
@@ -32,12 +33,56 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * @author Nathan Sweet <misc@n4te.com>\r
  */\r
 public class AndroidFileHandle extends FileHandle {\r
-       // The asset manager, or null if this is an external file.\r
+       // The asset manager, or null if this is not an internal file.\r
        final AssetManager assets;\r
 \r
+       AndroidFileHandle (AssetManager assets, String fileName, FileType type) {\r
+               this.assets = assets;\r
+               this.type = type;\r
+\r
+               switch (type) {\r
+               case Classpath:\r
+                       if (FileHandle.class.getResourceAsStream("/" + fileName) == null)\r
+                               throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
+                       file = new File("/" + fileName);\r
+                       break;\r
+               case Internal:\r
+                       try {\r
+                               assets.open(fileName).close();\r
+                       } catch (Exception ex) {\r
+                               throw new GdxRuntimeException("File not found: " + file + " (" + type + ")", ex);\r
+                       }\r
+                       file = new File(fileName);\r
+                       break;\r
+               case External:\r
+                       file = new File(Gdx.files.getExternalStoragePath() + fileName);\r
+                       break;\r
+               case Absolute:\r
+                       file = new File(fileName);\r
+                       break;\r
+               default:\r
+                       throw new IllegalArgumentException("Unknown type: " + type);\r
+               }\r
+       }\r
+\r
        AndroidFileHandle (AssetManager manager, File file, FileType type) {\r
-               super(file, type);\r
                this.assets = manager;\r
+               this.file = file;\r
+               this.type = type;\r
+\r
+               switch (type) {\r
+               case Classpath:\r
+                       if (FileHandle.class.getResourceAsStream(file.getPath().replace('\\', '/')) == null)\r
+                               throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
+                       break;\r
+               case Internal:\r
+                       try {\r
+                               assets.open(file.getPath()).close();\r
+                       } catch (Exception ex) {\r
+                               throw new GdxRuntimeException("File not found: " + file + " (" + type + ")", ex);\r
+                       }\r
+                       break;\r
+               }\r
        }\r
 \r
        public FileHandle child (String name) {\r
@@ -47,7 +92,7 @@ public class AndroidFileHandle extends FileHandle {
        public FileHandle parent () {\r
                File parent = file.getParentFile();\r
                if (parent == null) {\r
-                       if (type == FileType.Absolute)\r
+                       if (type == FileType.Classpath || type == FileType.Absolute)\r
                                parent = new File("/");\r
                        else\r
                                parent = new File(".");\r
@@ -57,8 +102,6 @@ public class AndroidFileHandle extends FileHandle {
 \r
        public InputStream read () {\r
                if (type == FileType.Internal) {\r
-                       InputStream input = FileHandle.class.getResourceAsStream("/" + file.getPath());\r
-                       if (input != null) return input;\r
                        try {\r
                                return assets.open(file.getPath());\r
                        } catch (IOException ex) {\r
@@ -75,6 +118,7 @@ public class AndroidFileHandle extends FileHandle {
                                FileHandle[] handles = new FileHandle[relativePaths.length];\r
                                for (int i = 0, n = handles.length; i < n; i++)\r
                                        handles[i] = new AndroidFileHandle(assets, new File(file, relativePaths[i]), type);\r
+                               return handles;\r
                        } catch (Exception ex) {\r
                                throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex);\r
                        }\r
@@ -93,17 +137,4 @@ public class AndroidFileHandle extends FileHandle {
                }\r
                return super.isDirectory();\r
        }\r
-\r
-       public boolean exists () {\r
-               if (type == FileType.Internal) {\r
-                       try {\r
-                               InputStream in = assets.open(file.getPath());\r
-                               in.close();\r
-                               return true;\r
-                       } catch (Exception ex) {\r
-                               return false;\r
-                       }\r
-               }\r
-               return super.exists();\r
-       }\r
 }\r
index 6f3c3cb..36f118b 100644 (file)
 \r
 package com.badlogic.gdx.backends.android;\r
 \r
-import java.io.File;\r
-import java.io.InputStream;\r
-\r
 import android.content.res.AssetManager;\r
 import android.os.Environment;\r
 \r
 import com.badlogic.gdx.Files;\r
 import com.badlogic.gdx.files.FileHandle;\r
-import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
- * An implementation of the {@link Files} interface for Android. External files are stored and accessed relative to\r
- * Environment.getExternalStorageDirectory().getAbsolutePath(). Internal files are accessed relative to the assets directory.\r
- * \r
  * @author mzechner\r
- * \r
+ * @author Nathan Sweet <misc@n4te.com>\r
  */\r
 public class AndroidFiles implements Files {\r
        protected final String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";\r
@@ -38,36 +31,24 @@ public class AndroidFiles implements Files {
                this.assets = assets;\r
        }\r
 \r
-       @Override public FileHandle getFileHandle (String fileName, FileType type) {\r
-               File file;\r
-               if (type == FileType.Internal) {\r
-                       file = new File(fileName);\r
-                       if (FileHandle.class.getResourceAsStream("/" + fileName) == null) {\r
-                               try {\r
-                                       InputStream in = assets.open(fileName);\r
-                                       in.close();\r
-                               } catch (Exception ignored) {\r
-                               }\r
-                       }\r
-               } else {\r
-                       if (type == FileType.External)\r
-                               file = new File(sdcard + fileName);\r
-                       else\r
-                               file = new File(fileName);\r
-               }\r
-               return new AndroidFileHandle(assets, file, type);\r
+       @Override public FileHandle getFileHandle (String path, FileType type) {\r
+               return new AndroidFileHandle(type == FileType.Internal ? assets : null, path, type);\r
+       }\r
+\r
+       @Override public FileHandle classpath (String path) {\r
+               return new AndroidFileHandle(null, path, FileType.Classpath);\r
        }\r
 \r
        @Override public FileHandle internal (String path) {\r
-               return getFileHandle(path, FileType.Internal);\r
+               return new AndroidFileHandle(assets, path, FileType.Internal);\r
        }\r
 \r
        @Override public FileHandle external (String path) {\r
-               return getFileHandle(path, FileType.External);\r
+               return new AndroidFileHandle(null, path, FileType.External);\r
        }\r
 \r
        @Override public FileHandle absolute (String path) {\r
-               return getFileHandle(path, FileType.Absolute);\r
+               return new AndroidFileHandle(null, path, FileType.Absolute);\r
        }\r
 \r
        @Override public String getExternalStoragePath () {\r
index 2b7502b..bd3f85f 100644 (file)
@@ -19,12 +19,14 @@ import com.badlogic.gdx.Files.FileType;
 import com.badlogic.gdx.files.FileHandle;\r
 \r
 /**\r
- * A {@link FileHandle} implementation for the desktop.\r
- * \r
  * @author mzechner\r
- * \r
+ * @author Nathan Sweet <misc@n4te.com>\r
  */\r
 public class JoglFileHandle extends FileHandle {\r
+       JoglFileHandle (String fileName, FileType type) {\r
+               super(fileName, type);\r
+       }\r
+\r
        JoglFileHandle (File file, FileType type) {\r
                super(file, type);\r
        }\r
@@ -36,7 +38,7 @@ public class JoglFileHandle extends FileHandle {
        public FileHandle parent () {\r
                File parent = file.getParentFile();\r
                if (parent == null) {\r
-                       if (type == FileType.Absolute)\r
+                       if (type == FileType.Classpath || type == FileType.Absolute)\r
                                parent = new File("/");\r
                        else\r
                                parent = new File(".");\r
index d55e144..e2a20df 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************\r
  * Copyright 2010 Mario Zechner (contact@badlogicgames.com)\r
- *\r
+ * \r
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
  * License. You may obtain a copy of the License at\r
- *\r
+ * \r
  * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * \r
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
  * governing permissions and limitations under the License.\r
 \r
 package com.badlogic.gdx.backends.jogl;\r
 \r
-import java.io.File;\r
-\r
 import com.badlogic.gdx.Files;\r
 import com.badlogic.gdx.files.FileHandle;\r
-import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
- * Implementation for a desktop application of {@link Files}. Internal resources are relative to the application root directory,\r
- * external files are relative to the user's home directory.\r
- *\r
  * @author mzechner\r
- *\r
+ * @author Nathan Sweet <misc@n4te.com>\r
  */\r
 final class JoglFiles implements Files {\r
        private final String externalPath = System.getProperty("user.home") + "/";\r
 \r
        @Override public FileHandle getFileHandle (String fileName, FileType type) {\r
-               File file;\r
-               if (type == FileType.External)\r
-                       file = new File(this.externalPath + fileName);\r
-               else if (type == FileType.Internal) {\r
-                       file = new File(fileName);\r
-                       if (FileHandle.class.getResourceAsStream("/" + fileName) == null && !file.exists())\r
-                               throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
-               }\r
-               return new JoglFileHandle(new File(fileName), type);\r
+               return new JoglFileHandle(fileName, type);\r
+       }\r
+\r
+       @Override public FileHandle classpath (String path) {\r
+               return new JoglFileHandle(path, FileType.Classpath);\r
        }\r
 \r
        @Override public FileHandle internal (String path) {\r
-               return getFileHandle(path, FileType.Internal);\r
+               return new JoglFileHandle(path, FileType.Internal);\r
        }\r
 \r
        @Override public FileHandle external (String path) {\r
-               return getFileHandle(path, FileType.External);\r
+               return new JoglFileHandle(path, FileType.External);\r
        }\r
 \r
        @Override public FileHandle absolute (String path) {\r
-               return getFileHandle(path, FileType.Absolute);\r
+               return new JoglFileHandle(path, FileType.Absolute);\r
        }\r
 \r
        @Override public String getExternalStoragePath () {\r
index 564d1df..ce5a4b8 100644 (file)
 package com.badlogic.gdx.backends.lwjgl;\r
 \r
 import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.InputStream;\r
-import java.io.OutputStream;\r
 \r
 import com.badlogic.gdx.Files.FileType;\r
 import com.badlogic.gdx.files.FileHandle;\r
-import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * @author mzechner\r
  * @author Nathan Sweet <misc@n4te.com>\r
  */\r
 final class LwjglFileHandle extends FileHandle {\r
+       LwjglFileHandle (String fileName, FileType type) {\r
+               super(fileName, type);\r
+       }\r
+\r
        LwjglFileHandle (File file, FileType type) {\r
                super(file, type);\r
        }\r
@@ -40,7 +38,7 @@ final class LwjglFileHandle extends FileHandle {
        public FileHandle parent () {\r
                File parent = file.getParentFile();\r
                if (parent == null) {\r
-                       if (type == FileType.Absolute)\r
+                       if (type == FileType.Classpath || type == FileType.Absolute)\r
                                parent = new File("/");\r
                        else\r
                                parent = new File(".");\r
index deca2aa..0b169f0 100644 (file)
 \r
 package com.badlogic.gdx.backends.lwjgl;\r
 \r
-import java.io.File;\r
-\r
 import com.badlogic.gdx.Files;\r
 import com.badlogic.gdx.files.FileHandle;\r
-import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * @author mzechner\r
@@ -27,27 +24,23 @@ final class LwjglFiles implements Files {
        private final String externalPath = System.getProperty("user.home") + "/";\r
 \r
        @Override public FileHandle getFileHandle (String fileName, FileType type) {\r
-               File file;\r
-               if (type == FileType.External)\r
-                       file = new File(this.externalPath + fileName);\r
-               else if (type == FileType.Internal) {\r
-                       file = new File(fileName);\r
-                       if (FileHandle.class.getResourceAsStream("/" + fileName) == null && !file.exists())\r
-                               throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
-               }\r
-               return new LwjglFileHandle(new File(fileName), type);\r
+               return new LwjglFileHandle(fileName, type);\r
+       }\r
+\r
+       @Override public FileHandle classpath (String path) {\r
+               return new LwjglFileHandle(path, FileType.Classpath);\r
        }\r
 \r
        @Override public FileHandle internal (String path) {\r
-               return getFileHandle(path, FileType.Internal);\r
+               return new LwjglFileHandle(path, FileType.Internal);\r
        }\r
 \r
        @Override public FileHandle external (String path) {\r
-               return getFileHandle(path, FileType.External);\r
+               return new LwjglFileHandle(path, FileType.External);\r
        }\r
 \r
        @Override public FileHandle absolute (String path) {\r
-               return getFileHandle(path, FileType.Absolute);\r
+               return new LwjglFileHandle(path, FileType.Absolute);\r
        }\r
 \r
        @Override public String getExternalStoragePath () {\r
index 5ffc46c..1349d35 100644 (file)
@@ -25,11 +25,19 @@ public interface Files {
        /**\r
         * Indicates how to resolve a path to a file.\r
         * @author mzechner\r
+        * @author Nathan Sweet <misc@n4te.com>\r
         */\r
        public enum FileType {\r
                /**\r
-                * Path relative to the root of the classpath, and if not found there, to the asset directory on Android or the\r
-                * application's root directory on the desktop. Internal files are always readonly.\r
+                * Path relative to the root of the classpath. Classpath files are always readonly. Note that classpath files are not\r
+                * compatible with some functionality on Android, such as {@link Audio#newSound(FileHandle)} and\r
+                * {@link Audio#newMusic(FileHandle)}.\r
+                */\r
+               Classpath,\r
+\r
+               /**\r
+                * Path relative to the asset directory on Android and to the application's root directory on the desktop. Internal files\r
+                * are always readonly.\r
                 */\r
                Internal,\r
 \r
@@ -40,20 +48,25 @@ public interface Files {
 \r
                /**\r
                 * Path that is a fully qualified, absolute filesystem path. To ensure portability across platforms use absolute files only\r
-                * when absolutely necessary.\r
+                * when absolutely (heh) necessary.\r
                 */\r
-               Absolute\r
+               Absolute;\r
        }\r
 \r
        /**\r
         * Returns a handle representing a file or directory.\r
         * @param type Determines how the path is resolved.\r
-        * @throws GdxRuntimeException if the type is internal and the file does not exist.\r
+        * @throws GdxRuntimeException if the type is classpath or internal and the file does not exist.\r
         * @see FileType\r
         */\r
        public FileHandle getFileHandle (String path, FileType type);\r
 \r
        /**\r
+        * Convenience method that returns a {@link FileType#Classpath} file handle.\r
+        */\r
+       public FileHandle classpath (String path);\r
+\r
+       /**\r
         * Convenience method that returns an {@link FileType#Internal} file handle.\r
         */\r
        public FileHandle internal (String path);\r
@@ -69,13 +82,14 @@ public interface Files {
        public FileHandle absolute (String path);\r
 \r
        /**\r
-        * @return the external storage path directory. This is the SD card on Android or the home directory of the current user on the\r
-        * desktop.\r
+        * Returns the external storage path directory. This is the SD card on Android and the home directory of the current user on\r
+        * the desktop.\r
         */\r
        public String getExternalStoragePath ();\r
 \r
        /**\r
-        * @return true if the external storage is ready for file i/o.\r
+        * Returns true if the external storage is ready for file IO. Eg, on Android, the SD card is not available when mounted for use\r
+        * with a PC.\r
         */\r
        public boolean isExternalStorageAvailable ();\r
 }\r
index c069dd5..46beb0e 100644 (file)
@@ -22,6 +22,7 @@ import java.io.OutputStream;
 \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
 /**\r
@@ -31,12 +32,49 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * @author Nathan Sweet <misc@n4te.com>\r
  */\r
 public abstract class FileHandle {\r
-       protected final File file;\r
-       protected final FileType type;\r
+       protected File file;\r
+       protected FileType type;\r
+\r
+       protected FileHandle () {\r
+       }\r
+\r
+       protected FileHandle (String fileName, FileType type) {\r
+               this.type = type;\r
+\r
+               switch (type) {\r
+               case Classpath:\r
+                       if (FileHandle.class.getResourceAsStream("/" + fileName) == null)\r
+                               throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
+                       file = new File("/" + fileName);\r
+                       break;\r
+               case Internal:\r
+                       file = new File(fileName);\r
+                       if (!file.exists()) throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
+                       break;\r
+               case External:\r
+                       file = new File(Gdx.files.getExternalStoragePath() + fileName);\r
+                       break;\r
+               case Absolute:\r
+                       file = new File(fileName);\r
+                       break;\r
+               default:\r
+                       throw new IllegalArgumentException("Unknown type: " + type);\r
+               }\r
+       }\r
 \r
        protected FileHandle (File file, FileType type) {\r
                this.file = file;\r
                this.type = type;\r
+\r
+               switch (type) {\r
+               case Classpath:\r
+                       if (FileHandle.class.getResourceAsStream(file.getPath().replace('\\', '/')) == null)\r
+                               throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
+                       break;\r
+               case Internal:\r
+                       if (!file.exists()) throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
+                       break;\r
+               }\r
        }\r
 \r
        public String path () {\r
@@ -67,13 +105,17 @@ public abstract class FileHandle {
 \r
        /**\r
         * Returns a stream for reading this file.\r
-        * @throw GdxRuntimeException if this file handle represents a directory or if it could not be read.\r
+        * @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or\r
+        *        {@link FileType#Internal} and the file doesn't exist, or if it could not be read.\r
         */\r
        public InputStream read () {\r
-               if (type == FileType.Internal) {\r
-                       InputStream input = FileHandle.class.getResourceAsStream("/" + file.getPath());\r
-                       if (input != null) return input;\r
+               if (type == FileType.Classpath) {\r
+                       InputStream input = FileHandle.class.getResourceAsStream(file.getPath().replace('\\', '/'));\r
+                       if (input == null) throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
+                       return input;\r
                }\r
+               if (type == FileType.Internal && !file.exists())\r
+                       throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
                try {\r
                        return new FileInputStream(file);\r
                } catch (FileNotFoundException ex) {\r
@@ -83,11 +125,12 @@ public abstract class FileHandle {
 \r
        /**\r
         * Returns a stream for writing to this file.\r
-        * @param append If false, this file will be overwritten if it exists, otherwise it is appended.\r
-        * @throw GdxRuntimeException if this file handle represents a directory, if it is an {@link FileType#Internal} file, or if it\r
-        *        could not be written.\r
+        * @param append If false, this file will be overwritten if it exists, otherwise it will be appended.\r
+        * @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or\r
+        *        {@link FileType#Internal} file, or if it could not be written.\r
         */\r
        public OutputStream write (boolean append) {\r
+               if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot write to a classpath file: " + file);\r
                if (type == FileType.Internal) throw new GdxRuntimeException("Cannot write to an internal file: " + file);\r
                try {\r
                        return new FileOutputStream(file, append);\r
@@ -99,9 +142,10 @@ public abstract class FileHandle {
        /**\r
         * Returns the paths to the children of this directory. Returns an empty list if this file handle represents a file and not a\r
         * directory.\r
-        * @throw GdxRuntimeException if this file is an {@link FileType#Internal} file.\r
+        * @throw GdxRuntimeException if this file is an {@link FileType#Classpath} file.\r
         */\r
        public FileHandle[] list () {\r
+               if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot list a classpath directory: " + file);\r
                String[] relativePaths = file.list();\r
                if (relativePaths == null) return new FileHandle[0];\r
                FileHandle[] handles = new FileHandle[relativePaths.length];\r
@@ -110,49 +154,62 @@ public abstract class FileHandle {
                return handles;\r
        }\r
 \r
+       /**\r
+        * Returns true if this file is a directory. Always returns false for classpath files.\r
+        */\r
        public boolean isDirectory () {\r
-               if (type == FileType.Internal) return false; // BOZO - This works on Android, where internal is assets dir.\r
+               if (type == FileType.Classpath) return false;\r
                return file.isDirectory();\r
 \r
        }\r
 \r
+       /**\r
+        * Returns a handle to the child with the specified name.\r
+        * @throw GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} and the child\r
+        *        doesn't exist.\r
+        */\r
        abstract public FileHandle child (String name);\r
 \r
        abstract public FileHandle parent ();\r
 \r
        /**\r
-        * @throw GdxRuntimeException if this file handle is an {@link FileType#Internal} file.\r
+        * @throw GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file.\r
         */\r
        public void mkdirs () {\r
+               if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot mkdirs with a classpath file: " + file);\r
                if (type == FileType.Internal) throw new GdxRuntimeException("Cannot mkdirs with an internal file: " + file);\r
                file.mkdirs();\r
        }\r
 \r
        public boolean exists () {\r
+               // Classpath and internal FileHandles can't be created unless they exist.\r
+               if (type == FileType.Classpath || type == FileType.Internal) return true;\r
                return file.exists();\r
        }\r
 \r
        /**\r
         * Deletes this file or empty directory and returns success. Will not delete a directory that has children.\r
-        * @throw GdxRuntimeException if this file handle is an {@link FileType#Internal} file.\r
+        * @throw GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file.\r
         */\r
        public boolean delete () {\r
+               if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot delete a classpath file: " + file);\r
                if (type == FileType.Internal) throw new GdxRuntimeException("Cannot delete an internal file: " + file);\r
                return file.delete();\r
        }\r
 \r
        /**\r
         * Deletes this file or directory and all children, recursively.\r
-        * @throw GdxRuntimeException if this file handle is an {@link FileType#Internal} file.\r
+        * @throw GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file.\r
         */\r
        public boolean deleteDirectory () {\r
+               if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot delete a classpath file: " + file);\r
                if (type == FileType.Internal) throw new GdxRuntimeException("Cannot delete an internal file: " + file);\r
                return deleteDirectory(file);\r
        }\r
 \r
        /**\r
         * Copies this file to the specified file, overwriting the file if it already exists.\r
-        * @throw GdxRuntimeException if the destination file handle is an {@link FileType#Internal} file.\r
+        * @throw GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file.\r
         */\r
        public void copyTo (FileHandle dest) {\r
                InputStream input = null;\r
@@ -183,7 +240,7 @@ public abstract class FileHandle {
 \r
        /**\r
         * Moves this file to the specified file, overwriting the file if it already exists.\r
-        * @throw GdxRuntimeException if the destination file handle is an {@link FileType#Internal} file.\r
+        * @throw GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file.\r
         */\r
        public void moveTo (FileHandle dest) {\r
                copyTo(dest);\r
@@ -194,7 +251,7 @@ public abstract class FileHandle {
         * Returns the length in bytes of this file, or 0 if this file is a directory or does not exist.\r
         */\r
        public long length () {\r
-               if (type == FileType.Internal) {\r
+               if (type == FileType.Classpath || type == FileType.Internal) {\r
                        try {\r
                                InputStream input = read();\r
                                long length = input.available();\r
index 122d846..c3adb83 100644 (file)
@@ -13,47 +13,14 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
 \r
 /**\r
  * A FileHandle intended to be subclassed for the purpose of implemented {@link #read()} and/or {@link #write(boolean)}. Methods\r
- * that would modify a file instead throw UnsupportedOperationException.\r
+ * that would manipulate the file instead throw UnsupportedOperationException.\r
+ * @author Nathan Sweet <misc@n4te.com>\r
  */\r
 public abstract class FileHandleStream extends FileHandle {\r
        public FileHandleStream (String path) {\r
                super(new File(path), FileType.Absolute);\r
        }\r
 \r
-       public FileHandle child (String name) {\r
-               throw new UnsupportedOperationException();\r
-       }\r
-\r
-       public FileHandle parent () {\r
-               throw new UnsupportedOperationException();\r
-       }\r
-\r
-       public String path () {\r
-               return file.getPath();\r
-       }\r
-\r
-       public String name () {\r
-               return file.getName();\r
-       }\r
-\r
-       public String extension () {\r
-               String name = file.getName();\r
-               int dotIndex = name.lastIndexOf('.');\r
-               if (dotIndex == -1) return "";\r
-               return name.substring(dotIndex + 1);\r
-       }\r
-\r
-       public String nameWithoutExtension () {\r
-               String name = file.getName();\r
-               int dotIndex = name.lastIndexOf('.');\r
-               if (dotIndex == -1) return name;\r
-               return name.substring(0, dotIndex);\r
-       }\r
-\r
-       public FileType type () {\r
-               return type;\r
-       }\r
-\r
        public boolean isDirectory () {\r
                return false;\r
        }\r
@@ -66,6 +33,14 @@ public abstract class FileHandleStream extends FileHandle {
                return true;\r
        }\r
 \r
+       public FileHandle child (String name) {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+\r
+       public FileHandle parent () {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+\r
        public InputStream read () {\r
                throw new UnsupportedOperationException();\r
        }\r
index 7c8813a..09d01ad 100644 (file)
@@ -81,8 +81,8 @@ public class BitmapFont {
      * the gdx jar file. This is here to get you up and running quickly.\r
      */\r
     public BitmapFont() {\r
-               this(Gdx.files.internal("com/badlogic/gdx/utils/arial-15.fnt"),\r
-                       Gdx.files.internal("com/badlogic/gdx/utils/arial-15.png"), false);\r
+               this(Gdx.files.classpath("com/badlogic/gdx/utils/arial-15.fnt"),\r
+                       Gdx.files.classpath("com/badlogic/gdx/utils/arial-15.png"), false);\r
     }\r
 \r
     public BitmapFont(FileHandle fontFile, Texture texture, boolean flip) {\r