Search code examples
javajarimagejmedical

Know what methods are in .jar files


I know that there is a plugin for ImageJ that handles NIfTI-1 files (http://rsb.info.nih.gov/ij/plugins/nifti.html).

But all its instructions on that page is to use ImageJ as a standalone program, however I am using its API. How can I know what methods are available in this jar file without its source?

I couldn't find the source code either.

For the supported archives in imageJ (such as DICOM) is quite easy :

public class ImageJTest {
    public static void main(){
                        String path = "res/vaca.dcm"; 
            FileInputStream fis;
            ImageView image;
            try {
                fis = new FileInputStream(path);
                DICOM d = new DICOM(fis);
                d.run(path);
                // Stretches the histogram because the pictures were being
                // displayed too dark.
                (new ij.plugin.ContrastEnhancer()).stretchHistogram(d, 0.1);
                Image picture = SwingFXUtils.toFXImage(d.getBufferedImage(),
                        null);
                // Makes the size standard for thumbnails
                image = new ImageView(picture);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
    }
}

How can I load the NIfTI-1 files in imageJ ?


Solution

  • Once you have the class files, which are embedded in the jar file (as @Alvin Thompson pointed out, these are just zip files by a different name), you can use the reflection API to mine the class files to get their methods. A sample follows for one class, cribbed from here:

    Method[] methods = thisClass.getClass().getMethods(); // thisClass is an instance of the class you're working with
    
    for(Method method : methods){
        System.out.println("method = " + method.getName());
    }