package com.badlogic.gdx.backends.jogl;\r
\r
import java.io.File;\r
-import java.io.FileInputStream;\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
/**\r
* A {@link FileHandle} implementation for the desktop.\r
* @author mzechner\r
* \r
*/\r
-public class JoglFileHandle implements FileHandle {\r
- /** the file **/\r
- private final File file;\r
- private final FileType type;\r
-\r
+public class JoglFileHandle extends FileHandle {\r
JoglFileHandle (File file, FileType type) {\r
- this.file = file;\r
- this.type = type;\r
+ super(file, type);\r
}\r
\r
- /**\r
- * @return the underlying {@link File}.\r
- */\r
- public File getFile () {\r
- return file;\r
+ public FileHandle child (String name) {\r
+ return new JoglFileHandle(new File(file, name), type);\r
}\r
\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, ex);\r
+ public FileHandle parent () {\r
+ File parent = file.getParentFile();\r
+ if (parent == null) {\r
+ if (type == FileType.Absolute)\r
+ parent = new File("/");\r
+ else\r
+ parent = new File(".");\r
}\r
- }\r
-\r
- public String toString () {\r
- return file.toString();\r
- }\r
-\r
- @Override public String getPath () {\r
- return file.toString();\r
+ return new JoglFileHandle(parent, type);\r
}\r
}\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
-import java.io.*;\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
final class JoglFiles implements Files {\r
private final String externalPath = System.getProperty("user.home") + "/";\r
\r
- public FileHandle getFileHandle (String fileName, FileType type) {\r
- if (type == FileType.External) fileName = this.externalPath + fileName;\r
- File file = new File(fileName);\r
-\r
- if (JoglFileHandle.class.getResource("/" + fileName) == null && file.exists() == false)\r
- throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
- else\r
- return new JoglFileHandle(file, type);\r
- }\r
-\r
- public String[] listDirectory (String directory, FileType type) {\r
- if (type == FileType.External) directory = this.externalPath + directory;\r
- File file = new File(directory);\r
-\r
- if (file.exists() == false) throw new GdxRuntimeException("Directory not found: " + directory + " (" + type + ")");\r
-\r
- return file.list();\r
- }\r
-\r
- public boolean makeDirectory (String directory, FileType type) {\r
- if (type == FileType.Internal) return false;\r
-\r
- File file = null;\r
- if (type == FileType.Absolute)\r
- file = new File(directory);\r
- else\r
- file = new File(this.externalPath + directory);\r
- return file.mkdirs();\r
- }\r
-\r
- public InputStream readFile (String fileName, FileType type) {\r
+ @Override public FileHandle getFileHandle (String fileName, FileType type) {\r
+ File file;\r
if (type == FileType.External)\r
- fileName = this.externalPath + fileName;\r
+ file = new File(this.externalPath + fileName);\r
else if (type == FileType.Internal) {\r
- final String path = fileName.startsWith("/") ? fileName : "/" + fileName;\r
- InputStream input = JoglFileHandle.class.getResourceAsStream(path);\r
- if (input != null) return input;\r
- }\r
-\r
- try {\r
- return new FileInputStream(fileName);\r
- } catch (FileNotFoundException ex) {\r
- throw new GdxRuntimeException("Error reading file: " + fileName);\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
}\r
\r
- public OutputStream writeFile (String fileName, FileType type) {\r
- if (type == FileType.Internal) return null;\r
+ @Override public FileHandle internal (String path) {\r
+ return getFileHandle(path, FileType.Internal);\r
+ }\r
\r
- File file = null;\r
- if (type == FileType.Absolute)\r
- file = new File(fileName);\r
- else\r
- file = new File(this.externalPath + fileName);\r
+ @Override public FileHandle external (String path) {\r
+ return getFileHandle(path, FileType.External);\r
+ }\r
\r
- try {\r
- return new FileOutputStream(file);\r
- } catch (FileNotFoundException e) {\r
- throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
- }\r
+ @Override public FileHandle absolute (String path) {\r
+ return getFileHandle(path, FileType.Absolute);\r
}\r
\r
- @Override\r
- public String getExternalStoragePath() {\r
+ @Override public String getExternalStoragePath () {\r
return externalPath;\r
}\r
\r
- @Override\r
- public boolean isExternalStorageAvailable() {\r
+ @Override public boolean isExternalStorageAvailable () {\r
return true;\r
}\r
}\r