Changeset 5897 for branches/cleanup


Ignore:
Timestamp:
02/10/10 15:17:59 (10 years ago)
Author:
melissa
Message:
  • Fixed bug that caused ByteArrayHandles constructed from byte arrays to have length 0.
  • Fixed bug that caused NIOFileHandle to swap byte ordering.
Location:
branches/cleanup/components/common
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/common/src/loci/common/ByteArrayHandle.java

    r5877 r5897  
    6262  public ByteArrayHandle(byte[] bytes) { 
    6363    buffer = ByteBuffer.wrap(bytes); 
    64     buffer.limit(0); 
    6564  } 
    6665 
  • branches/cleanup/components/common/src/loci/common/NIOFileHandle.java

    r5874 r5897  
    465465      bufferStartPosition = offset; 
    466466      long newSize = Math.min(length() - bufferStartPosition, bufferSize); 
     467      if (newSize < size && newSize == bufferSize) newSize = size; 
     468      ByteOrder order = buffer == null ? null : getOrder(); 
    467469      buffer = channel.map(mapMode, bufferStartPosition, newSize); 
     470      if (order != null) setOrder(order); 
    468471    } 
    469472    buffer.position((int) (offset - bufferStartPosition)); 
  • branches/cleanup/components/common/test/loci/common/utests/EndiannessTest.java

    r5836 r5897  
    5656  private static final String MODE = "r"; 
    5757 
    58   private static final int BUFFER_SIZE = 1024; 
     58  private static final int BUFFER_SIZE = 4; 
    5959 
    6060  private IRandomAccess fileHandle; 
     
    7171  public void testLength() throws IOException { 
    7272    assertEquals(8, fileHandle.length()); 
     73  } 
     74 
     75  @Test 
     76  public void testSeekBigEndian() throws IOException { 
     77    fileHandle.seek(6); 
     78    assertEquals(3854, fileHandle.readShort()); 
     79  } 
     80 
     81  @Test 
     82  public void testSeekLittleEndian() throws IOException { 
     83    fileHandle.setOrder(ByteOrder.LITTLE_ENDIAN); 
     84    fileHandle.seek(6); 
     85    assertEquals(3599, fileHandle.readShort()); 
    7386  } 
    7487 
  • branches/cleanup/components/common/test/loci/common/utests/WriteByteArrayTest.java

    r5876 r5897  
    142142    assertEquals(2, fileHandle.readByte()); 
    143143    assertEquals(3, fileHandle.readByte()); 
    144     if (fileHandle.length() > 2 
    145         && (fileHandle.readByte() != 0 && fileHandle.readByte() != 0)) 
    146     { 
     144    if (fileHandle.length() > 2 && fileHandle.readByte() == 4) { 
    147145      fail("Incorrect length or trailing bytes."); 
    148146    } 
  • branches/cleanup/components/common/test/loci/common/utests/WriteByteBufferTest.java

    r5876 r5897  
    149149    assertEquals(2, fileHandle.readByte()); 
    150150    assertEquals(3, fileHandle.readByte()); 
    151     if (fileHandle.length() > 2 
    152         && (fileHandle.readByte() != 0)) 
    153     { 
     151    if (fileHandle.length() > 2 && (fileHandle.readByte() == 4)) { 
    154152      fail("Incorrect length or trailing bytes."); 
    155153    } 
Note: See TracChangeset for help on using the changeset viewer.