API Example - Showing Header Information for a UNC Image

This example shows you how to create a simple programme to write UNC image header information to standard output. To try out the programme, save the following text to a file called ImageHeader.java. You need to make sure that the following files from the Jim installation folder are in your classpath:

For programs that use other parts of the A.P.I., you may also need to put these files from the Jim installation folder in your classpath: Then compile the program with the javac command:

javac ImageHeader.java

Note: you must use javac version 17.
This will create a file called ImageHeader.class. To run the programme, type:

java ImageHeader image

where image is the name of an the UNC from which to find the header information.

<--Java code Starts Here -->

import java.io.IOException;

import com.xinapse.image.ReadableImage;
import com.xinapse.image.ImageUtils;
import com.xinapse.image.InvalidImageException;

public class ImageHeader {

  /**
     Java application to write the image header information for one or more images.
     to System.out.
  */
  public static void main(String argv[]) {

    int nImages = argv.length;
    if (nImages == 0) {
      System.err.println("Usage: java ImageHeader image-name [image-name ...]");
      System.exit(-1);
    }

    for (int i = 0; i < nImages; i++) {
      String imageName = argv[i];
      try {
        ReadableImage image = ImageUtils.getReadableImage(imageName);
        System.out.print(image.toString());
        image.close();
      }
      catch (InvalidImageException iiE) {
        System.err.println("Error reading image " + imageName + ": " + iiE.getMessage());
      }
      catch (IOException ioE) {
        System.err.println("Error closing image " + imageName + ": " + ioE.getMessage());
      }
    }
    System.exit(0);
  }
}
Jim Home