/** Returns a reader for reading this file as characters. * @throw RuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public Reader reader () { return new InputStreamReader(read()); }
/** Returns a reader for reading this file as characters. * @throw RuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public Reader reader () { return new InputStreamReader(read()); }
/** Returns a reader for reading this file as characters. * @throw RuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public Reader reader (String charset) { try { return new InputStreamReader(read(), charset); } catch (UnsupportedEncodingException ex) { throw new RuntimeException("Error reading file: " + this, ex); } }
/** Returns a reader for reading this file as characters. * @throw RuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public Reader reader (String charset) { try { return new InputStreamReader(read(), charset); } catch (UnsupportedEncodingException ex) { throw new RuntimeException("Error reading file: " + this, ex); } }
/** Returns a buffered reader for reading this file as characters. * @throw RuntimeException 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. * @throw RuntimeException 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 RuntimeException("Error reading file: " + this, ex); } }
/** Returns a buffered reader for reading this file as characters. * @throw RuntimeException 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. * @throw RuntimeException 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 RuntimeException("Error reading file: " + this, ex); } }
static private void copyFile (FileDescriptor source, FileDescriptor dest) { try { dest.write(source.read(), false); } catch (Exception ex) { throw new RuntimeException("Error copying source file: " + source.file + " (" + source.type + ")\n" // + "To destination: " + dest.file + " (" + dest.type + ")", ex); } }
static private void copyFile (FileDescriptor source, FileDescriptor dest) { try { dest.write(source.read(), false); } catch (Exception ex) { throw new RuntimeException("Error copying source file: " + source.file + " (" + source.type + ")\n" // + "To destination: " + dest.file + " (" + dest.type + ")", ex); } }
/** Reads the entire file into the byte array. The byte array must be big enough to hold the file's data. * @param bytes the array to load the file into * @param offset the offset to start writing bytes * @param size the number of bytes to read, see {@link #length()} * @return the number of read bytes */ public int readBytes (byte[] bytes, int offset, int size) { InputStream input = read(); int position = 0; try { while (true) { int count = input.read(bytes, offset + position, size - position); if (count <= 0) break; position += count; } } catch (IOException ex) { throw new RuntimeException("Error reading file: " + this, ex); } finally { try { if (input != null) input.close(); } catch (IOException ignored) { } } return position - offset; }
/** Reads the entire file into the byte array. The byte array must be big enough to hold the file's data. * @param bytes the array to load the file into * @param offset the offset to start writing bytes * @param size the number of bytes to read, see {@link #length()} * @return the number of read bytes */ public int readBytes (byte[] bytes, int offset, int size) { InputStream input = read(); int position = 0; try { while (true) { int count = input.read(bytes, offset + position, size - position); if (count <= 0) break; position += count; } } catch (IOException ex) { throw new RuntimeException("Error reading file: " + this, ex); } finally { try { if (input != null) input.close(); } catch (IOException ignored) { } } return position - offset; }
/** Reads the entire file into a string using the specified charset. * @throw RuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public String readString (String charset) { StringBuilder output = new StringBuilder(512); 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 RuntimeException("Error reading layout file: " + this, ex); } finally { try { if (reader != null) reader.close(); } catch (IOException ignored) { } } return output.toString(); }
/** Reads the entire file into a string using the specified charset. * @throw RuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public String readString (String charset) { StringBuilder output = new StringBuilder(512); 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 RuntimeException("Error reading layout file: " + this, ex); } finally { try { if (reader != null) reader.close(); } catch (IOException ignored) { } } return output.toString(); }
/** Returns the length in bytes of this file, or 0 if this file is a directory, does not exist, or the size cannot otherwise be * determined. */ public long length () { if (type == FileType.Classpath || !file.exists()) { InputStream input = read(); try { return input.available(); } catch (Exception ignored) { } finally { try { input.close(); } catch (IOException ignored) { } } return 0; } return file().length(); }
/** Returns the length in bytes of this file, or 0 if this file is a directory, does not exist, or the size cannot otherwise be * determined. */ public long length () { if (type == FileType.Classpath || !file.exists()) { InputStream input = read(); try { return input.available(); } catch (Exception ignored) { } finally { try { input.close(); } catch (IOException ignored) { } } return 0; } return file().length(); }
byte[] buffer = new byte[length]; int position = 0; InputStream input = read(); try { while (true) {
byte[] buffer = new byte[length]; int position = 0; InputStream input = read(); try { while (true) {
/** Returns a reader for reading this file as characters. * @throw RuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public Reader reader (String charset) { try { return new InputStreamReader(read(), charset); } catch (UnsupportedEncodingException ex) { throw new RuntimeException("Error reading file: " + this, ex); } }
/** Returns a buffered reader for reading this file as characters. * @throw RuntimeException 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 RuntimeException("Error reading file: " + this, ex); } }