Changeset 6060


Ignore:
Timestamp:
03/22/10 19:04:43 (10 years ago)
Author:
melissa
Message:
  • Fixed TIFF offset reading, so that zero offsets are not adjusted.
  • Removed usage of map() from NIOFileHandle, to avoid garbage collection issues.
  • Fixed common classpath to allow tests to run. This will cause scan-deps.pl to complain, see ticket #481.
Location:
trunk/components
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r6026 r6060  
    192192      Number subfile = (Number) ifds.get(i).getIFDValue(IFD.NEW_SUBFILE_TYPE); 
    193193      int subfileType = subfile == null ? 0 : subfile.intValue(); 
    194       if (subfileType != 0) { 
     194      if (subfileType != 0 && ifds.size() > 1) { 
    195195        ifds.remove(i--); 
    196196      } 
     
    882882    } 
    883883    long offset = (previous & ~0xffffffffL) | (in.readInt() & 0xffffffffL); 
    884     if (offset < previous) { 
     884    if (offset < previous && offset != 0) { 
    885885      offset += 0x100000000L; 
    886886    } 
  • trunk/components/common/build.properties

    r6045 r6060  
    1111component.version        = 4.1.1 
    1212component.classpath      = ${lib.dir}/slf4j-api-1.5.10.jar:\ 
     13                           ${lib.dir}/slf4j-log4j12-1.5.10.jar:\ 
     14                           ${lib.dir}/log4j-1.2.15.jar:\ 
    1315                           ${lib.dir}/testng-5.11-jdk15.jar 
    1416component.java-version   = 1.5 
  • trunk/components/common/src/loci/common/NIOFileHandle.java

    r6057 r6060  
    336336    long newPosition = oldPosition + Math.min(n, length()); 
    337337 
    338     buffer(newPosition, n); 
     338    buffer(newPosition, 0); 
    339339    return (int) (position - oldPosition); 
    340340  } 
     
    359359  /* @see IRandomAccess.write(ByteBuffer, int, int) */ 
    360360  public void write(ByteBuffer buf, int off, int len) throws IOException { 
    361     validateLength(len); 
    362     buf.position(off); 
     361    writeSetup(len); 
     362    buf.position(off + len); 
    363363    buf.limit(off + len); 
    364     channel.position(position); 
    365     buffer(position + channel.write(buf), 0); 
     364    buf.position(buf.position() - len); 
     365    position += channel.write(buf, position); 
     366    buffer = null; 
    366367  } 
    367368 
     
    378379  /* @see java.io.DataOutput.writeByte(int) */ 
    379380  public void writeByte(int v) throws IOException { 
    380     validateLength(1); 
    381     buffer(position, 1); 
     381    writeSetup(1); 
    382382    buffer.put((byte) v); 
    383     position += 1; 
     383    doWrite(1); 
    384384  } 
    385385 
     
    391391  /* @see java.io.DataOutput.writeChar(int) */ 
    392392  public void writeChar(int v) throws IOException { 
    393     validateLength(2); 
    394     buffer(position, 2); 
     393    writeSetup(2); 
    395394    buffer.putChar((char) v); 
    396     position += 2; 
     395    doWrite(2); 
    397396  } 
    398397 
     
    404403  /* @see java.io.DataOutput.writeDouble(double) */ 
    405404  public void writeDouble(double v) throws IOException { 
    406     validateLength(8); 
    407     buffer(position, 8); 
     405    writeSetup(8); 
    408406    buffer.putDouble(v); 
    409     position += 8; 
     407    doWrite(8); 
    410408  } 
    411409 
    412410  /* @see java.io.DataOutput.writeFloat(float) */ 
    413411  public void writeFloat(float v) throws IOException { 
    414     validateLength(4); 
    415     buffer(position, 4); 
     412    writeSetup(4); 
    416413    buffer.putFloat(v); 
    417     position += 4; 
     414    doWrite(4); 
    418415  } 
    419416 
    420417  /* @see java.io.DataOutput.writeInt(int) */ 
    421418  public void writeInt(int v) throws IOException { 
    422     validateLength(4); 
    423     buffer(position, 4); 
     419    writeSetup(4); 
    424420    buffer.putInt(v); 
    425     position += 4; 
     421    doWrite(4); 
    426422  } 
    427423 
    428424  /* @see java.io.DataOutput.writeLong(long) */ 
    429425  public void writeLong(long v) throws IOException { 
    430     validateLength(8); 
    431     buffer(position, 8); 
     426    writeSetup(8); 
    432427    buffer.putLong(v); 
    433     position += 8; 
     428    doWrite(8); 
    434429  } 
    435430 
    436431  /* @see java.io.DataOutput.writeShort(int) */ 
    437432  public void writeShort(int v) throws IOException { 
    438     validateLength(2); 
    439     buffer(position, 2); 
     433    writeSetup(2); 
    440434    buffer.putShort((short) v); 
    441     position += 2; 
     435    doWrite(2); 
    442436  } 
    443437 
     
    446440    // NB: number of bytes written is greater than the length of the string 
    447441    int strlen = str.getBytes("UTF-8").length + 2; 
    448     validateLength(strlen); 
    449     buffer(position, strlen); 
     442    writeSetup(strlen); 
    450443    raf.seek(position); 
    451444    raf.writeUTF(str); 
    452445    position += strlen; 
     446    buffer = null; 
    453447  } 
    454448 
     
    464458    position = offset; 
    465459    long newPosition = offset + size; 
    466     if (newPosition < bufferStartPosition 
    467         || newPosition > bufferStartPosition + bufferSize 
    468         || buffer == null) { 
    469       bufferStartPosition = Math.min(offset, length() - 1); 
     460    if (newPosition < bufferStartPosition || 
     461      newPosition > bufferStartPosition + bufferSize || buffer == null) 
     462    { 
     463      bufferStartPosition = offset; 
     464      if (length() > 0 && length() - 1 < bufferStartPosition) { 
     465        bufferStartPosition = length() - 1; 
     466      } 
    470467      long newSize = Math.min(length() - bufferStartPosition, bufferSize); 
    471468      if (newSize < size && newSize == bufferSize) newSize = size; 
     
    475472      offset = bufferStartPosition; 
    476473      ByteOrder byteOrder = buffer == null ? order : getOrder(); 
    477       try { 
    478         buffer = channel.map(mapMode, bufferStartPosition, newSize); 
    479       } catch (IOException e) { 
    480         // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092131 and 
    481         //     http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6417205 
    482         // for an explanation of why the following is necessary 
    483         // This is not a problem with JDK 1.6 and higher but can be a 
    484         // problem with earlier JVMs. 
    485         System.gc(); 
    486         System.runFinalization(); 
    487         buffer = channel.map(mapMode, bufferStartPosition, newSize); 
    488       } 
     474      buffer = ByteBuffer.allocate((int) newSize); 
    489475      if (byteOrder != null) setOrder(byteOrder); 
     476      channel.read(buffer, bufferStartPosition); 
    490477    } 
    491478    buffer.position((int) (offset - bufferStartPosition)); 
    492479  } 
    493480 
     481  private void writeSetup(int length) throws IOException { 
     482    validateLength(length); 
     483    buffer(position, length); 
     484  } 
     485 
     486  private void doWrite(int length) throws IOException { 
     487    buffer.position(buffer.position() - length); 
     488    channel.write(buffer, position); 
     489    position += length; 
     490  } 
     491 
    494492} 
  • trunk/components/common/test/loci/common/utests/WriteCharTest.java

    r6026 r6060  
    8585  @Test 
    8686  public void testSequential() throws IOException { 
     87    fileHandle.seek(0); 
    8788    fileHandle.writeChar('a'); 
    8889    if (checkGrowth) { 
     
    123124  @Test 
    124125  public void testReset() throws IOException { 
     126    fileHandle.seek(0); 
    125127    fileHandle.writeChar('a'); 
    126128    if (checkGrowth) { 
Note: See TracChangeset for help on using the changeset viewer.