Changeset 3467


Ignore:
Timestamp:
12/12/07 12:22:40 (12 years ago)
Author:
melissa
Message:

Extended Location's ID mapping logic to allow a String ID to be mapped to an instance of IRandomAccess. RandomAccessStream takes this into account, and constructs its underlying IRandomAccess accordingly.

Location:
trunk/loci/formats
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/Location.java

    r3046 r3467  
    9595  } 
    9696 
     97  /** Maps the given id to the given file. */ 
     98  public static void mapFile(String id, IRandomAccess file) { 
     99    if (idMap == null) idMap = new Hashtable(); 
     100    if (id == null) return; 
     101    if (file == null) idMap.remove(id); 
     102    else idMap.put(id, file); 
     103  } 
     104 
    97105  /** 
    98106   * Gets the actual filename on disk for the given id. Typically the id itself 
     
    106114  public static String getMappedId(String id) { 
    107115    if (idMap == null) return id; 
    108     String filename = id == null ? null : (String) idMap.get(id); 
     116    String filename = null; 
     117    if (id != null && (idMap.get(id) instanceof String)) { 
     118      filename = (String) idMap.get(id); 
     119    } 
    109120    return filename == null ? id : filename; 
     121  } 
     122 
     123  /** Gets the file for the given id. */ 
     124  public static IRandomAccess getMappedFile(String id) { 
     125    if (idMap == null) return null; 
     126    IRandomAccess file = null; 
     127    if (id != null && (idMap.get(id) instanceof IRandomAccess)) { 
     128      file = (IRandomAccess) idMap.get(id); 
     129    } 
     130    return file; 
    110131  } 
    111132 
  • trunk/loci/formats/RandomAccessStream.java

    r3085 r3467  
    194194      length = raf.length(); 
    195195    } 
     196    else if (Location.getMappedFile(file) != null) { 
     197      raf = Location.getMappedFile(file); 
     198      length = raf.length(); 
     199    } 
    196200    else throw new IOException("File not found : " + file); 
    197201    this.file = file; 
     
    701705      } 
    702706    } 
    703     else { 
     707    else if (file.startsWith("http")) { 
    704708      raf = new RAUrl(Location.getMappedId(file), "r"); 
     709      length = raf.length(); 
     710    } 
     711    else if (Location.getMappedFile(file) != null) { 
     712      raf = Location.getMappedFile(file); 
    705713      length = raf.length(); 
    706714    } 
Note: See TracChangeset for help on using the changeset viewer.