public boolean exists () { if (type == FileType.Internal) { String fileName = file.getPath(); try { assets.open(fileName).close(); // Check if file exists. return true; } catch (Exception ex) { // This is SUPER slow! but we need it for directories. try { return assets.list(fileName).length > 0; } catch (Exception ignored) { } return false; } } return super.exists(); }
public boolean exists () { if (type == FileType.Internal) { String fileName = file.getPath(); try { assets.open(fileName).close(); // Check if file exists. return true; } catch (Exception ex) { // This is SUPER slow! but we need it for directories. try { return assets.list(fileName).length > 0; } catch (Exception ignored) { } return false; } } return super.exists(); }
public HeadlessPreferences(FileHandle file) { this.file = file; if (!file.exists()) return; InputStream in = null; try { in = new BufferedInputStream(file.read()); properties.loadFromXML(in); } catch (Throwable t) { t.printStackTrace(); } finally { StreamUtils.closeQuietly(in); } }
public HeadlessPreferences(FileHandle file) { this.file = file; if (!file.exists()) return; InputStream in = null; try { in = new BufferedInputStream(file.read()); properties.loadFromXML(in); } catch (Throwable t) { t.printStackTrace(); } finally { StreamUtils.closeQuietly(in); } }
public Lwjgl3Preferences (FileHandle file) { this.file = file; if (!file.exists()) return; InputStream in = null; try { in = new BufferedInputStream(file.read()); properties.loadFromXML(in); } catch (Throwable t) { t.printStackTrace(); } finally { StreamUtils.closeQuietly(in); } }
public Lwjgl3Preferences (FileHandle file) { this.file = file; if (!file.exists()) return; InputStream in = null; try { in = new BufferedInputStream(file.read()); properties.loadFromXML(in); } catch (Throwable t) { t.printStackTrace(); } finally { StreamUtils.closeQuietly(in); } }
private FileHandle getZipFileHandleIfExists (FileHandle handle, String path) { try { assets.open(path).close(); // Check if file exists. return handle; } catch (Exception ex) { // try APK expansion instead FileHandle zipHandle = new AndroidZipFileHandle(path); if (!zipHandle.isDirectory()) return zipHandle; else if (zipHandle.exists()) return zipHandle; } return handle; }
private FileHandle getZipFileHandleIfExists (FileHandle handle, String path) { try { assets.open(path).close(); // Check if file exists. return handle; } catch (Exception ex) { // try APK expansion instead FileHandle zipHandle = new AndroidZipFileHandle(path); if (!zipHandle.isDirectory()) return zipHandle; else if (zipHandle.exists()) return zipHandle; } return handle; }
public LwjglPreferences (FileHandle file) { this.name = file.name(); this.file = file; if (!file.exists()) return; InputStream in = null; try { in = new BufferedInputStream(file.read()); properties.loadFromXML(in); } catch (Throwable t) { t.printStackTrace(); } finally { StreamUtils.closeQuietly(in); } }
public LwjglPreferences (FileHandle file) { this.name = file.name(); this.file = file; if (!file.exists()) return; InputStream in = null; try { in = new BufferedInputStream(file.read()); properties.loadFromXML(in); } catch (Throwable t) { t.printStackTrace(); } finally { StreamUtils.closeQuietly(in); } }
/** Creates a skin containing the resources in the specified skin JSON file. If a file in the same directory with a ".atlas" * extension exists, it is loaded as a {@link TextureAtlas} and the texture regions added to the skin. The atlas is * automatically disposed when the skin is disposed. */ public Skin (FileHandle skinFile) { FileHandle atlasFile = skinFile.sibling(skinFile.nameWithoutExtension() + ".atlas"); if (atlasFile.exists()) { atlas = new TextureAtlas(atlasFile); addRegions(atlas); } load(skinFile); }
/** Creates a skin containing the resources in the specified skin JSON file. If a file in the same directory with a ".atlas" * extension exists, it is loaded as a {@link TextureAtlas} and the texture regions added to the skin. The atlas is * automatically disposed when the skin is disposed. */ public Skin (FileHandle skinFile) { FileHandle atlasFile = skinFile.sibling(skinFile.nameWithoutExtension() + ".atlas"); if (atlasFile.exists()) { atlas = new TextureAtlas(atlasFile); addRegions(atlas); } load(skinFile); }
@Override public FileHandle resolve (String fileName) { Resolution bestResolution = choose(descriptors); FileHandle originalHandle = new FileHandle(fileName); FileHandle handle = baseResolver.resolve(resolve(originalHandle, bestResolution.folder)); if (!handle.exists()) handle = baseResolver.resolve(fileName); return handle; }
@Override public FileHandle resolve (String fileName) { Resolution bestResolution = choose(descriptors); FileHandle originalHandle = new FileHandle(fileName); FileHandle handle = baseResolver.resolve(resolve(originalHandle, bestResolution.folder)); if (!handle.exists()) handle = baseResolver.resolve(fileName); return handle; }
/** May return null. */ protected FileHandle loadAtlas (Element root, FileHandle tmxFile) throws IOException { Element e = root.getChildByName("properties"); if (e != null) { for (Element property : e.getChildrenByName("property")) { String name = property.getAttribute("name", null); String value = property.getAttribute("value", null); if (name.equals("atlas")) { if (value == null) { value = property.getText(); } if (value == null || value.length() == 0) { // keep trying until there are no more atlas properties continue; } return getRelativeFileHandle(tmxFile, value); } } } FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas"); return atlasFile.exists() ? atlasFile : null; }
/** May return null. */ protected FileHandle loadAtlas (Element root, FileHandle tmxFile) throws IOException { Element e = root.getChildByName("properties"); if (e != null) { for (Element property : e.getChildrenByName("property")) { String name = property.getAttribute("name", null); String value = property.getAttribute("value", null); if (name.equals("atlas")) { if (value == null) { value = property.getText(); } if (value == null || value.length() == 0) { // keep trying until there are no more atlas properties continue; } return getRelativeFileHandle(tmxFile, value); } } } FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas"); return atlasFile.exists() ? atlasFile : null; }
/** Moves this file to the specified file, overwriting the file if it already exists. * @throws GdxRuntimeException if the source or destination file handle is a {@link FileType#Classpath} or * {@link FileType#Internal} file. */ public void moveTo (FileHandle dest) { switch (type) { case Classpath: throw new GdxRuntimeException("Cannot move a classpath file: " + file); case Internal: throw new GdxRuntimeException("Cannot move an internal file: " + file); case Absolute: case External: // Try rename for efficiency and to change case on case-insensitive file systems. if (file().renameTo(dest.file())) return; } copyTo(dest); delete(); if (exists() && isDirectory()) deleteDirectory(); }
/** Moves this file to the specified file, overwriting the file if it already exists. * @throws GdxRuntimeException if the source or destination file handle is a {@link FileType#Classpath} or * {@link FileType#Internal} file. */ public void moveTo (FileHandle dest) { switch (type) { case Classpath: throw new GdxRuntimeException("Cannot move a classpath file: " + file); case Internal: throw new GdxRuntimeException("Cannot move an internal file: " + file); case Absolute: case External: // Try rename for efficiency and to change case on case-insensitive file systems. if (file().renameTo(dest.file())) return; } copyTo(dest); delete(); if (exists() && isDirectory()) deleteDirectory(); }
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a * file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination * doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If * this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is * a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't * exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively. * @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} * file, or copying failed. */ public void copyTo (FileHandle dest) { if (!isDirectory()) { if (dest.isDirectory()) dest = dest.child(name()); copyFile(this, dest); return; } if (dest.exists()) { if (!dest.isDirectory()) throw new GdxRuntimeException("Destination exists but is not a directory: " + dest); } else { dest.mkdirs(); if (!dest.isDirectory()) throw new GdxRuntimeException("Destination directory cannot be created: " + dest); } copyDirectory(this, dest.child(name())); }
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a * file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination * doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If * this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is * a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't * exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively. * @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} * file, or copying failed. */ public void copyTo (FileHandle dest) { if (!isDirectory()) { if (dest.isDirectory()) dest = dest.child(name()); copyFile(this, dest); return; } if (dest.exists()) { if (!dest.isDirectory()) throw new GdxRuntimeException("Destination exists but is not a directory: " + dest); } else { dest.mkdirs(); if (!dest.isDirectory()) throw new GdxRuntimeException("Destination directory cannot be created: " + dest); } copyDirectory(this, dest.child(name())); }