Changeset 2078


Ignore:
Timestamp:
01/12/07 13:01:51 (13 years ago)
Author:
melissa
Message:

Tweaked RAUrl and several readers to provide better support for reading over
HTTP (now works for all formats).

Location:
trunk/loci/formats
Files:
1 added
27 edited

Legend:

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

    r2037 r2078  
    283283  public static void main(String[] args) throws FormatException, IOException { 
    284284    File file = args.length < 1 ? 
    285       new File(System.getProperty("user.dir")).listFiles()[0] : 
    286       new File(args[0]); 
     285      new FileWrapper(System.getProperty("user.dir")).listFiles()[0] : 
     286      new FileWrapper(args[0]); 
    287287    System.out.println("File = " + file.getAbsoluteFile()); 
    288288    String pat = FilePattern.findPattern(file); 
     
    294294        System.out.println("Pattern is valid."); 
    295295        String id = fp.getFiles()[0]; 
    296         if (!new File(id).exists()) { 
     296        if (!new FileWrapper(id).exists()) { 
    297297          System.out.println("File '" + id + "' does not exist."); 
    298298        } 
  • trunk/loci/formats/BaseCompressor.java

    r2075 r2078  
    2525package loci.formats; 
    2626 
    27 import java.io.*; 
    2827import java.util.*; 
    2928 
  • trunk/loci/formats/FilePattern.java

    r1912 r2078  
    302302      dir += File.separator; 
    303303    } 
    304     File dirFile = new File(dir.equals("") ? "." : dir); 
     304    File dirFile = new FileWrapper(dir.equals("") ? "." : dir); 
    305305 
    306306    // list files in the given directory 
     
    538538    if (args.length > 0) { 
    539539      // test file pattern detection based on the given file on disk 
    540       File file = new File(args[0]); 
     540      File file = new FileWrapper(args[0]); 
    541541      System.out.println("File = " + file.getAbsoluteFile()); 
    542542      pat = findPattern(file); 
  • trunk/loci/formats/FileStitcher.java

    r2053 r2078  
    197197      else { 
    198198        // id is an unmapped file path; look to similar files on disk 
    199         pattern = FilePattern.findPattern(new File(id)); // id == getMapped(id) 
     199 
     200        // id == getMapped(id) 
     201        pattern = FilePattern.findPattern(new FileWrapper(id)); 
    200202      } 
    201203      if (pattern != null) id = pattern; 
     
    616618    } 
    617619    for (int i=0; i<files.length; i++) { 
    618       if (!new File(getMappedId(files[i])).exists()) { 
     620      if (!new FileWrapper(getMappedId(files[i])).exists()) { 
    619621        throw new FormatException("File #" + i + 
    620622          " (" + files[i] + ") does not exist."); 
  • trunk/loci/formats/FormatReader.java

    r2053 r2078  
    157157   */ 
    158158  protected boolean checkBytes(String name, int maxLen) { 
    159     long len = new File(name).length(); 
    160     byte[] buf = new byte[len < maxLen ? (int) len : maxLen]; 
    161159    try { 
    162       DataInputStream fin = new DataInputStream(new FileInputStream(name)); 
    163       fin.readFully(buf); 
    164       fin.close(); 
     160      RandomAccessStream ras = new RandomAccessStream(name); 
     161      long len = ras.length(); 
     162      byte[] buf = new byte[len < maxLen ? (int) len : maxLen]; 
     163      ras.readFully(buf); 
     164      ras.close(); 
    165165      return isThisType(buf); 
    166166    } 
     
    603603    if (stitch) { 
    604604      reader = new FileStitcher(reader, true); 
    605       String pat = FilePattern.findPattern(new File(map == null ? id : map)); 
     605      String pat =  
     606        FilePattern.findPattern(new FileWrapper(map == null ? id : map)); 
    606607      if (pat != null) id = pat; 
    607608    } 
  • trunk/loci/formats/ImageViewer.java

    r2053 r2078  
    180180    wait(true); 
    181181    try { 
    182       File f = new File(id); 
     182      File f = new FileWrapper(id); 
    183183      id = f.getAbsolutePath(); 
    184184      int num = myReader.getImageCount(id); 
  • trunk/loci/formats/LegacyQTTools.java

    r1615 r2078  
    7878 
    7979    while (st.hasMoreTokens()) { 
    80       File f = new File(st.nextToken(), "QTJava.zip"); 
     80      File f = new FileWrapper(st.nextToken(), "QTJava.zip"); 
    8181      if (f.exists()) { 
    8282        try { 
  • trunk/loci/formats/RAUrl.java

    r2039 r2078  
    5959  private long length; 
    6060 
     61  /** Reset marker */ 
     62  private long mark; 
     63 
    6164  // -- Constructors -- 
    6265 
    6366  public RAUrl(String url, String mode) throws IOException { 
     67    if (!url.startsWith("http")) url = "http://" + url; 
    6468    conn = (HttpURLConnection) (new URL(url)).openConnection(); 
    65     if (mode.equals("r")) is = new DataInputStream(conn.getInputStream()); 
     69    if (mode.equals("r")) { 
     70      is = new DataInputStream(new BufferedInputStream( 
     71        conn.getInputStream(), 65536)); 
     72    } 
    6673    else if (mode.equals("w")) { 
    6774      conn.setDoOutput(true); 
     
    7077    fp = 0; 
    7178    length = conn.getContentLength(); 
     79    if (is != null) is.mark((int) length); 
    7280    this.url = url; 
    7381  } 
     
    95103    while (value == -1 && fp < length()) value = is.read(); 
    96104    if (value != -1) fp++; 
     105    markManager(); 
    97106    return value; 
    98107  } 
     
    100109  /* @see IRandomAccess#read(byte[]) */ 
    101110  public int read(byte[] b) throws IOException { 
    102     int read = is.read(b); 
    103     while (read < b.length && fp < length()) { 
    104       read += read(b, read, b.length - read); 
    105     } 
    106     if (read != -1) fp += read; 
    107     return read; 
     111    return read(b, 0, b.length); 
    108112  } 
    109113 
     
    111115  public int read(byte[] b, int off, int len) throws IOException { 
    112116    int read = is.read(b, off, len); 
    113     while (read < len && fp + read < length()) { 
    114       b[off + read] = (byte) is.read(); 
    115       read++; 
    116     } 
    117117    if (read != -1) fp += read; 
    118     return read; 
     118    if (read == -1) read = 0; 
     119    markManager(); 
     120    while (read < len && fp < length()) { 
     121      int oldRead = read; 
     122      read += read(b, off + read, len - read); 
     123      if (read < oldRead) read = oldRead; 
     124    } 
     125    return read == 0 ? -1 : read; 
    119126  } 
    120127 
    121128  /* @see IRandomAccess#seek(long) */ 
    122129  public void seek(long pos) throws IOException { 
    123     if (pos < fp) { 
    124       close(); 
    125       conn = (HttpURLConnection) (new URL(url)).openConnection(); 
    126       conn.setDoOutput(true); 
    127       if (is != null) is = new DataInputStream(conn.getInputStream()); 
    128       if (os != null) os = new DataOutputStream(conn.getOutputStream()); 
    129       this.url = url; 
    130       fp = 0; 
    131       skipBytes((int) pos); 
    132     } 
    133     else { 
     130    if (pos >= fp) { 
    134131      skipBytes((int) (pos - fp)); 
    135     } 
     132      return; 
     133    } 
     134    else if (pos >= mark) { 
     135      try { 
     136        is.reset(); 
     137        fp = mark; 
     138        skipBytes((int) (pos - fp)); 
     139        return; 
     140      } 
     141      catch (IOException e) { } 
     142    } 
     143   
     144    close(); 
     145    conn = (HttpURLConnection) (new URL(url)).openConnection(); 
     146    conn.setDoOutput(true); 
     147    if (is != null) { 
     148      is = new DataInputStream(new BufferedInputStream( 
     149        conn.getInputStream(), 65536)); 
     150      is.mark((int) length()); 
     151      mark = 0; 
     152    } 
     153    if (os != null) os = new DataOutputStream(conn.getOutputStream()); 
     154    this.url = url; 
     155    fp = 0; 
     156    skipBytes((int) pos); 
    136157  } 
    137158 
     
    228249  /* @see DataInput#skipBytes(int) */ 
    229250  public int skipBytes(int n) throws IOException { 
    230     fp += n; 
    231     return is.skipBytes(n); 
     251    int skipped = 0; 
     252    for (int i=0; i<n; i++) { 
     253      if (read() != -1) skipped++; 
     254      markManager(); 
     255    } 
     256    return skipped; 
    232257  } 
    233258 
     
    304329  } 
    305330 
     331  // -- Helper methods -- 
     332 
     333  private void markManager() throws IOException { 
     334    if (fp >= mark + 65535) { 
     335      mark = fp; 
     336      is.mark((int) length()); 
     337    } 
     338  } 
    306339} 
  • trunk/loci/formats/RandomAccessStream.java

    r2049 r2078  
    9090  public RandomAccessStream(String file) throws IOException { 
    9191    File f = new File(file); 
     92    f = f.getAbsoluteFile(); 
    9293    if (f.exists()) { 
    93       raf = new RAFile(file, "r"); 
     94      raf = new RAFile(f, "r"); 
    9495      dis = new DataInputStream(new BufferedInputStream( 
    9596        new FileInputStream(file), MAX_OVERHEAD)); 
     
    119120  // -- RandomAccessStream API methods -- 
    120121 
     122  /** Return the underlying InputStream */ 
     123  public DataInputStream getInputStream() { return dis; } 
     124 
    121125  /** 
    122126   * Sets the number of bytes by which to extend the stream.  This only applies 
     
    341345 
    342346  public int available() throws IOException { 
    343     return dis.available() + ext; 
     347    return dis != null ? dis.available() + ext :  
     348      (int) (length() - getFilePointer()); 
    344349  } 
    345350 
  • trunk/loci/formats/getting-started.txt

    r1966 r2078  
    127127  It is recommended that you use this for reading binary files. 
    128128 
     129- loci.formats.FileWrapper extends java.io.File to support reading from URLs. 
     130  It is recommended that you use this instead of File.  See the JavaDoc for 
     131  additional information. 
     132 
    129133- loci.formats.DataTools provides a number of methods for converting bytes to 
    130134  shorts, ints, longs, etc.  It also supports reading most primitive types 
  • trunk/loci/formats/in/ICSReader.java

    r2033 r2078  
    218218 
    219219    if (icsId == null) throw new FormatException("No ICS file found."); 
    220     File icsFile = new File(getMappedId(icsId)); 
     220    File icsFile = new FileWrapper(getMappedId(icsId)); 
    221221    if (!icsFile.exists()) throw new FormatException("ICS file not found."); 
    222222 
    223223    // check if we have a v2 ICS file 
    224     RandomAccessFile f = new RandomAccessFile(getMappedId(icsId), "r"); 
     224    RandomAccessStream f = new RandomAccessStream(getMappedId(icsId)); 
    225225    byte[] b = new byte[17]; 
    226226    f.read(b); 
     
    232232    else { 
    233233      if (idsId == null) throw new FormatException("No IDS file found."); 
    234       File idsFile = new File(getMappedId(idsId)); 
     234      File idsFile = new FileWrapper(getMappedId(idsId)); 
    235235      if (!idsFile.exists()) throw new FormatException("IDS file not found."); 
    236236      currentIdsId = idsId; 
     
    242242    icsIn = icsFile; 
    243243 
    244     BufferedReader reader = new BufferedReader(new FileReader(icsIn)); 
    245     String line = reader.readLine(); 
    246     line = reader.readLine(); 
     244    RandomAccessStream reader = new RandomAccessStream(icsIn.getAbsolutePath()); 
    247245    StringTokenizer t; 
    248246    String token; 
     247    b = new byte[(int) reader.length()]; 
     248    reader.read(b); 
     249    String s = new String(b); 
     250    StringTokenizer st = new StringTokenizer(s, "\n"); 
     251    String line = st.nextToken(); 
     252    line = st.nextToken(); 
    249253    while (line != null && !line.trim().equals("end")) { 
    250254      t = new StringTokenizer(line); 
     
    270274        } 
    271275      } 
    272       line = reader.readLine(); 
     276      try { 
     277        line = st.nextToken(); 
     278      } 
     279      catch (NoSuchElementException e) { line = null; } 
    273280    } 
    274281 
     
    336343 
    337344    if (versionTwo) { 
    338       String s = idsIn.readLine(); 
     345      s = idsIn.readLine(); 
    339346      while(!s.trim().equals("end")) s = idsIn.readLine(); 
    340347    } 
  • trunk/loci/formats/in/IPWReader.java

    r2033 r2078  
    207207 
    208208    try { 
    209       r.setVar("fis", new FileInputStream(getMappedId(id))); 
     209      r.setVar("fis", in); 
    210210      r.exec("fs = new POIFSFileSystem(fis)"); 
    211211      r.exec("dir = fs.getRoot()"); 
  • trunk/loci/formats/in/ImageIOReader.java

    r1988 r2078  
    2828import java.io.BufferedInputStream; 
    2929import java.io.DataInputStream; 
    30 import java.io.FileInputStream; 
    3130import java.io.IOException; 
    3231import javax.imageio.ImageIO; 
     
    106105    } 
    107106 
    108     return ImageIO.read(new DataInputStream( 
    109       new BufferedInputStream(new FileInputStream(getMappedId(id)), 4096))); 
     107    return ImageIO.read(new DataInputStream(new BufferedInputStream( 
     108      new RandomAccessStream(getMappedId(id)), 4096))); 
    110109  } 
    111110 
  • trunk/loci/formats/in/ImageJReader.java

    r2033 r2078  
    126126 
    127127    try { 
    128       File file = new File(getMappedId(id)); 
     128      File file = new FileWrapper(getMappedId(id)); 
    129129      r.setVar("dir", file.getParent() + System.getProperty("file.separator")); 
    130130      r.setVar("name", file.getName()); 
  • trunk/loci/formats/in/LegacyPictReader.java

    r1947 r2078  
    8989 
    9090    // read in PICT data 
    91     File file = new File(getMappedId(id)); 
     91    File file = new FileWrapper(getMappedId(id)); 
    9292    int len = (int) (file.length() - 512); 
    9393    byte[] bytes = new byte[len]; 
  • trunk/loci/formats/in/LegacyQTReader.java

    r2033 r2078  
    173173 
    174174      // open movie file 
    175       File file = new File(getMappedId(id)); 
     175      File file = new FileWrapper(getMappedId(id)); 
    176176      r.setVar("path", file.getAbsolutePath()); 
    177177      r.exec("qtf = new QTFile(path)"); 
  • trunk/loci/formats/in/LegacyZVIReader.java

    r2010 r2078  
    2727import java.awt.image.BufferedImage; 
    2828import java.io.IOException; 
    29 import java.io.RandomAccessFile; 
    3029import java.util.HashSet; 
    3130import java.util.Set; 
     
    6867 
    6968  /** Current file. */ 
    70   protected RandomAccessFile in; 
     69  protected RandomAccessStream in; 
    7170 
    7271  /** List of image blocks. */ 
     
    156155    if (debug) debug("initFile(" + id + ")"); 
    157156    super.initFile(id); 
    158     in = new RandomAccessFile(getMappedId(id), "r"); 
     157    in = new RandomAccessStream(getMappedId(id)); 
    159158 
    160159    // Highly questionable decoding strategy: 
     
    445444   * starting from the given file position. 
    446445   */ 
    447   private static long findBlock(RandomAccessFile in, byte[] block, long start) 
     446  private static long findBlock(RandomAccessStream in, byte[] block, long start) 
    448447    throws IOException 
    449448  { 
     
    537536 
    538537    /** Reads in this block's image data from the given file. */ 
    539     public BufferedImage readImage(RandomAccessFile raf) 
     538    public BufferedImage readImage(RandomAccessStream raf) 
    540539      throws IOException, FormatException 
    541540    { 
  • trunk/loci/formats/in/LeicaReader.java

    r2039 r2078  
    377377        int tempImages = DataTools.bytesToInt(tempData, 0, 4, littleEndian); 
    378378        String dirPrefix = 
    379           new File(getMappedId(id)).getAbsoluteFile().getParent(); 
     379          new FileWrapper(getMappedId(id)).getAbsoluteFile().getParent(); 
    380380        dirPrefix = dirPrefix == null ? "" : (dirPrefix + File.separator); 
    381381        for (int j=0; j<tempImages; j++) { 
     
    384384            new String(tempData, 20 + 2*(j*nameLength), 2*nameLength))); 
    385385          // test to make sure the path is valid 
    386           File test = new File((String) f.get(f.size() - 1)); 
     386          File test = new FileWrapper((String) f.get(f.size() - 1)); 
    387387          if (!test.exists()) { 
    388388            // TIFF files were renamed 
    389389 
    390             File[] dirListing = (new File(dirPrefix)).listFiles(); 
     390            File[] dirListing = (new FileWrapper(dirPrefix)).listFiles(); 
    391391 
    392392            int pos = 0; 
     
    456456    // just checking the filename isn't enough to differentiate between 
    457457    // Leica and regular TIFF; open the file and check more thoroughly 
    458     File file = new File(getMappedId(name)); 
     458    File file = new FileWrapper(getMappedId(name)); 
    459459    if (!file.exists()) return false; 
    460460    long len = file.length(); 
     
    478478      lei = dir + lei; 
    479479 
    480       File check = new File(getMappedId(lei)); 
     480      File check = new FileWrapper(getMappedId(lei)); 
    481481      return check.exists(); 
    482482    } 
  • trunk/loci/formats/in/MDBParser.java

    r2039 r2078  
    8989      // print out all data 
    9090 
    91       r.setVar("filename", filename); 
    92       r.exec("dbfile = new File(filename)"); 
     91      r.setVar("dbfile", new FileWrapper(filename)); 
    9392      r.exec("mdb = file.mdb_open(dbfile)"); 
    9493      r.exec("Catalog.mdb_read_catalog(mdb, Constants.MDB_TABLE)"); 
  • trunk/loci/formats/in/ND2Reader.java

    r2049 r2078  
    5656      r = new ReflectedUniverse(); 
    5757      r.exec("import jj2000.j2k.fileformat.reader.FileFormatReader"); 
    58       r.exec("import jj2000.j2k.io.BEBufferedRandomAccessFile"); 
     58      r.exec("import jj2000.j2k.util.ISRandomAccessIO"); 
    5959    } 
    6060    catch (Throwable exc) { 
     61      /* debug */ exc.printStackTrace(); 
    6162      noJAI = true; 
    6263    } 
     
    218219 
    219220    try { 
    220       r.setVar("id", getMappedId(id)); 
    221       r.setVar("read", "r"); 
    222       r.exec("in = new BEBufferedRandomAccessFile(id, read)"); 
     221      r.setVar("id", in); 
     222      r.exec("in = new ISRandomAccessIO(id)"); 
    223223      r.setVar("j2kMetadata", null); 
    224224      r.exec("ff = new FileFormatReader(in, j2kMetadata)"); 
     
    232232    numImages = offsets.length; 
    233233 
     234    /* debug */ System.out.println("num images : " + numImages); 
     235 
    234236    pixelType[0] = FormatReader.UINT8; 
    235237 
     
    241243    int off = -1; 
    242244    byte[] buf = new byte[2048]; 
    243     while (!found) { 
     245    while (!found && in.getFilePointer() < in.length()) { 
    244246      int read = 0; 
    245247      if (in.getFilePointer() == offsets[offsets.length - 1]) { 
  • trunk/loci/formats/in/OIFReader.java

    r2039 r2078  
    2828import java.awt.image.ColorModel; 
    2929import java.io.*; 
    30 import java.util.Hashtable; 
    31 import java.util.Vector; 
     30import java.util.*; 
    3231import loci.formats.*; 
    3332 
     
    4241 
    4342  /** Current file. */ 
    44   protected BufferedReader reader; 
     43  protected RandomAccessStream reader; 
    4544 
    4645  /** Number of image planes in the file. */ 
     
    231230    String oifFile = id; 
    232231    if (!id.toLowerCase().endsWith("oif")) { 
    233       File current = new File(getMappedId(id)); 
     232      File current = new FileWrapper(getMappedId(id)); 
    234233      current = current.getAbsoluteFile(); 
    235234      String parent = current.getParent(); 
    236       File tmp = new File(parent); 
     235      File tmp = new FileWrapper(parent); 
    237236      parent = tmp.getParent(); 
    238237 
     
    244243      oifFile = parent + oifFile.substring(0, oifFile.indexOf("_")) + ".oif"; 
    245244 
    246       tmp = new File(getMappedId(oifFile)); 
     245      tmp = new FileWrapper(getMappedId(oifFile)); 
    247246      if (!tmp.exists()) { 
    248247        oifFile = oifFile.substring(0, oifFile.lastIndexOf(".")) + ".OIF"; 
    249         tmp = new File(getMappedId(oifFile)); 
     248        tmp = new FileWrapper(getMappedId(oifFile)); 
    250249        if (!tmp.exists()) throw new FormatException("OIF file not found"); 
    251250        currentId = oifFile; 
     
    255254 
    256255    super.initFile(oifFile); 
    257     reader = new BufferedReader(new FileReader(getMappedId(oifFile))); 
     256    reader = new RandomAccessStream(getMappedId(oifFile)); 
    258257 
    259258    int slash = oifFile.lastIndexOf(File.separator); 
     
    262261    // parse each key/value pair (one per line) 
    263262 
     263    byte[] b = new byte[(int) reader.length()]; 
     264    reader.read(b); 
     265    String s = new String(b); 
     266    StringTokenizer st = new StringTokenizer(s, "\r\n"); 
     267 
    264268    Hashtable filenames = new Hashtable(); 
    265     String line = reader.readLine(); 
    266269    String prefix = ""; 
    267     while (line != null) { 
    268       line = DataTools.stripString(line); 
     270    while (st.hasMoreTokens()) { 
     271      String line = DataTools.stripString(st.nextToken().trim()); 
    269272      if (!line.startsWith("[") && (line.indexOf("=") > 0)) { 
    270273        String key = line.substring(0, line.indexOf("=")).trim(); 
     
    282285        prefix = line + " - "; 
    283286      } 
    284       line = reader.readLine(); 
    285287    } 
    286288 
     
    295297 
    296298    String tiffPath; 
    297     BufferedReader ptyReader; 
     299    RandomAccessStream ptyReader; 
    298300    for (int i=0; i<numImages; i++) { 
    299301      String file = (String) filenames.get(new Integer(i)); 
     
    304306      tiffPath = file.substring(0, file.lastIndexOf(File.separator)); 
    305307 
    306       ptyReader = new BufferedReader(new FileReader(getMappedId(file))); 
    307       line = ptyReader.readLine(); 
    308       while (line != null) { 
     308      ptyReader = new RandomAccessStream(getMappedId(file)); 
     309      b = new byte[(int) ptyReader.length()]; 
     310      ptyReader.read(b); 
     311      s = new String(b); 
     312      st = new StringTokenizer(s, "\n"); 
     313 
     314      while (st.hasMoreTokens()) { 
     315        String line = st.nextToken().trim(); 
    309316        if (!line.startsWith("[") && (line.indexOf("=") > 0)) { 
    310317          String key = line.substring(0, line.indexOf("=") - 1).trim(); 
     
    318325          metadata.put("Image " + i + " : " + key, value); 
    319326        } 
    320         line = ptyReader.readLine(); 
    321327      } 
    322328      ptyReader.close(); 
     
    380386    if (validBits.length == 2) validBits = new int[3]; 
    381387    for (int i=0; i<validBits.length; i++) { 
    382       String s = 
    383         (String) metadata.get("[Reference Image Parameter] - ValidBitCounts"); 
     388      s = (String) metadata.get("[Reference Image Parameter] - ValidBitCounts"); 
    384389      if (s != null) { 
    385390        validBits[i] = Integer.parseInt(s); 
  • trunk/loci/formats/in/OMEXMLReader.java

    r2066 r2078  
    329329    OMENode ome = null; 
    330330    try { 
    331       ome = new OMENode(new File(getMappedId(id))); 
     331      File f = new File(getMappedId(id)); 
     332      f = f.getAbsoluteFile(); 
     333      if (f.exists()) ome = new OMENode(f); 
     334      else { 
     335        byte[] b = new byte[(int) in.length()]; 
     336        long oldFp = in.getFilePointer(); 
     337        in.seek(0); 
     338        in.read(b); 
     339        in.seek(oldFp); 
     340        ome = new OMENode(new String(b)); 
     341        b = null; 
     342      } 
    332343    } 
    333344    catch (Exception exc) { 
  • trunk/loci/formats/in/PerkinElmerReader.java

    r2033 r2078  
    171171 
    172172    // get the working directory 
    173     File tempFile = new File(getMappedId(id)); 
     173    File tempFile = new FileWrapper(getMappedId(id)); 
    174174    File workingDir = tempFile.getParentFile(); 
    175     if (workingDir == null) workingDir = new File("."); 
     175    if (workingDir == null) workingDir = new FileWrapper("."); 
    176176    String workingDirPath = workingDir.getPath() + File.separator; 
    177177    String[] ls = workingDir.list(); 
     
    342342 
    343343    numImages = files.length; 
    344     BufferedReader read; 
    345     char[] data; 
     344    RandomAccessStream read; 
     345    byte[] data; 
    346346    StringTokenizer t; 
    347347 
     
    355355 
    356356    if (timPos != -1) { 
    357       tempFile = new File(workingDir, ls[timPos]); 
     357      tempFile = new FileWrapper(workingDir, ls[timPos]); 
    358358      allFiles.add(tempFile.getAbsolutePath()); 
    359       read = new BufferedReader(new FileReader(tempFile)); 
    360       data = new char[(int) tempFile.length()]; 
     359      read = new RandomAccessStream(tempFile.getAbsolutePath()); 
     360      data = new byte[(int) tempFile.length()]; 
    361361      read.read(data); 
    362362      t = new StringTokenizer(new String(data)); 
     
    388388 
    389389    if (csvPos != -1) { 
    390       tempFile = new File(workingDir, ls[csvPos]); 
     390      tempFile = new FileWrapper(workingDir, ls[csvPos]); 
    391391      allFiles.add(tempFile.getAbsolutePath()); 
    392       read = new BufferedReader(new FileReader(tempFile)); 
    393       data = new char[(int) tempFile.length()]; 
     392      read = new RandomAccessStream(tempFile.getAbsolutePath()); 
     393      data = new byte[(int) tempFile.length()]; 
    394394      read.read(data); 
    395395      t = new StringTokenizer(new String(data)); 
     
    417417    } 
    418418    else if (zpoPos != -1) { 
    419       tempFile = new File(workingDir, ls[zpoPos]); 
     419      tempFile = new FileWrapper(workingDir, ls[zpoPos]); 
    420420      allFiles.add(tempFile.getAbsolutePath()); 
    421       read = new BufferedReader(new FileReader(tempFile)); 
    422       data = new char[(int) tempFile.length()]; 
     421      read = new RandomAccessStream(tempFile.getAbsolutePath()); 
     422      data = new byte[(int) tempFile.length()]; 
    423423      read.read(data); 
    424424      t = new StringTokenizer(new String(data)); 
     
    434434 
    435435    if (htmPos != -1) { 
    436       tempFile = new File(workingDir, ls[htmPos]); 
     436      tempFile = new FileWrapper(workingDir, ls[htmPos]); 
    437437      allFiles.add(tempFile.getAbsolutePath()); 
    438       read = new BufferedReader(new FileReader(tempFile)); 
    439       data = new char[(int) tempFile.length()]; 
     438      read = new RandomAccessStream(tempFile.getAbsolutePath()); 
     439      data = new byte[(int) tempFile.length()]; 
    440440      read.read(data); 
    441441 
  • trunk/loci/formats/in/PrairieReader.java

    r2039 r2078  
    7979 
    8080    // check if there is an XML file in the same directory 
    81     File f = new File(name); 
     81    File f = new FileWrapper(name); 
    8282    f = f.getAbsoluteFile(); 
    8383    File parent = f.getParentFile(); 
     
    8989    }; 
    9090    File[] listing = parent.listFiles(ff); 
    91     boolean xml = listing.length > 0; 
     91    boolean xml = listing != null && listing.length > 0; 
    9292 
    9393    // just checking the filename isn't enough to differentiate between 
     
    263263              el = el.substring(el.indexOf("\"", eq + 2) + 1).trim(); 
    264264              if (prefix.equals("File") && key.equals("filename")) { 
    265                 f.add(value); 
     265                File current = new FileWrapper(getMappedId(id)); 
     266                current = current.getAbsoluteFile(); 
     267                f.add(current.getParent() + "/" + value); 
    266268              } 
    267269            } 
     
    324326 
    325327      if (!readXML || !readCFG) { 
    326         File file = new File(id); 
     328        File file = new FileWrapper(id); 
    327329        file = file.getAbsoluteFile(); 
    328330        File parent = file.getParentFile(); 
     
    341343 
    342344      String tiffFile = getMappedId(id); 
    343       File f = new File(tiffFile); 
     345      File f = new FileWrapper(tiffFile); 
    344346      f = f.getAbsoluteFile(); 
    345347      File parent = f.getParentFile(); 
  • trunk/loci/formats/in/QTReader.java

    r2010 r2078  
    616616      else base = id; 
    617617 
    618       File f = new File(getMappedId(base + ".qtr")); 
     618      File f = new FileWrapper(getMappedId(base + ".qtr")); 
    619619      if (f.exists()) { 
    620620        in = new RandomAccessStream(f.getAbsolutePath()); 
     
    626626      } 
    627627      else { 
    628         f = new File(getMappedId(base.substring(0, 
     628        f = new FileWrapper(getMappedId(base.substring(0, 
    629629          base.lastIndexOf(File.separator) + 1) + "._" + 
    630630          base.substring(base.lastIndexOf(File.separator) + 1))); 
     
    637637        } 
    638638        else { 
    639           f = new File(getMappedId(base + "/rsrc")); 
     639          f = new FileWrapper(getMappedId(base + "/rsrc")); 
    640640          if (f.exists()) { 
    641641            in = new RandomAccessStream(f.getAbsolutePath()); 
  • trunk/loci/formats/in/ZeissLSMReader.java

    r2052 r2078  
    685685 
    686686    File dir = 
    687       new File(getMappedId(currentId)).getAbsoluteFile().getParentFile(); 
     687      new FileWrapper(getMappedId(currentId)).getAbsoluteFile().getParentFile(); 
    688688    String[] dirList = dir.list(); 
    689689 
  • trunk/loci/formats/test/ReaderTest.java

    r2041 r2078  
    326326      } 
    327327    } 
    328     String absFile = new File(file).getAbsolutePath(); 
     328    String absFile = new FileWrapper(file).getAbsolutePath(); 
    329329    for (int i=0; i<badFiles.size(); i++) { 
    330330      String bad = (String) badFiles.elementAt(i); 
     
    336336  /** Recursively generates a list of files to test. */ 
    337337  public static void getFiles(String root, Vector files) { 
    338     File f = new File(root); 
     338    File f = new FileWrapper(root); 
    339339    String[] subs = f.list(); 
    340340    if (subs == null) { 
     
    350350        continue; 
    351351      } 
    352       File file = new File(subs[i]); 
     352      File file = new FileWrapper(subs[i]); 
    353353      if (file.isDirectory()) getFiles(subs[i], files); 
    354354      else { 
     
    401401    while (files.size() > 0) { 
    402402      String id = (String) files.elementAt(0); 
    403       String pattern = FilePattern.findPattern(new File(id)); 
     403      String pattern = FilePattern.findPattern(new FileWrapper(id)); 
    404404      if (pattern == null) pattern = id; 
    405405      System.out.println("Testing " + pattern); 
Note: See TracChangeset for help on using the changeset viewer.