Changeset 6153


Ignore:
Timestamp:
04/20/10 16:25:38 (10 years ago)
Author:
curtis
Message:

Construct JAI ImageIO service only once per JPEG2000Codec instance.

Location:
trunk/components/bio-formats/src/loci/formats/codec
Files:
2 edited

Legend:

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

    r6026 r6153  
    5555public class JPEG2000Codec extends BaseCodec { 
    5656 
    57   // -- Constants -- 
     57  // -- Fields -- 
     58 
     59  private JAIIIOService service; 
    5860 
    5961  // -- Codec API methods -- 
     
    7476    throws FormatException 
    7577  { 
     78    initialize(); 
     79 
    7680    JPEG2000CodecOptions j2kOptions = 
    7781      JPEG2000CodecOptions.getDefaultOptions(options); 
     
    132136      img = AWTImageTools.constructImage(s.length, DataBuffer.TYPE_USHORT, 
    133137        j2kOptions.width, j2kOptions.height, false, true, buffer); 
    134     } 
    135  
    136     JAIIIOService service = null; 
    137     try { 
    138       ServiceFactory factory = new ServiceFactory(); 
    139       service = factory.getInstance(JAIIIOService.class); 
    140     } 
    141     catch (DependencyException de) { 
    142       throw new MissingLibraryException(JAIIIOServiceImpl.NO_J2K_MSG, de); 
    143138    } 
    144139 
     
    167162    throws FormatException, IOException 
    168163  { 
     164    initialize(); 
     165 
    169166    if (options == null) { 
    170167      options = CodecOptions.getDefaultOptions(); 
     
    182179    } 
    183180    in.read(buf); 
    184  
    185     JAIIIOService service = null; 
    186     try { 
    187       ServiceFactory factory = new ServiceFactory(); 
    188       service = factory.getInstance(JAIIIOService.class); 
    189     } 
    190     catch (DependencyException de) { 
    191       throw new MissingLibraryException(JAIIIOServiceImpl.NO_J2K_MSG, de); 
    192     } 
    193181 
    194182    try { 
     
    230218  } 
    231219 
     220  // -- Helper methods -- 
     221 
     222  /** 
     223   * Initializes the JAI ImageIO dependency service. This is called at the 
     224   * beginning of the {@link #compress} and {@link #decompress} methods to 
     225   * avoid having the constructor's method definition contain a checked 
     226   * exception. 
     227   * 
     228   * @throws FormatException If there is an error initializing JAI ImageIO 
     229   *   services. 
     230   */ 
     231  private void initialize() throws FormatException { 
     232    if (service != null) return; 
     233    try { 
     234      ServiceFactory factory = new ServiceFactory(); 
     235      service = factory.getInstance(JAIIIOService.class); 
     236    } 
     237    catch (DependencyException de) { 
     238      throw new MissingLibraryException(JAIIIOServiceImpl.NO_J2K_MSG, de); 
     239    } 
     240  } 
     241 
    232242} 
  • trunk/components/bio-formats/src/loci/formats/codec/LuraWaveCodec.java

    r6026 r6153  
    5252public class LuraWaveCodec extends BaseCodec { 
    5353 
    54   // -- Constants -- 
    55  
    56   // -- Static fields -- 
    57  
    5854  // -- Fields -- 
    5955 
     
    6157 
    6258  // -- Codec API methods -- 
    63  
    64   /** 
    65    * Initializes the LuraWave dependency service. This is called at the 
    66    * beginning of the {@link #decompress()} method to avoid having the 
    67    * constructor's method definition contain a checked exception. 
    68    * @throws FormatException If there is an error initializing LuraWave 
    69    * services. 
    70    */ 
    71   private void initialize() throws FormatException { 
    72     if (service != null) { 
    73       return; 
    74     } 
    75     try { 
    76       ServiceFactory factory = new ServiceFactory(); 
    77       service = factory.getInstance(LuraWaveService.class); 
    78     } 
    79     catch (DependencyException e) { 
    80       throw new MissingLibraryException(LuraWaveServiceImpl.NO_LURAWAVE_MSG, e); 
    81     } 
    82   } 
    8359 
    8460  /* @see Codec#compress(byte[], CodecOptions) */ 
     
    10884  { 
    10985    initialize(); 
    110     BufferedInputStream stream =  
     86 
     87    BufferedInputStream stream = 
    11188      new BufferedInputStream(new ByteArrayInputStream(buf), 4096); 
    11289    try { 
     
    157134  } 
    158135 
     136  // -- Helper methods -- 
     137 
     138  /** 
     139   * Initializes the LuraWave dependency service. This is called at the 
     140   * beginning of the {@link #decompress} method to avoid having the 
     141   * constructor's method definition contain a checked exception. 
     142   * 
     143   * @throws FormatException If there is an error initializing LuraWave 
     144   * services. 
     145   */ 
     146  private void initialize() throws FormatException { 
     147    if (service != null) return; 
     148    try { 
     149      ServiceFactory factory = new ServiceFactory(); 
     150      service = factory.getInstance(LuraWaveService.class); 
     151    } 
     152    catch (DependencyException e) { 
     153      throw new MissingLibraryException(LuraWaveServiceImpl.NO_LURAWAVE_MSG, e); 
     154    } 
     155  } 
     156 
    159157} 
Note: See TracChangeset for help on using the changeset viewer.