Changeset 4919


Ignore:
Timestamp:
03/16/09 11:34:22 (11 years ago)
Author:
melissa
Message:
  • Changed TiffTools.overwriteIFDValue to accept a String filename instead of a RandomAccessFile.
  • Updated loci.ome.editor.MetadataPane to use TiffTools.overwriteComment(String, String) instead of TiffTools.overwriteIFDValue.
  • Updated ReadWriteInMemory utility to take advantage of the loci.common.RABytes fixes in r4917.

Reading from/writing to files in memory should work now. Closes #354.

Location:
trunk
Files:
3 edited

Legend:

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

    r4914 r4919  
    16451645   * data in place. 
    16461646   */ 
    1647   public static void overwriteIFDValue(RandomAccessFile raf, 
     1647  public static void overwriteIFDValue(String file, 
    16481648    int ifd, int tag, Object value) throws FormatException, IOException 
    16491649  { 
     
    16511651      value + ")"); 
    16521652    byte[] header = new byte[4]; 
     1653 
     1654    RandomAccessStream raf = new RandomAccessStream(file); 
    16531655    raf.seek(0); 
    16541656    raf.readFully(header); 
     
    17441746        } 
    17451747 
     1748        long filePointer = raf.getFilePointer(); 
     1749        raf.close(); 
     1750 
     1751        RandomAccessOutputStream out = new RandomAccessOutputStream(file); 
     1752 
    17461753        // overwrite old entry 
    1747         raf.seek(raf.getFilePointer() - (bigTiff ? 18 : 10)); // jump back 
    1748         DataTools.writeShort(raf, newType, little); 
    1749         if (bigTiff) DataTools.writeLong(raf, newCount, little); 
    1750         else DataTools.writeInt(raf, newCount, little); 
    1751         if (bigTiff) DataTools.writeLong(raf, newOffset, little); 
    1752         else DataTools.writeInt(raf, (int) newOffset, little); 
     1754        out.seek(filePointer - (bigTiff ? 18 : 10)); // jump back 
     1755        DataTools.writeShort(out, newType, little); 
     1756        if (bigTiff) DataTools.writeLong(out, newCount, little); 
     1757        else DataTools.writeInt(out, newCount, little); 
     1758        if (bigTiff) DataTools.writeLong(out, newOffset, little); 
     1759        else DataTools.writeInt(out, (int) newOffset, little); 
    17531760        if (extra.length > 0) { 
    1754           raf.seek(newOffset); 
    1755           raf.write(extra); 
    1756         } 
    1757         if (terminate) raf.setLength(raf.getFilePointer()); 
     1761          out.seek(newOffset); 
     1762          out.write(extra); 
     1763        } 
    17581764        return; 
    17591765      } 
     
    17671773    throws FormatException, IOException 
    17681774  { 
    1769     RandomAccessFile raf = new RandomAccessFile(id, "rw"); 
    1770     overwriteIFDValue(raf, 0, TiffTools.IMAGE_DESCRIPTION, value); 
    1771     raf.close(); 
     1775    overwriteIFDValue(id, 0, TiffTools.IMAGE_DESCRIPTION, value); 
    17721776  } 
    17731777 
  • trunk/components/legacy/ome-editor/src/loci/ome/editor/MetadataPane.java

    r4550 r4919  
    344344        if (originalTIFF.equals(file)) { 
    345345          //just rewrite image description of original file. 
    346           RandomAccessFile raf = new RandomAccessFile(file, "rw"); 
    347346          xml = addTiffData(xml, file); 
    348           TiffTools.overwriteIFDValue(raf, 0, TiffTools.IMAGE_DESCRIPTION, xml); 
    349           raf.close(); 
     347          TiffTools.overwriteComment(file.getAbsolutePath(), xml); 
    350348        } 
    351349        else { 
  • trunk/utils/ReadWriteInMemory.java

    r4788 r4919  
    6464    /* 
    6565    // map output id string to output byte array 
    66     String outId = "outBytes.ome.tif"; 
    67     byte[] outBytes = new byte[10000000]; // TODO: how to decide this size? 
    68     Location.mapFile(outId, new RABytes(outBytes)); 
     66    String outId = fileName + ".ome.tif"; 
     67    RABytes outputFile = new RABytes(); 
     68    Location.mapFile(outId, outputFile); 
    6969 
    7070    // write data to byte array using ImageWriter 
     
    9292    System.out.println(); 
    9393 
     94    byte[] outBytes = outputFile.getBytes(); 
     95    outputFile.close(); 
     96 
    9497    // flush output byte array to disk 
    9598    System.out.println(); 
Note: See TracChangeset for help on using the changeset viewer.