tmf: Switch tmf.ui to Java 7 + fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / callstack / FunctionNameMapper.java
CommitLineData
5da83da5
AM
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.ui.views.callstack;
14
15import java.io.BufferedReader;
16import java.io.File;
17import java.io.FileNotFoundException;
18import java.io.FileReader;
19import java.io.IOException;
20import java.util.Collections;
21import java.util.HashMap;
22import java.util.Map;
23
24import org.eclipse.jdt.annotation.Nullable;
25
26/**
27 * Class containing the different methods to import an address->name mapping.
28 *
29 * @author Alexandre Montplaisir
30 */
31class FunctionNameMapper {
32
33 public static @Nullable Map<String, String> mapFromNmTextFile(File mappingFile) {
507b1336 34 Map<String, String> map = new HashMap<>();
5da83da5 35
507b1336
AM
36 try (FileReader fr = new FileReader(mappingFile);
37 BufferedReader reader = new BufferedReader(fr);) {
5da83da5
AM
38 for (String line = reader.readLine(); line != null; line = reader.readLine()) {
39 String[] elems = line.split(" "); //$NON-NLS-1$
40 /* Only lines with 3 elements contain addresses */
41 if (elems.length == 3) {
42 /* Strip the leading zeroes from the address */
43 String address = elems[0].replaceFirst("^0+(?!$)", ""); //$NON-NLS-1$ //$NON-NLS-2$;
44 String name = elems[elems.length - 1];
45 map.put(address, name);
46 }
47 }
507b1336
AM
48 } catch (FileNotFoundException e) {
49 return null;
5da83da5
AM
50 } catch (IOException e) {
51 /* Stop reading the file at this point */
5da83da5
AM
52 }
53
54 if (map.isEmpty()) {
55 return null;
56 }
57 return Collections.unmodifiableMap(map);
58 }
59
60}
This page took 0.03262 seconds and 5 git commands to generate.