Changeset 2069


Ignore:
Timestamp:
01/11/07 08:57:18 (13 years ago)
Author:
nor
Message:

Style fixes, bug fixes (thanks Curtis!)

File:
1 edited

Legend:

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

    r2056 r2069  
    5050 
    5151  /** 
    52    *  Default constructor. 
     52   * Default constructor. 
    5353   */ 
    5454  public BitBuffer(byte[] byteBuffer) { 
     
    6565   */ 
    6666  public void skipBits(long bits) { 
    67     // TODO: Consider whether negative bits should be allowed as a "rewind" 
    6867    if(bits < 0) { 
    6968      throw new IllegalArgumentException("Bits to skip may not be negative"); 
    7069    } 
    71     long skipBytes = bits / 8; 
    72     int skipBits = (int) bits % 8; 
    73     // If we would overflow the currentByte value, well, we're larger than 
    74     // the array anyway, so... 
    75     if(skipBytes + currentByte > Integer.MAX_VALUE) { 
     70 
     71    // handles skipping past eof 
     72    if((long) eofByte * 8 < (long) currentByte * 8 + currentBit + bits) { 
    7673      eofFlag = true; 
    77     } 
    78     currentByte = (int) (skipBytes + currentByte); 
     74      currentByte = eofByte; 
     75      currentBit = 0; 
     76      return; 
     77    } 
     78 
     79    int skipBytes = (int) (bits / 8); 
     80    int skipBits = (int) (bits % 8); 
     81    currentByte += skipBytes; 
    7982    currentBit += skipBits; 
    80     if(currentBit > 8) { 
     83    if(currentBit >= 8) { 
    8184      currentByte++; 
    8285      currentBit -= 8; 
    83     } 
    84     if(currentByte >= eofByte) { 
    85       eofFlag = true; 
    8686    } 
    8787  } 
     
    195195        if(readint != nums[i]) { 
    196196          System.out.println("Error at #" + i + ": " + readint + " received, " + 
    197                              nums[i] + " expected."); 
     197            nums[i] + " expected."); 
    198198        } 
    199199      } 
Note: See TracChangeset for help on using the changeset viewer.