private static boolean checkFileExistence (FileHandle fh) { try { fh.read().close(); return true; } catch (Exception e) { return false; } }
/** 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()); }
/** Returns a buffered stream for reading this file as bytes. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public BufferedInputStream read (int bufferSize) { return new BufferedInputStream(read(), bufferSize); }
/** Returns a buffered stream for reading this file as bytes. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public BufferedInputStream read (int bufferSize) { return new BufferedInputStream(read(), bufferSize); }
/** 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); }
/** 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); }
/** 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); } }
public InputStream read () { if (type == FileType.Internal) { try { return assets.open(file.getPath()); } catch (IOException ex) { throw new GdxRuntimeException("Error reading file: " + file + " (" + type + ")", ex); } } return super.read(); }
/** 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 (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); } }
static private void copyFile (FileHandle source, FileHandle dest) { try { dest.write(source.read(), false); } catch (Exception ex) { throw new GdxRuntimeException("Error copying source file: " + source.file + " (" + source.type + ")\n" // + "To destination: " + dest.file + " (" + dest.type + ")", ex); } }
@Override public JsonValue parse (FileHandle file) { try { return parse(file.read(8192)); } catch (Exception ex) { throw new SerializationException("Error parsing file: " + file, ex); } }
public Music (OpenALAudio audio, FileHandle file) { super(audio, file); if (audio.noDevice) return; input = new OggInputStream(file.read()); setup(input.getChannels(), input.getSampleRate()); }
/** @param ttfFileRef The file system or classpath location of the TrueTypeFont file. */ static private Font createFont (String ttfFileRef) { try { return Font.createFont(Font.TRUETYPE_FONT, Gdx.files.absolute(ttfFileRef).read()); } catch (FontFormatException ex) { throw new GdxRuntimeException("Invalid font: " + ttfFileRef, ex); } catch (IOException ex) { throw new GdxRuntimeException("Error reading font: " + ttfFileRef, ex); } }
/** Reads the entire file into a byte array. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public byte[] readBytes () { InputStream input = read(); try { return StreamUtils.copyStreamToByteArray(input, estimateLength()); } catch (IOException ex) { throw new GdxRuntimeException("Error reading file: " + this, ex); } finally { StreamUtils.closeQuietly(input); } }
/** @param ttfFileRef The file system or classpath location of the TrueTypeFont file. */ static private Font createFont (String ttfFileRef) { try { return Font.createFont(Font.TRUETYPE_FONT, Gdx.files.absolute(ttfFileRef).read()); } catch (FontFormatException ex) { throw new GdxRuntimeException("Invalid font: " + ttfFileRef, ex); } catch (IOException ex) { throw new GdxRuntimeException("Error reading font: " + ttfFileRef, ex); } }
/** Reads the entire file into a byte array. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public byte[] readBytes () { InputStream input = read(); try { return StreamUtils.copyStreamToByteArray(input, estimateLength()); } catch (IOException ex) { throw new GdxRuntimeException("Error reading file: " + this, ex); } finally { StreamUtils.closeQuietly(input); } }
public Music (OpenALAudio audio, FileHandle file) { super(audio, file); if (audio.noDevice) return; input = new OggInputStream(file.read()); setup(input.getChannels(), input.getSampleRate()); }
public int read (byte[] buffer) { if (input == null) { input = new OggInputStream(file.read(), previousInput); setup(input.getChannels(), input.getSampleRate()); previousInput = null; // release this reference } return input.read(buffer); }
public int read (byte[] buffer) { if (input == null) { input = new OggInputStream(file.read(), previousInput); setup(input.getChannels(), input.getSampleRate()); previousInput = null; // release this reference } return input.read(buffer); }