Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../../img/srcFileCovDistChart0.png 94% of files have more coverage
39   113   18   7,8
18   95   0,46   5
5     3,6  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  AlarmSound       Line # 15 39 18 0% 0.0
 
No Tests
 
1   
2    package pl.magot.vetch.ancal.reminder;
3   
4   
5    import java.io.File;
6    import java.io.FileNotFoundException;
7    import java.io.FileOutputStream;
8    import java.io.IOException;
9    import java.io.InputStream;
10    import android.content.Context;
11    import android.net.Uri;
12    import android.content.res.AssetManager;
13   
14   
 
15    public class AlarmSound
16    {
17    //fields
18    private Context context = null;
19   
20    //fields
21    private final String strAlarmFileName = "ancalalarm.mp3";
22    private String strFilesPath = "";
23    private File alarmFile = null;
24   
25    //methods
 
26  0 toggle public AlarmSound(Context context)
27    {
28  0 this.context = context;
29  0 strFilesPath = String.format("//data//data//%s//files//", this.context.getPackageName());
30  0 alarmFile = new File(strFilesPath + strAlarmFileName);
31  0 if (!alarmFile.exists())
32  0 copyAlarmSoundToFileSystem();
33    }
34   
 
35  0 toggle private int getStreamFileLength(InputStream stream)
36    {
37  0 if (stream != null)
38    {
39  0 int iSize = 0;
40  0 try
41    {
42  0 while (stream.read() != -1)
43  0 iSize ++;
44  0 return iSize;
45    } catch (IOException e) {
46  0 return -1;
47    }
48    }
49  0 return -1;
50    }
51   
 
52  0 toggle private boolean copyBufferToFile(byte[] buffer, int iSize, String sTargetFileName)
53    {
54  0 if (buffer != null)
55    {
56  0 try
57    {
58  0 FileOutputStream fileOut = context.openFileOutput(sTargetFileName, Context.MODE_WORLD_READABLE);
59  0 if (fileOut != null)
60    {
61  0 fileOut.write(buffer, 0, iSize);
62  0 fileOut.flush();
63  0 fileOut.close();
64  0 return true;
65    }
66    } catch (FileNotFoundException e1) {
67    } catch (IOException e) {
68    }
69    }
70  0 return false;
71    }
72   
 
73  0 toggle private boolean copyAlarmSoundToFileSystem()
74    {
75  0 boolean bResult = false;
76  0 AssetManager assets = context.getAssets();
77  0 if (assets != null)
78    {
79  0 try
80    {
81  0 InputStream stream = assets.open(strAlarmFileName);
82  0 if (stream != null)
83    {
84  0 final int iStreamFileSize = getStreamFileLength(stream);
85  0 if (iStreamFileSize != -1)
86    {
87    //create buffer
88  0 byte[] buffer = new byte[iStreamFileSize];
89    //read file to buffer
90  0 stream.read(buffer, 0, iStreamFileSize);
91    //save data to file
92  0 bResult = copyBufferToFile(buffer, iStreamFileSize, strAlarmFileName);
93    }
94  0 stream.close();
95    }
96    } catch (IOException e) {
97    }
98  0 assets.close();
99    }
100  0 return bResult;
101    }
102   
 
103  0 toggle public Uri getUri()
104    {
105  0 if (alarmFile.exists())
106    {
107  0 return Uri.fromFile(alarmFile);
108    } else {
109  0 return null;
110    }
111    }
112   
113    }