|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Definitions for the class ReadFile |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.s60tools.analyzetool.engine.statistic; |
|
19 |
|
20 import java.io.BufferedReader; |
|
21 import java.io.FileInputStream; |
|
22 import java.io.FileNotFoundException; |
|
23 import java.io.IOException; |
|
24 import java.io.InputStreamReader; |
|
25 import java.util.AbstractList; |
|
26 |
|
27 import com.nokia.s60tools.analyzetool.engine.ParseAnalyzeData; |
|
28 |
|
29 /** |
|
30 * Reads thru trace file and generates statistic info |
|
31 * @author kihe |
|
32 * |
|
33 */ |
|
34 public class ReadFile { |
|
35 |
|
36 /** Parser */ |
|
37 ParseAnalyzeData parser; |
|
38 |
|
39 /** |
|
40 * Constructor |
|
41 */ |
|
42 public ReadFile() |
|
43 { |
|
44 parser = new ParseAnalyzeData(false, true); |
|
45 } |
|
46 |
|
47 |
|
48 /** |
|
49 * Reads thru file |
|
50 * @param path File location |
|
51 * @return True if no errors occurs when reading file otherwise False |
|
52 */ |
|
53 public boolean readFile(final String path) { |
|
54 // return value |
|
55 boolean retValue = true; |
|
56 |
|
57 // input |
|
58 BufferedReader input = null; |
|
59 FileInputStream fis = null; |
|
60 try { |
|
61 |
|
62 // check that file exists |
|
63 if (path == null || ("").equals(path)) { |
|
64 return false; |
|
65 } |
|
66 java.io.File file = new java.io.File(path); |
|
67 if (!file.exists()) { |
|
68 return false; |
|
69 } |
|
70 |
|
71 // get input |
|
72 fis = new FileInputStream(file); |
|
73 input = new BufferedReader(new InputStreamReader(fis,"UTF-8")); |
|
74 |
|
75 // get first line of data file |
|
76 String line = null; |
|
77 // go thru file |
|
78 while ((line = input.readLine()) != null) { |
|
79 parser.parse(line); |
|
80 } |
|
81 fis.close(); |
|
82 input.close(); |
|
83 } catch (FileNotFoundException ex) { |
|
84 retValue = false; |
|
85 ex.printStackTrace(); |
|
86 } catch (OutOfMemoryError oome){ |
|
87 retValue = true; |
|
88 oome.printStackTrace(); |
|
89 } catch (IOException ex) { |
|
90 retValue = false; |
|
91 ex.printStackTrace(); |
|
92 } finally { |
|
93 try { |
|
94 if (input != null) { |
|
95 input.close(); |
|
96 } |
|
97 } catch (IOException ex) { |
|
98 ex.printStackTrace(); |
|
99 } |
|
100 |
|
101 try { |
|
102 if( fis != null ) { |
|
103 fis.close(); |
|
104 } |
|
105 }catch(Exception e) { |
|
106 e.printStackTrace(); |
|
107 } |
|
108 } |
|
109 return retValue; |
|
110 } |
|
111 |
|
112 /** |
|
113 * Returns statistic |
|
114 * @return Statistic |
|
115 */ |
|
116 public AbstractList<ProcessInfo> getStatistic() |
|
117 { |
|
118 return parser.getStatistic(); |
|
119 } |
|
120 |
|
121 /** |
|
122 * Finish the file reading. |
|
123 */ |
|
124 public void finish() |
|
125 { |
|
126 parser.finish(); |
|
127 |
|
128 } |
|
129 } |