• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 1667 for branches/3.0-Beta2/components/common/src/ome/util/PathUtil.java

Show
Ignore:
Timestamp:
06/24/07 14:27:29 (18 months ago)
Author:
jmoore
Message:

Fixing PathUtil to prevent NPEs.

Files:
1 modified

  • branches/3.0-Beta2/components/common/src/ome/util/PathUtil.java (modified) (1 diff)

Legend:

Unmodified
Added
Removed
  • branches/3.0-Beta2/components/common/src/ome/util/PathUtil.java

    r1567 r1667  
    11package ome.util; 
    22 
     3import java.io.File; 
    34import java.io.FileInputStream; 
    45import java.io.IOException; 
    56import java.util.Properties; 
    67 
     8import ome.conditions.InternalException; 
     9 
     10import org.springframework.util.ResourceUtils; 
    711 
    812public class PathUtil { 
    9          
    10         private final String SPRING_FILE_PATH = "components/romio/resources/beanRefContext.xml";  
    11         private final String OMERO_PROPS = "etc/omero.properties"; 
    12         private static PathUtil instance = null; 
    13         private static Properties properties; 
    14          
    15         private PathUtil() { 
    16                 properties = new Properties(); 
    17             try { 
    18                 properties.load(new FileInputStream(OMERO_PROPS)); 
    19             } catch (IOException e) { 
    20                         // TODO - something 
    21                 }                
    22         } 
    23          
    24         public static PathUtil getInstance() { 
    25                 if (instance == null) { 
    26                         return new PathUtil(); 
    27                 } else { 
    28                         return instance; 
    29                 } 
    30         } 
    31          
    32         public String getDataFilePath() { 
    33                 String path = properties.getProperty("omero.data.dir");                          
    34                 return path; 
    35         } 
     13 
     14    private final String SPRING_FILE_PATH = "components/romio/resources/beanRefContext.xml"; 
     15 
     16    private final String OMERO_PROPS = "classpath:omero.properties"; 
     17 
     18    private static PathUtil instance = null; 
     19 
     20    private static Properties properties; 
     21 
     22    private PathUtil() { 
     23        properties = new Properties(); 
     24        File f = null; 
     25        FileInputStream fis = null; 
     26        try { 
     27            f = ResourceUtils.getFile(OMERO_PROPS); 
     28            fis = new FileInputStream(f); 
     29            properties.load(fis); 
     30        } catch (IOException e) { 
     31            throw new InternalException("Could not load omero.properties:"); 
     32        } finally { 
     33            if (fis != null) { 
     34                try { 
     35                    fis.close(); 
     36                } catch (Exception e) { 
     37                    // ok 
     38                } 
     39            } 
     40        } 
     41    } 
     42 
     43    public static PathUtil getInstance() { 
     44        if (instance == null) { 
     45            return new PathUtil(); 
     46        } else { 
     47            return instance; 
     48        } 
     49    } 
     50 
     51    public String getDataFilePath() { 
     52        String path = properties.getProperty("omero.data.dir"); 
     53        return path; 
     54    } 
    3655 
    3756} 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/