Changeset 6921


Ignore:
Timestamp:
09/14/10 06:27:06 (9 years ago)
Author:
callan
Message:

A solution for file handles being left hanging around after close() on OMETiffWriter on the Beta 4.1 series. Due to the work done during 4.2 a simple backport of r6872 was not possible as some of the underlying infrastructure was not closing files at all and the code path is radically different. (See #543)

Location:
branches/4.1/components/bio-formats/src/loci/formats
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/components/bio-formats/src/loci/formats/out/OMETiffWriter.java

    r5615 r6921  
    7777    if (out != null) out.close(); 
    7878    out = null; 
     79    try { 
     80      doClose(); 
     81    } 
     82    finally { 
     83      super.close(); 
     84      seriesMap = null; 
     85      wroteLast = false; 
     86    } 
     87  } 
     88 
     89  /** 
     90   * Performs the actual close operation so that it can be wrapped in a 
     91   * try/finally block to ensure that file handles are released. 
     92   * @throws IOException If there is an error writing to the output file. 
     93   */ 
     94  private void doClose() throws IOException { 
    7995    if (currentId != null) { 
    8096      if (!wroteLast) { 
     
    177193      } 
    178194    } 
    179     super.close(); 
    180     seriesMap = null; 
    181     wroteLast = false; 
    182195  } 
    183196 
  • branches/4.1/components/bio-formats/src/loci/formats/tiff/TiffSaver.java

    r5334 r6921  
    332332   * data in place. 
    333333   */ 
    334   public static void overwriteIFDValue(String file, 
     334  public static void overwriteIFDValue(RandomAccessInputStream raf, String file, 
    335335    int ifd, int tag, Object value) throws FormatException, IOException 
    336336  { 
     
    339339    byte[] header = new byte[4]; 
    340340 
    341     RandomAccessInputStream raf = new RandomAccessInputStream(file); 
    342341    raf.seek(0); 
    343342    raf.readFully(header); 
     
    442441 
    443442        RandomAccessOutputStream out = new RandomAccessOutputStream(file); 
    444  
    445         // overwrite old entry 
    446         out.seek(filePointer - (bigTiff ? 18 : 10)); // jump back 
    447         DataTools.writeShort(out, newType, little); 
    448         if (bigTiff) DataTools.writeLong(out, newCount, little); 
    449         else DataTools.writeInt(out, newCount, little); 
    450         if (bigTiff) DataTools.writeLong(out, newOffset, little); 
    451         else DataTools.writeInt(out, (int) newOffset, little); 
    452         if (extra.length > 0) { 
    453           out.seek(newOffset); 
    454           out.write(extra); 
    455         } 
    456         return; 
     443        try { 
     444          // overwrite old entry 
     445          out.seek(filePointer - (bigTiff ? 18 : 10)); // jump back 
     446          DataTools.writeShort(out, newType, little); 
     447          if (bigTiff) DataTools.writeLong(out, newCount, little); 
     448          else DataTools.writeInt(out, newCount, little); 
     449          if (bigTiff) DataTools.writeLong(out, newOffset, little); 
     450          else DataTools.writeInt(out, (int) newOffset, little); 
     451          if (extra.length > 0) { 
     452            out.seek(newOffset); 
     453            out.write(extra); 
     454          } 
     455          return; 
     456        } 
     457        finally { 
     458          out.close(); 
     459        } 
    457460      } 
    458461    } 
     
    465468    throws FormatException, IOException 
    466469  { 
    467     overwriteIFDValue(id, 0, IFD.IMAGE_DESCRIPTION, value); 
     470    RandomAccessInputStream raf = new RandomAccessInputStream(id); 
     471    try { 
     472      overwriteIFDValue(raf, id, 0, IFD.IMAGE_DESCRIPTION, value); 
     473    } 
     474    finally { 
     475      raf.close(); 
     476    } 
    468477  } 
    469478 
Note: See TracChangeset for help on using the changeset viewer.