public void write(InputStream input, boolean append) { OutputStream output = null; try { output = write(append); LSystem.copyStream(input, output, 4096); } catch (Exception ex) { throw new RuntimeException("Error stream writing to file: " + file + " (" + type + ")", ex); } finally { LSystem.close(input); LSystem.close(output); } }
public Reader reader(String charset) { InputStream stream = read(); try { return new InputStreamReader(stream, charset); } catch (UnsupportedEncodingException ex) { LSystem.close(stream); throw new RuntimeException("Error reading file: " + this, ex); } }
public void writeBytes(byte[] bytes, int offset, int length, boolean append) { OutputStream output = write(append); try { output.write(bytes, offset, length); } catch (IOException ex) { throw new RuntimeException("Error writing file: " + file + " (" + type + ")", ex); } finally { LSystem.close(output); } }
public byte[] readBytes() { InputStream input = read(); try { return LSystem.copyStreamToByteArray(input, estimateLength()); } catch (IOException ex) { throw new RuntimeException("Error reading file: " + this, ex); } finally { LSystem.close(input); } }
public void writeString(String string, boolean append, String charset) { Writer writer = null; try { writer = writer(append, charset); writer.write(string); } catch (Exception ex) { throw new RuntimeException("Error writing file: " + file + " (" + type + ")", ex); } finally { LSystem.close(writer); } }
public long length() { if (type == FileType.Classpath || (type == FileType.Internal && !file.exists())) { InputStream input = read(); try { return input.available(); } catch (Exception ignored) { } finally { LSystem.close(input); } return 0; } return file().length(); }
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 { LSystem.close(input); } return position - offset; }
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 RuntimeException("Error reading layout file: " + this, ex); } finally { LSystem.close(reader); } return output.toString(); }