/** Reads the entire file into a string using the specified charset. * @param charset If null the default charset is used. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public String readString (String charset) { StringBuilder output = new StringBuilder(estimateLength()); InputStreamReader reader = null; try { if (charset == null) reader = new InputStreamReader(read()); else reader = new InputStreamReader(read(), charset); char[] buffer = new char[256]; while (true) { int length = reader.read(buffer); if (length == -1) break; output.append(buffer, 0, length); } } catch (IOException ex) { throw new GdxRuntimeException("Error reading layout file: " + this, ex); } finally { StreamUtils.closeQuietly(reader); } return output.toString(); }
/** Reads the entire file into a string using the specified charset. * @param charset If null the default charset is used. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public String readString (String charset) { StringBuilder output = new StringBuilder(estimateLength()); InputStreamReader reader = null; try { if (charset == null) reader = new InputStreamReader(read()); else reader = new InputStreamReader(read(), charset); char[] buffer = new char[256]; while (true) { int length = reader.read(buffer); if (length == -1) break; output.append(buffer, 0, length); } } catch (IOException ex) { throw new GdxRuntimeException("Error reading layout file: " + this, ex); } finally { StreamUtils.closeQuietly(reader); } return output.toString(); }
/** 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); } }
/** 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); } }
/** Reads the entire file into a string using the specified charset. * @param charset If null the default charset is used. * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public String readString (String charset) { StringBuilder output = new StringBuilder(estimateLength()); InputStreamReader reader = null; try { if (charset == null) reader = new InputStreamReader(read()); else reader = new InputStreamReader(read(), charset); char[] buffer = new char[256]; while (true) { int length = reader.read(buffer); if (length == -1) break; output.append(buffer, 0, length); } } catch (IOException ex) { throw new GdxRuntimeException("Error reading layout file: " + this, ex); } finally { StreamUtils.closeQuietly(reader); } return output.toString(); }
/** 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); } }