Changeset 31573

Show
Ignore:
Timestamp:
05.04.2017 20:16:54 (2 years ago)
Author:
ak19
Message:

Commit ahead of larger changes: Misc.NEWLINE now works sets the NEWLINE constant to be appropriate for the OS and uses the more convenient System property when we're working with Java 7+ or otherwise manually decides based on OS.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/util/Misc.java

    r29576 r31573  
    3535/** contains miscellaneous functions */ 
    3636public class Misc { 
     37 
     38    // Can initialise static final vars on declaration or in static initialisation code block 
     39    // http://stackoverflow.com/questions/2339932/java-can-final-variables-be-initialized-in-static-initialization-block 
     40    // Initialise object member final vars on declaration or in constructors 
     41    public static final String NEWLINE; 
    3742     
     43    // Before Java 7, no System.lineSeparator() or System.getProperty("line.separator") 
     44    // And on local linux, am compiling with JDK 6, so need this. 
     45    // http://stackoverflow.com/questions/207947/how-do-i-get-a-platform-dependent-new-line-character 
     46 
     47    static { 
     48    // http://stackoverflow.com/questions/2591083/getting-java-version-at-runtime 
     49    // https://www.tutorialspoint.com/java/lang/package_getspecificationversion.htm 
     50     
     51    double java_version = Double.parseDouble(System.getProperty("java.specification.version")); 
     52    if(java_version >= 1.7) { // https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html 
     53        NEWLINE = System.getProperty("line.separator"); 
     54    } else { 
     55        NEWLINE = isWindows() ? "\r\n" : "\n"; 
     56    }    
     57    } 
     58 
    3859    public static void printHash(HashMap map) { 
    3960    Set entries = map.entrySet();