|
1 /* |
|
2 * Copyright (c) 2007-2010 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: |
|
15 * |
|
16 * OST Data Matcher Checker |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.ost; |
|
20 |
|
21 import java.io.FileInputStream; |
|
22 import java.io.IOException; |
|
23 |
|
24 import com.nokia.traceviewer.engine.TraceViewerConst; |
|
25 |
|
26 /** |
|
27 * OST Data Matcher Checker |
|
28 * |
|
29 */ |
|
30 public class OstDataMatcherChecker implements OstConsts, TraceViewerConst { |
|
31 |
|
32 /** |
|
33 * Checks if file format seems to match |
|
34 * |
|
35 * @param filePath |
|
36 * file path |
|
37 * @return true if file format seems to match, false if not |
|
38 */ |
|
39 boolean checkIfFileFormatMatches(String filePath) { |
|
40 boolean matches = false; |
|
41 FileInputStream is = null; |
|
42 try { |
|
43 is = new FileInputStream(filePath); |
|
44 if (is.available() > 0) { |
|
45 byte[] arr = new byte[OST_V05_PROTOCOLID_OFFSET + 1]; |
|
46 is.read(arr); |
|
47 int versionNumber = 0; |
|
48 int msgId = 0; |
|
49 |
|
50 // Get version number and message ID |
|
51 versionNumber |= arr[OST_VERSION_OFFSET] & BYTE_MASK; |
|
52 |
|
53 // Version must be 0.0, 0.1, 0.5 or 1.0 |
|
54 if (versionNumber == OST_V00 || versionNumber == OST_V01) { |
|
55 msgId |= arr[OST_V01_PROTOCOLID_OFFSET] & BYTE_MASK; |
|
56 } else if (versionNumber == OST_V05 || versionNumber == OST_V10) { |
|
57 msgId |= arr[OST_V05_PROTOCOLID_OFFSET] & BYTE_MASK; |
|
58 } |
|
59 |
|
60 // Message ID must be Simple Trace or ASCII |
|
61 if (msgId == OST_SIMPLE_TRACE_ID || msgId == OST_ASCII_TRACE_ID) { |
|
62 matches = true; |
|
63 } |
|
64 } |
|
65 |
|
66 } catch (IOException e) { |
|
67 |
|
68 // Close the stream |
|
69 } finally { |
|
70 if (is != null) { |
|
71 try { |
|
72 is.close(); |
|
73 } catch (IOException e) { |
|
74 } |
|
75 } |
|
76 |
|
77 } |
|
78 |
|
79 return matches; |
|
80 } |
|
81 } |