Exemple #1
0
 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);
   }
 }
Exemple #2
0
 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);
   }
 }
Exemple #3
0
 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);
   }
 }
Exemple #4
0
 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);
   }
 }
Exemple #5
0
 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);
   }
 }
Exemple #6
0
 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();
 }
Exemple #7
0
 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;
 }
Exemple #8
0
 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();
 }