Changeset 6407


Ignore:
Timestamp:
05/27/10 11:44:20 (9 years ago)
Author:
curtis
Message:

Temporary(?) hack to speed up text file reading.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/in/TextReader.java

    r6397 r6407  
    2424package loci.formats.in; 
    2525 
     26import java.io.BufferedReader; 
     27import java.io.FileReader; 
    2628import java.io.IOException; 
    2729import java.util.ArrayList; 
     
    3032 
    3133import loci.common.DataTools; 
     34import loci.common.IRandomAccess; 
     35import loci.common.Location; 
    3236import loci.common.RandomAccessInputStream; 
    3337import loci.formats.FormatException; 
     
    191195    List<String> lines = new ArrayList<String>(); 
    192196    long time = System.currentTimeMillis(); 
    193     RandomAccessInputStream in = new RandomAccessInputStream(id); 
    194     int no = 0; 
    195     while (true) { 
    196       no++; 
    197       time = checkTime(time, no, in.getFilePointer(), in.length()); 
    198       String line = in.readLine(); 
    199       if (line == null) break; // eof 
    200       lines.add(line); 
    201     } 
    202     in.close(); 
     197    IRandomAccess handle = Location.getMappedFile(id); 
     198    if (handle == null) { 
     199      // HACK: Read using vanilla BufferedReader, since it's faster. 
     200      String mapId = Location.getMappedId(id); 
     201      BufferedReader in = new BufferedReader(new FileReader(mapId)); 
     202      int no = 0; 
     203      while (true) { 
     204        no++; 
     205        time = checkTime(time, no, 0, 0); 
     206        String line = in.readLine(); 
     207        if (line == null) break; // eof 
     208        lines.add(line); 
     209      } 
     210      in.close(); 
     211    } 
     212    else { 
     213      // read data using RandomAccessInputStream (data may not be a file) 
     214      RandomAccessInputStream in = new RandomAccessInputStream(handle); 
     215      int no = 0; 
     216      while (true) { 
     217        no++; 
     218        time = checkTime(time, no, in.getFilePointer(), in.length()); 
     219        String line = in.readLine(); 
     220        if (line == null) break; // eof 
     221        lines.add(line); 
     222      } 
     223      in.close(); 
     224    } 
    203225    return lines; 
    204226  } 
     
    364386    if (t - time > TIME_OFFSET) { 
    365387      // some time has passed; report progress 
    366       int percent = (int) (100 * pos / len); 
    367       LOGGER.info("Reading line " + no + " (" + percent + "%)"); 
     388      if (len > 0) { 
     389        int percent = (int) (100 * pos / len); 
     390        LOGGER.info("Reading line " + no + " (" + percent + "%)"); 
     391      } 
     392      else LOGGER.info("Reading line " + no); 
    368393      time = t; 
    369394    } 
Note: See TracChangeset for help on using the changeset viewer.