sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/engine/statistic/ReadFile.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.s60tools.analyzetool.engine.statistic; |
18 package com.nokia.s60tools.analyzetool.engine.statistic; |
19 |
19 |
20 import java.io.BufferedReader; |
20 import java.io.BufferedReader; |
|
21 import java.io.File; |
21 import java.io.FileInputStream; |
22 import java.io.FileInputStream; |
22 import java.io.FileNotFoundException; |
23 import java.io.FileNotFoundException; |
|
24 import java.io.FileReader; |
23 import java.io.IOException; |
25 import java.io.IOException; |
24 import java.io.InputStreamReader; |
26 import java.io.InputStreamReader; |
25 import java.util.AbstractList; |
27 import java.util.AbstractList; |
26 |
28 |
27 import com.nokia.s60tools.analyzetool.engine.ParseAnalyzeData; |
29 import com.nokia.s60tools.analyzetool.engine.ParseAnalyzeData; |
32 * |
34 * |
33 */ |
35 */ |
34 public class ReadFile { |
36 public class ReadFile { |
35 |
37 |
36 /** Parser */ |
38 /** Parser */ |
37 ParseAnalyzeData parser; |
39 private ParseAnalyzeData parser; |
38 |
40 |
39 /** |
41 /** |
40 * Constructor |
42 * Constructor |
41 */ |
43 */ |
42 public ReadFile() |
44 public ReadFile() |
43 { |
45 { |
44 parser = new ParseAnalyzeData(false, true); |
|
45 } |
46 } |
46 |
47 |
47 |
48 |
48 /** |
49 /** |
49 * Reads thru file |
50 * Reads thru file |
69 } |
70 } |
70 |
71 |
71 // get input |
72 // get input |
72 fis = new FileInputStream(file); |
73 fis = new FileInputStream(file); |
73 input = new BufferedReader(new InputStreamReader(fis,"UTF-8")); |
74 input = new BufferedReader(new InputStreamReader(fis,"UTF-8")); |
|
75 int linebreakSize = lineBreakSize(file); //important to determine file position for deferred callstack reading |
74 |
76 |
75 // get first line of data file |
77 // get first line of data file |
|
78 parser = new ParseAnalyzeData(false, true, true, linebreakSize); |
76 String line = null; |
79 String line = null; |
77 // go thru file |
80 // go thru file |
78 while ((line = input.readLine()) != null) { |
81 while ((line = input.readLine()) != null) { |
79 parser.parse(line); |
82 parser.parse(line); |
80 } |
83 } |
124 public void finish() |
127 public void finish() |
125 { |
128 { |
126 parser.finish(); |
129 parser.finish(); |
127 |
130 |
128 } |
131 } |
|
132 |
|
133 /** |
|
134 * Returns true if callstack reading from file is done |
|
135 * on demand; false if callstacks are made available during parsing |
|
136 * phase. |
|
137 * @return true for deferred callstack reading |
|
138 */ |
|
139 public boolean hasDeferredCallstacks(){ |
|
140 return parser.hasDeferredCallstacks(); |
|
141 } |
|
142 |
|
143 /** |
|
144 * Determines the size of line breaks in the given file. File produced on the device-side |
|
145 * should have while Windows files have. |
|
146 * @param aFile the file to check |
|
147 * @return 1 or 2 for size of line break, or 0 if it cannot be determined |
|
148 */ |
|
149 private static int lineBreakSize(File aFile){ |
|
150 int ret = 0; |
|
151 try { |
|
152 BufferedReader br = new BufferedReader(new FileReader( aFile.getPath() )); |
|
153 |
|
154 int ch; |
|
155 int cnt = 0; |
|
156 while ((ch = br.read()) >=0){ |
|
157 cnt ++; |
|
158 if (ch == '\r'){ |
|
159 ret ++; |
|
160 } else if (ch == '\n'){ |
|
161 ret ++; |
|
162 break; |
|
163 } |
|
164 } |
|
165 |
|
166 } catch (IOException e) { |
|
167 // do nothing, a return value of 0 will indicate some problem |
|
168 } |
|
169 return ret; |
|
170 } |
|
171 |
129 } |
172 } |