anuragraghavan / franca

Automatically exported from code.google.com/p/franca
0 stars 0 forks source link

Remove hackish "helpfile.tmp" in DBusConnector.java #86

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We discovered a problem with the creation of the temporary file "helpfile.tmp" 
in the addStyleSheet routine in DBusConnector. In our case the renamking of the 
helpfile and the end of the routine failed. The following code works without 
creating a temporary and doing a renaming. Please replaced the current 
implementation of addStyleSheet with the code below.

private static void addStyleSheet(File inFile) throws IOException {
     String content = contents(inFile);
     content = content.replaceAll("(<\\?xml version.*\\?>)", "$1\n<?xml-stylesheet type=\"text/xsl\" href=\"introspect.xsl\"?>");
     FileOutputStream fos = new FileOutputStream(inFile);
     PrintWriter out = new PrintWriter(fos);
     out.print(content);
     out.flush();
     out.close();
}       

public static String contents (File file) throws IOException {
    InputStream in = new FileInputStream(file);
    byte[] b  = new byte[(int) file. length()];
    int len = b.length;
    int total = 0;

    while (total < len) {
      int result = in.read(b, total, len - total);
      if (result == -1) {
        break;
      }
      total += result;
    }
    in.close();
    return new String( b );
}

Original issue reported on code.google.com by ChristophKulla@gmail.com on 30 Jan 2014 at 2:20

GoogleCodeExporter commented 9 years ago

Original comment by klaus.birken@gmail.com on 12 Feb 2014 at 8:19

GoogleCodeExporter commented 9 years ago
Thanks for the hint and the ready-to-use contribution!

Original comment by klaus.birken@gmail.com on 12 Feb 2014 at 2:49

GoogleCodeExporter commented 9 years ago
Fixed by commit 049e5c5, will be part of 0.9.0.

Original comment by klaus.birken@gmail.com on 12 Feb 2014 at 2:49

GoogleCodeExporter commented 9 years ago
Merged on master.

Original comment by klaus.birken@gmail.com on 19 Feb 2014 at 10:24