[changed] FileHandle getFileName -> getPath, getInputStream -> readFile.
\r
if (aHandle.isAsset()) {\r
try {\r
- AssetFileDescriptor descriptor = aHandle.getAssetManager().openFd(aHandle.getFileName());\r
+ AssetFileDescriptor descriptor = aHandle.getAssetManager().openFd(aHandle.getPath());\r
mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());\r
descriptor.close();\r
mediaPlayer.prepare();\r
}\r
} else {\r
try {\r
- mediaPlayer.setDataSource(aHandle.getFileName());\r
+ mediaPlayer.setDataSource(aHandle.getPath());\r
mediaPlayer.prepare();\r
AndroidMusic music = new AndroidMusic(this, mediaPlayer);\r
musics.add(music);\r
AndroidFileHandle aHandle = (AndroidFileHandle)file;\r
if (aHandle.isAsset()) {\r
try {\r
- AssetFileDescriptor descriptor = aHandle.getAssetManager().openFd(aHandle.getFileName());\r
+ AssetFileDescriptor descriptor = aHandle.getAssetManager().openFd(aHandle.getPath());\r
AndroidSound sound = new AndroidSound(soundPool, manager, soundPool.load(descriptor, 1));\r
descriptor.close();\r
return sound;\r
}\r
} else {\r
try {\r
- return new AndroidSound(soundPool, manager, soundPool.load(aHandle.getFileName(), 1));\r
+ return new AndroidSound(soundPool, manager, soundPool.load(aHandle.getPath(), 1));\r
} catch (Exception e) {\r
throw new GdxRuntimeException("Couldn't load Sound from file '" + file + "'", e);\r
}\r
/**\r
* @return the filename\r
*/\r
- public String getFileName () {\r
+ public String getPath () {\r
return filename;\r
}\r
\r
- public InputStream getInputStream () {\r
+ public InputStream readFile () {\r
try {\r
return manager.open(filename);\r
} catch (IOException ex) {\r
* {@inheritDoc}\r
*/\r
@Override public Pixmap newPixmap (FileHandle file) {\r
- return newPixmap(file.getInputStream());\r
+ return newPixmap(file.readFile());\r
}\r
\r
/**\r
import java.io.FileNotFoundException;\r
import java.io.InputStream;\r
\r
+import com.badlogic.gdx.Files.FileType;\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
public class JoglFileHandle implements FileHandle {\r
/** the file **/\r
private final File file;\r
+ private final FileType type;\r
\r
- JoglFileHandle (File file) {\r
+ JoglFileHandle (File file, FileType type) {\r
this.file = file;\r
+ this.type = type;\r
}\r
\r
/**\r
return file;\r
}\r
\r
- public InputStream getInputStream () {\r
+ public InputStream readFile () {\r
+ if (type == FileType.Internal) {\r
+ InputStream input = JoglFileHandle.class.getResourceAsStream("/" + file);\r
+ if (input != null) return input;\r
+ }\r
try {\r
return new FileInputStream(file);\r
} catch (FileNotFoundException ex) {\r
- throw new GdxRuntimeException("Error reading file: " + file);\r
+ throw new GdxRuntimeException("Error reading file: " + file, ex);\r
}\r
}\r
\r
return file.toString();\r
}\r
\r
- @Override public String getFileName() {\r
+ @Override public String getPath () {\r
return file.toString();\r
}\r
}\r
if (file.exists() == false)\r
throw new GdxRuntimeException("File '" + filename + "' doesn't exist");\r
else\r
- return new JoglFileHandle(file);\r
+ return new JoglFileHandle(file, type);\r
}\r
\r
/**\r
\r
@Override\r
public Pixmap newPixmap(FileHandle file) {\r
- return newPixmap(file.getInputStream());\r
+ return newPixmap(file.readFile());\r
}\r
\r
@Override\r
import java.io.FileNotFoundException;\r
import java.io.InputStream;\r
\r
+import com.badlogic.gdx.Files.FileType;\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
public class LwjglFileHandle implements FileHandle {\r
/** the file **/\r
private final File file;\r
+ private final FileType type;\r
\r
- LwjglFileHandle (File file) {\r
+ LwjglFileHandle (File file, FileType type) {\r
this.file = file;\r
+ this.type = type;\r
}\r
\r
/**\r
return file;\r
}\r
\r
- public InputStream getInputStream () {\r
+ public InputStream readFile () {\r
+ if (type == FileType.Internal) {\r
+ InputStream input = LwjglFileHandle.class.getResourceAsStream("/" + file);\r
+ if (input != null) return input;\r
+ }\r
try {\r
return new FileInputStream(file);\r
} catch (FileNotFoundException ex) {\r
return file.toString();\r
}\r
\r
- @Override public String getFileName() {\r
+ @Override public String getPath() {\r
return file.toString();\r
}\r
}\r
if (file.exists() == false)\r
throw new GdxRuntimeException("File '" + filename + "' doesn't exist");\r
else\r
- return new LwjglFileHandle(file);\r
+ return new LwjglFileHandle(file, type);\r
}\r
\r
public String[] listDirectory (String directory, FileType type) {\r
}\r
\r
public Pixmap newPixmap (FileHandle file) {\r
- return newPixmap(file.getInputStream());\r
+ return newPixmap(file.readFile());\r
}\r
\r
public Pixmap newPixmap (Object nativePixmap) {\r
public interface Files {\r
/**\r
* Enum describing the three file types, internal, external and absolute. Internal files are located in the asset directory on\r
- * Android and are relative to the applications root directory on the desktop. External files are relative to the SD-card on\r
+ * Android and are relative to the root of the classpath or application's root directory on the desktop. External files are relative to the SD-card on\r
* Android and relative to the home directory of the current user on the Desktop. Absolute files are just that, absolute files\r
* that can point anywhere.\r
* @author mzechner\r
import java.io.InputStream;\r
\r
import com.badlogic.gdx.Files;\r
+import com.badlogic.gdx.Files.FileType;\r
\r
/**\r
* A file handle represents a system dependant representation of an internal or external file. FileHandles can only be created via\r
/**\r
* @return a new {@link InputStream} to the underlying file.\r
*/\r
- public InputStream getInputStream ();\r
+ public InputStream readFile ();\r
\r
/**\r
- * @return the file name.\r
+ * @return the path to the file.\r
*/\r
- public String getFileName ();\r
+ public String getPath ();\r
}\r
\r
this(new FileHandle() {\r
@Override\r
- public String getFileName() {\r
+ public String getPath() {\r
return "/com/badlogic/gdx/utils/arial-15.fnt";\r
}\r
\r
@Override\r
- public InputStream getInputStream() {\r
- return BitmapFont.class.getResourceAsStream(getFileName());\r
+ public InputStream readFile() {\r
+ return BitmapFont.class.getResourceAsStream(getPath());\r
}\r
}, new FileHandle() {\r
@Override\r
- public String getFileName() {\r
+ public String getPath() {\r
return "/com/badlogic/gdx/utils/arial-15.png";\r
}\r
\r
@Override\r
- public InputStream getInputStream() {\r
- return BitmapFont.class.getResourceAsStream(getFileName());\r
+ public InputStream readFile() {\r
+ return BitmapFont.class.getResourceAsStream(getPath());\r
}\r
}, false);\r
}\r
float invTexHeight = 1.0f / texture.getHeight();\r
\r
BufferedReader reader = new BufferedReader(new InputStreamReader(\r
- fontFile.getInputStream()), 512);\r
+ fontFile.readFile()), 512);\r
try {\r
reader.readLine(); // info\r
\r
}\r
\r
void loadEmitters (FileHandle file) {\r
- InputStream input = file.getInputStream();\r
+ InputStream input = file.readFile();\r
if (input == null) throw new GdxRuntimeException("Effect file not found: " + file);\r
emitters.clear();\r
BufferedReader reader = null;\r