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