final class JoglFiles implements Files {\r
private final String externalPath = System.getProperty("user.home") + "/";\r
\r
- /**\r
- * {@inheritDoc}\r
- */\r
- @Override public FileHandle getFileHandle (String filename, FileType type) {\r
- File file = null;\r
- if (type == FileType.Absolute || type == FileType.Internal)\r
- file = new File(filename);\r
- else\r
- file = new File(this.externalPath + filename);\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 (file.exists() == false)\r
- throw new GdxRuntimeException("File '" + filename + "' doesn't exist");\r
+ if (JoglFileHandle.class.getResource("/" + fileName) == null && file.exists() == false)\r
+ throw new GdxRuntimeException("File '" + fileName + "' doesn't exist");\r
else\r
return new JoglFileHandle(file, type);\r
}\r
\r
- /**\r
- * {@inheritDoc}\r
- */\r
- @Override public String[] listDirectory (String directory, FileType type) {\r
- File file = null;\r
- if (type == FileType.Absolute || type == FileType.Internal)\r
- file = new File(directory);\r
- else\r
- file = new File(this.externalPath + directory);\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 '" + directory + "' does not exist");\r
\r
return file.list();\r
}\r
\r
- /**\r
- * {@inheritDoc}\r
- */\r
- @Override public boolean makeDirectory (String directory, FileType type) {\r
- File file = null;\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
return file.mkdirs();\r
}\r
\r
- /**\r
- * {@inheritDoc}\r
- */\r
- @Override public InputStream readFile (String fileName, FileType type) {\r
- File file = null;\r
- InputStream in = null;\r
- if (type == FileType.Absolute || type == FileType.Internal)\r
- file = new File(fileName);\r
- else\r
- file = new File(this.externalPath + fileName);\r
+ public InputStream readFile (String fileName, FileType type) {\r
+ if (type == FileType.External)\r
+ fileName = this.externalPath + fileName;\r
+ else if (type == FileType.Internal) {\r
+ InputStream input = JoglFileHandle.class.getResourceAsStream("/" + fileName);\r
+ if (input != null) return input;\r
+ }\r
\r
try {\r
- in = new FileInputStream(file);\r
- } catch (FileNotFoundException e) {\r
- throw new GdxRuntimeException("File '" + file + "' does not exist");\r
+ return new FileInputStream(fileName);\r
+ } catch (FileNotFoundException ex) {\r
+ throw new GdxRuntimeException("Error reading file: " + fileName);\r
}\r
-\r
- return in;\r
}\r
\r
- /**\r
- * {@inheritDoc}\r
- */\r
- @Override public OutputStream writeFile (String filename, FileType type) {\r
- File file = null;\r
- FileOutputStream out = null;\r
-\r
+ public OutputStream writeFile (String filename, FileType type) {\r
if (type == FileType.Internal) return null;\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
\r
try {\r
- out = new FileOutputStream(file);\r
+ return new FileOutputStream(file);\r
} catch (FileNotFoundException e) {\r
throw new GdxRuntimeException("File '" + file + "' does not exist");\r
}\r
-\r
- return out;\r
}\r
}\r
import java.io.OutputStream;\r
\r
import com.badlogic.gdx.Files;\r
+import com.badlogic.gdx.Files.FileType;\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
final class LwjglFiles implements Files {\r
private final String externalPath = System.getProperty("user.home") + "/";\r
\r
- public FileHandle getFileHandle (String filename, FileType type) {\r
- File file = null;\r
- if (type == FileType.Absolute || type == FileType.Internal)\r
- file = new File(filename);\r
- else\r
- file = new File(this.externalPath + filename);\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 (file.exists() == false)\r
- throw new GdxRuntimeException("File '" + filename + "' doesn't exist");\r
+ if (LwjglFileHandle.class.getResource("/" + fileName) == null && file.exists() == false)\r
+ throw new GdxRuntimeException("File '" + fileName + "' doesn't exist");\r
else\r
return new LwjglFileHandle(file, type);\r
}\r
\r
public String[] listDirectory (String directory, FileType type) {\r
- File file = null;\r
- if (type == FileType.Absolute || type == FileType.Internal)\r
- file = new File(directory);\r
- else\r
- file = new File(this.externalPath + directory);\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 '" + directory + "' does not exist");\r
\r
}\r
\r
public boolean makeDirectory (String directory, FileType type) {\r
- File file = null;\r
-\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
}\r
\r
public InputStream readFile (String fileName, FileType type) {\r
- File file = null;\r
- InputStream in = null;\r
- if (type == FileType.Absolute || type == FileType.Internal)\r
- file = new File(fileName);\r
- else\r
- file = new File(this.externalPath + fileName);\r
+ if (type == FileType.External)\r
+ fileName = this.externalPath + fileName;\r
+ else if (type == FileType.Internal) {\r
+ InputStream input = LwjglFileHandle.class.getResourceAsStream("/" + fileName);\r
+ if (input != null) return input;\r
+ }\r
\r
try {\r
- in = new FileInputStream(file);\r
- } catch (FileNotFoundException e) {\r
- throw new GdxRuntimeException("File '" + file + "' does not exist");\r
+ return new FileInputStream(fileName);\r
+ } catch (FileNotFoundException ex) {\r
+ throw new GdxRuntimeException("Error reading file: " + fileName);\r
}\r
-\r
- return in;\r
}\r
\r
public OutputStream writeFile (String filename, FileType type) {\r
- File file = null;\r
- FileOutputStream out = null;\r
-\r
if (type == FileType.Internal) return null;\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
\r
try {\r
- out = new FileOutputStream(file);\r
+ return new FileOutputStream(file);\r
} catch (FileNotFoundException e) {\r
throw new GdxRuntimeException("File '" + file + "' does not exist");\r
}\r
-\r
- return out;\r
}\r
}\r