/** Returns a buffered reader for reading this file as characters. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public BufferedReader reader (int bufferSize, String charset) { try { return new BufferedReader(new InputStreamReader(read(), charset), bufferSize); } catch (UnsupportedEncodingException ex) { throw new GdxRuntimeException("Error reading file: " + this, ex); } }
static public FileHandle tempFile (String prefix) { try { return new FileHandle(File.createTempFile(prefix, null)); } catch (IOException ex) { throw new GdxRuntimeException("Unable to create temp file.", ex); } }
static public String getAtlasName (String name, boolean flattenPaths) { return flattenPaths ? new FileHandle(name).name() : name; } }
static private void copyDirectory (FileHandle sourceDir, FileHandle destDir) { destDir.mkdirs(); FileHandle[] files = sourceDir.list(); for (int i = 0, n = files.length; i < n; i++) { FileHandle srcFile = files[i]; FileHandle destFile = destDir.child(srcFile.name()); if (srcFile.isDirectory()) copyDirectory(srcFile, destFile); else copyFile(srcFile, destFile); } } }
public void loadEmitters (FileHandle effectFile) { InputStream input = effectFile.read(); emitters.clear(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(input), 512); while (true) { ParticleEmitter emitter = newEmitter(reader); emitters.add(emitter); if (reader.readLine() == null) break; } } catch (IOException ex) { throw new GdxRuntimeException("Error loading effect: " + effectFile, ex); } finally { StreamUtils.closeQuietly(reader); } }
public TextureAtlasData (FileHandle packFile, FileHandle imagesDir, boolean flip) { BufferedReader reader = new BufferedReader(new InputStreamReader(packFile.read()), 64); try { Page pageImage = null; while (true) { String line = reader.readLine(); if (line == null) break; if (line.trim().length() == 0) pageImage = null; else if (pageImage == null) { FileHandle file = imagesDir.child(line); pages.add(pageImage); } else { boolean rotate = Boolean.valueOf(readValue(reader)); regions.add(region); throw new GdxRuntimeException("Error reading pack file: " + packFile, ex); } finally { StreamUtils.closeQuietly(reader); regions.sort(indexComparator);
BufferedReader reader = new BufferedReader(new InputStreamReader(Gdx.files.absolute(hieroFileRef).read(), "UTF-8")); while (true) { String line = reader.readLine(); if (line == null) break; line = line.trim(); effects.add(Class.forName(value).newInstance()); } catch (Throwable ex) { throw new GdxRuntimeException("Unable to create effect instance: " + value, ex); reader.close(); } catch (Throwable ex) { throw new GdxRuntimeException("Unable to load Hiero font file: " + hieroFileRef, ex);
/** Returns a buffered reader for reading this file as characters. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public BufferedReader reader (int bufferSize) { return new BufferedReader(new InputStreamReader(read()), bufferSize); }
/** If the PSH file contains a line starting with {@link PolygonRegionParameters#texturePrefix params.texturePrefix}, an * {@link AssetDescriptor} for the file referenced on that line will be added to the returned Array. Otherwise a sibling of the * given file with the same name and the first found extension in {@link PolygonRegionParameters#textureExtensions * params.textureExtensions} will be used. If no suitable file is found, the returned Array will be empty. */ @Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, PolygonRegionParameters params) { if (params == null) params = defaultParameters; String image = null; try { BufferedReader reader = file.reader(params.readerBuffer); for (String line = reader.readLine(); line != null; line = reader.readLine()) if (line.startsWith(params.texturePrefix)) { image = line.substring(params.texturePrefix.length()); break; } reader.close(); } catch (IOException e) { throw new GdxRuntimeException("Error reading " + fileName, e); } if (image == null && params.textureExtensions != null) for (String extension : params.textureExtensions) { FileHandle sibling = file.sibling(file.nameWithoutExtension().concat("." + extension)); if (sibling.exists()) image = sibling.name(); } if (image != null) { Array<AssetDescriptor> deps = new Array<AssetDescriptor>(1); deps.add(new AssetDescriptor<Texture>(file.sibling(image), Texture.class)); return deps; } return null; }
/** Returns a reader for reading this file as characters. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public Reader reader (String charset) { InputStream stream = read(); try { return new InputStreamReader(stream, charset); } catch (UnsupportedEncodingException ex) { StreamUtils.closeQuietly(stream); throw new GdxRuntimeException("Error reading file: " + this, ex); } }
/** Returns a reader for reading this file as characters. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public Reader reader () { return new InputStreamReader(read()); }
private void loadImages (ParticleEmitter emitter) { String imagePath = null; try { Array<Sprite> sprites = new Array<Sprite>(); Array<String> imagePaths = emitter.getImagePaths(); for (int i = 0; i < imagePaths.size; i++) { imagePath = imagePaths.get(i); String imageName = new File(imagePath.replace('\\', '/')).getName(); FileHandle file; if (imagePath.equals(ParticleEditor.DEFAULT_PARTICLE) || imagePath.equals(ParticleEditor.DEFAULT_PREMULT_PARTICLE)) { file = Gdx.files.classpath(imagePath); } else { if ((imagePath.contains("/") || imagePath.contains("\\")) && !imageName.contains("..")) { file = Gdx.files.absolute(imagePath); if (!file.exists()) { file = Gdx.files.absolute(new File(effectFile.getParentFile(), imageName).getAbsolutePath()); sprites.add(new Sprite(new Texture(file))); ex.printStackTrace(); final String imagePathFinal = imagePath; EventQueue.invokeLater(new Runnable() {
@Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, ParticleEffectLoadParameter parameter) { Json json = new Json(); ResourceData<ParticleEffect> data = json.fromJson(ResourceData.class, file); Array<AssetData> assets = null; synchronized (items) { ObjectMap.Entry<String, ResourceData<ParticleEffect>> entry = new ObjectMap.Entry<String, ResourceData<ParticleEffect>>(); entry.key = fileName; entry.value = data; items.add(entry); assets = data.getAssets(); } Array<AssetDescriptor> descriptors = new Array<AssetDescriptor>(); for (AssetData<?> assetData : assets) { // If the asset doesn't exist try to load it from loading effect directory if (!resolve(assetData.filename).exists()) { assetData.filename = file.parent().child(Gdx.files.internal(assetData.filename).name()).path(); } if (assetData.type == ParticleEffect.class) { descriptors.add(new AssetDescriptor(assetData.filename, assetData.type, parameter)); } else descriptors.add(new AssetDescriptor(assetData.filename, assetData.type)); } return descriptors; }
@Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle tmxFile, Parameters parameter) { Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>(); try { root = xml.parse(tmxFile); for (FileHandle image : loadTileSheets(root, tmxFile)) { dependencies.add(new AssetDescriptor(image.path(), Texture.class)); } return dependencies; } catch (IOException e) { throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e); } }
@Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle atlasFile, TextureAtlasParameter parameter) { FileHandle imgDir = atlasFile.parent(); if (parameter != null) data = new TextureAtlasData(atlasFile, imgDir, parameter.flip); else { data = new TextureAtlasData(atlasFile, imgDir, false); } Array<AssetDescriptor> dependencies = new Array(); for (Page page : data.getPages()) { TextureParameter params = new TextureParameter(); params.format = page.format; params.genMipMaps = page.useMipMaps; params.minFilter = page.minFilter; params.magFilter = page.magFilter; dependencies.add(new AssetDescriptor(page.textureFile, Texture.class, params)); } return dependencies; }
public OpenALSound newSound (FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); Class<? extends OpenALSound> soundClass = extensionToSoundClass.get(file.extension().toLowerCase()); if (soundClass == null) throw new GdxRuntimeException("Unknown file extension for sound: " + file); try { return soundClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file); } catch (Exception ex) { throw new GdxRuntimeException("Error creating sound " + soundClass.getName() + " for file: " + file, ex); } }
/** Deletes this file or empty directory and returns success. Will not delete a directory that has children. * @throws 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(); }
@Override public void flush () { OutputStream out = null; try { out = new BufferedOutputStream(file.write(false)); properties.storeToXML(out, null); } catch (Exception ex) { throw new GdxRuntimeException("Error writing preferences: " + file, ex); } finally { StreamUtils.closeQuietly(out); } }