if (NULL_LOCATION.equals(location) || !new File(getPath()).isFile()) {\r
return context;\r
}\r
+ BufferedRandomAccessFile raFile = null; \r
try {\r
- BufferedRandomAccessFile raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
+ raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
if (location != null && location.getLocation() instanceof Long) {\r
raFile.seek((Long)location.getLocation());\r
}\r
} catch (IOException e) {\r
e.printStackTrace();\r
return context;\r
+ } finally {\r
+ if (raFile != null) {\r
+ try {\r
+ raFile.close();\r
+ } catch (IOException e) {\r
+ }\r
+ }\r
}\r
\r
}\r
\r
@Override\r
public TmfContext seekLocation(double ratio) {\r
+ BufferedRandomAccessFile raFile = null; \r
try {\r
- BufferedRandomAccessFile raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
+ raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
long pos = (long) (ratio * raFile.length());\r
while (pos > 0) {\r
raFile.seek(pos - 1);\r
} catch (IOException e) {\r
e.printStackTrace();\r
return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
+ } finally {\r
+ if (raFile != null) {\r
+ try {\r
+ raFile.close();\r
+ } catch (IOException e) {\r
+ }\r
+ }\r
}\r
}\r
\r
@Override\r
public double getLocationRatio(ITmfLocation<?> location) {\r
+ BufferedRandomAccessFile raFile = null; \r
try {\r
if (location.getLocation() instanceof Long) {\r
- BufferedRandomAccessFile raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
+ raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
return (double) ((Long) location.getLocation()) / raFile.length();\r
}\r
} catch (FileNotFoundException e) {\r
e.printStackTrace();\r
} catch (IOException e) {\r
e.printStackTrace();\r
+ } finally {\r
+ if (raFile != null) {\r
+ try {\r
+ raFile.close();\r
+ } catch (IOException e) {\r
+ }\r
+ }\r
}\r
return 0;\r
}\r
\r
@Override\r
public TmfContext seekLocation(double ratio) {\r
+ BufferedRandomAccessFile raFile = null; \r
try {\r
- BufferedRandomAccessFile raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
+ raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
long pos = (long) (ratio * raFile.length());\r
while (pos > 0) {\r
raFile.seek(pos - 1);\r
} catch (IOException e) {\r
e.printStackTrace();\r
return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
+ } finally {\r
+ if (raFile != null) {\r
+ try {\r
+ raFile.close();\r
+ } catch (IOException e) {\r
+ }\r
+ }\r
}\r
}\r
\r
@Override\r
public double getLocationRatio(ITmfLocation<?> location) {\r
+ RandomAccessFile raFile = null; \r
try {\r
if (location.getLocation() instanceof Long) {\r
- RandomAccessFile raFile = new RandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
+ raFile = new RandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
return (double) ((Long) location.getLocation()) / raFile.length();\r
}\r
} catch (FileNotFoundException e) {\r
e.printStackTrace();\r
} catch (IOException e) {\r
e.printStackTrace();\r
+ } finally {\r
+ if (raFile != null) {\r
+ try {\r
+ raFile.close();\r
+ } catch (IOException e) {\r
+ }\r
+ }\r
}\r
return 0;\r
}\r