Changeset 2694


Ignore:
Timestamp:
04/27/07 10:38:57 (13 years ago)
Author:
curtis
Message:

Add assertId method for format handlers to verify current file null or not.

Location:
trunk/loci/formats
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/FormatHandler.java

    r2687 r2694  
    8282    StatusListener[] l = getStatusListeners(); 
    8383    for (int i=0; i<l.length; i++) l[i].statusUpdated(e); 
     84  } 
     85 
     86  /** 
     87   * Asserts that the current file is either null, nor not, according to the 
     88   * given flag. If the assertion fails, an IllegalStateException is thrown. 
     89   * @param notNull True iff id should be non-null. 
     90   * @param depth How far back in the stack the calling method is; this name 
     91   *   is reported as part of the exception message, if available. Use zero 
     92   *   to suppress output of the calling method name. 
     93   */ 
     94  protected void assertId(boolean notNull, int depth) { 
     95    String msg = null; 
     96    if (currentId == null && notNull) { 
     97      msg = "Current file should not be null; call setId(String) first"; 
     98    } 
     99    else if (currentId != null && !notNull) { 
     100      msg = "Current file should be null, but is '" + 
     101        currentId + "'; call close() first"; 
     102    } 
     103    if (msg == null) return; 
     104 
     105    StackTraceElement[] ste = new Exception().getStackTrace(); 
     106    String header; 
     107    if (depth > 0 && ste.length > depth) { 
     108      String c = ste[depth].getClassName(); 
     109      if (c.startsWith("loci.formats.")) { 
     110        c = c.substring(c.lastIndexOf(".") + 1); 
     111      } 
     112      header = c + "." + ste[depth].getMethodName() + ": "; 
     113    } 
     114    else header = ""; 
     115    throw new IllegalStateException(header + msg); 
    84116  } 
    85117 
  • trunk/loci/formats/in/BMPReader.java

    r2687 r2694  
    139139  /* @see loci.formats.IFormatReader#openImage(int) */ 
    140140  public BufferedImage openImage(int no) throws FormatException, IOException { 
     141    assertId(true, 1); 
    141142    return ImageTools.makeImage(openBytes(no), core.sizeX[0], core.sizeY[0], 
    142143      core.sizeC[0], false); 
Note: See TracChangeset for help on using the changeset viewer.