Coverage Report - org.mule.tools.visualizer.util.DOTtoMAP
 
Classes in this File Line Coverage Branch Coverage Complexity
DOTtoMAP
52%
16/31
33%
2/6
1.833
 
 1  
 /*
 2  
  * $Id: DOTtoMAP.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.tools.visualizer.util;
 12  
 
 13  
 import org.mule.tools.visualizer.config.GraphEnvironment;
 14  
 
 15  
 import java.io.IOException;
 16  
 import java.io.InputStream;
 17  
 import java.io.OutputStream;
 18  
 
 19  
 public class DOTtoMAP
 20  
 {
 21  
 
 22  
     private static final int BUFFER_SIZE = 32768;
 23  4
     private GraphEnvironment env = null;
 24  
 
 25  
     DOTtoMAP(GraphEnvironment env)
 26  4
     {
 27  4
         this.env = env;
 28  4
     }
 29  
 
 30  
     public static void transform(String dotExeFileName,
 31  
                                  String dotFileName,
 32  
                                  String outFormat,
 33  
                                  OutputStream out,
 34  
                                  GraphEnvironment env) throws IOException
 35  
     {
 36  0
         (new DOTtoMAP(env)).innerTransform(dotExeFileName, dotFileName, outFormat, out);
 37  0
     }
 38  
 
 39  
     public static void transform(String dotExeFileName,
 40  
                                  String dotFileName,
 41  
                                  String outFileName,
 42  
                                  GraphEnvironment env) throws IOException
 43  
     {
 44  4
         (new DOTtoMAP(env)).innerTransform(dotExeFileName, dotFileName, outFileName);
 45  4
     }
 46  
 
 47  
     private String getFormatForFile(String outFileName)
 48  
     {
 49  4
         int idx = outFileName.lastIndexOf(".");
 50  4
         if (idx == -1 || idx == outFileName.length() - 1)
 51  
         {
 52  0
             throw new IllegalArgumentException("Can't determine file name extention for file name "
 53  
                             + outFileName);
 54  
         }
 55  
         else
 56  
         {
 57  4
             return outFileName.substring(idx + 1);
 58  
         }
 59  
     }
 60  
 
 61  
     private void innerTransform(String dotExeFileName, String dotFileName, String outFormat, OutputStream out)
 62  
         throws IOException
 63  
     {
 64  0
         String exeCmd = dotExeFileName + " -T" + outFormat + " " + dotFileName;
 65  0
         Process p = Runtime.getRuntime().exec(exeCmd);
 66  0
         InputStream is = p.getInputStream();
 67  0
         byte buf[] = new byte[BUFFER_SIZE];
 68  
         do
 69  
         {
 70  0
             int len = is.read(buf);
 71  0
             if (len > 0)
 72  
             {
 73  0
                 out.write(buf, 0, len);
 74  
             }
 75  
             else
 76  
             {
 77  0
                 is.close();
 78  0
                 return;
 79  
             }
 80  
         }
 81  0
         while (true);
 82  
     }
 83  
 
 84  
     private void innerTransform(String dotExeFileName, String dotFileName, String outFileName)
 85  
         throws IOException
 86  
     {
 87  4
         String exeCmd = dotExeFileName + " -T" + getFormatForFile(outFileName) + " " + dotFileName + " -o "
 88  
                         + outFileName;
 89  4
         env.log(exeCmd);
 90  4
         Process p = Runtime.getRuntime().exec(exeCmd);
 91  
         try
 92  
         {
 93  4
             int i = p.waitFor();
 94  4
             env.log("result code from process is: " + i);
 95  
         }
 96  0
         catch (Exception ie)
 97  
         {
 98  0
             env.logError("Warning: failed to wait for native process to exit...", ie);
 99  4
         }
 100  4
     }
 101  
 }