package gov.nih.nci.nbia.wadosupport;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Iterator;
import java.io.ByteArrayOutputStream;
import java.io.File;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

import org.dcm4che.imageio.plugins.DcmImageReadParam;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class DCMUtils {
private static boolean scanned =false;
private static ImageReader reader;
private static DcmImageReadParam param;
public static synchronized byte[] getJPGFromFile(File file)
{

	BufferedImage myJpegImage = null;
	if (!scanned)
	{
	   scanned=true;
	   ImageIO.scanForPlugins();
	   Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
	   reader=(ImageReader) iter.next();
	   System.out.println("reader is not has beeb set");
	   param = (DcmImageReadParam) reader.getDefaultReadParam();
	}
	if (reader==null)
	{
		   System.out.println("reader was null");
		   ImageIO.scanForPlugins();
		   Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
		   reader=(ImageReader) iter.next();  
	}
    
	try {
		ImageInputStream iis = ImageIO.createImageInputStream(file);
		reader.setInput(iis, false);
		myJpegImage = reader.read(0, param);   
		iis.close();
	
		if (myJpegImage == null) {
			System.out.println("ERROR: Cannot read DICOM image. BufferedImage is NULL");
			return null;
		}
         
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
		encoder.encode(myJpegImage);
		output.close();
		return output.toByteArray();
    
	} catch(IOException e) {
		System.out.println("ERROR: Cannot read DICOM image");
		e.printStackTrace();
	}
	return null;
}
	    
		public static void main(String[] args) {
	        

	    }

}

@@ -321,16 +321,17 @@
 .dcm4che
+2
 .imageio
@@ -339,18 +339,24 @@
 plugins.
-Dc
+dcm.Dico
 mImageRe
@@ -577,17 +577,19 @@
 static D
-c
+ico
 mImageRe
@@ -940,17 +940,17 @@
  has bee
-b
+n
  set%22);%0D
@@ -964,17 +964,19 @@
 ram = (D
-c
+ico
 mImageRe

use correct version