More resources closes.
authorAlexander Kurtakov <akurtako@redhat.com>
Fri, 6 Apr 2012 09:01:01 +0000 (12:01 +0300)
committerAlexander Kurtakov <akurtako@redhat.com>
Fri, 6 Apr 2012 09:01:01 +0000 (12:01 +0300)
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AttributeTree.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java

index 71baedee45cc93b377c05d68a866632cdd07534d..d28e771a44729e4ad62c2ae5e782a38650519f2b 100644 (file)
@@ -135,7 +135,7 @@ final class AttributeTree {
      * @return The total number of bytes written.
      */
     int writeSelf(File file, long pos) {
-        RandomAccessFile raf;
+        RandomAccessFile raf = null;
         int total = 0;
         byte[] curByteArray;
 
@@ -179,6 +179,13 @@ final class AttributeTree {
             raf.close();
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+               if (raf != null) {
+                       try {
+                                       raf.close();
+                               } catch (IOException e) {
+                               }
+               }
         }
         return total;
     }
index 90a721618307d9cfc19b4e18fc2523ae21d3f1fc..57f72582b9f9c048f49b735f7c4aada880efec3e 100644 (file)
@@ -61,8 +61,9 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> {
         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
@@ -90,14 +91,22 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> {
         } 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
@@ -114,20 +123,35 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> {
         } 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
index 697726b227be351d84406baa47f623973b4a7772..efc619947f65a4bce3931ab6f5ebf26e49542c0a 100644 (file)
@@ -106,8 +106,9 @@ public class CustomXmlTrace extends TmfTrace<CustomXmlEvent> {
 \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
@@ -124,20 +125,35 @@ public class CustomXmlTrace extends TmfTrace<CustomXmlEvent> {
         } 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
This page took 0.043225 seconds and 5 git commands to generate.