1 6 7 package org.jboss.media.format.image.iio; 8 9 import java.io.IOException ; 10 import java.io.InputStream ; 11 import java.rmi.RemoteException ; 12 13 import javax.emb.MediaException; 14 import javax.emb.MediaHeader; 15 import javax.imageio.ImageReader ; 16 import javax.imageio.metadata.IIOMetadata ; 17 import javax.imageio.stream.FileCacheImageInputStream ; 18 import javax.imageio.stream.ImageInputStream ; 19 20 import org.jboss.media.format.EmbeddedMediaFormat; 21 22 30 public abstract class IIOMediaFormat extends EmbeddedMediaFormat 31 { 32 protected ImageReader imageReader; 33 34 39 public IIOMediaFormat(ImageReader imageReader) 40 { 41 super(); 42 this.imageReader = imageReader; 43 } 44 45 48 public abstract MediaHeader extractHeader(InputStream content) 49 throws MediaException; 50 51 54 public String getDefaultMimeType() 55 56 { 57 try 58 { 59 return "image/" + imageReader.getFormatName(); 61 } catch (IOException e) 62 { 63 return null; 65 } 66 } 67 68 71 public boolean isStreamingDesirable() 72 { 73 return false; 74 } 75 76 protected IIOMetadata extractImageMetadata(InputStream content) 77 throws MediaException 78 { 79 ImageInputStream imageInputStream = null; 80 81 try 82 { 83 imageInputStream = new FileCacheImageInputStream (content, null); 84 85 imageReader.setInput(imageInputStream); 86 IIOMetadata imageMetadata = imageReader.getImageMetadata(0); 87 88 return imageMetadata; 89 } catch (RemoteException re) 90 { 91 throw new RuntimeException (re.getMessage()); 92 } catch (IOException ioe) 93 { 94 throw new MediaException(ioe.getMessage()); 95 } finally 96 { 97 try 98 { 99 imageInputStream.close(); 100 content.close(); 101 } catch (IOException ignore) 102 { 103 } 104 } 105 } 106 } | Popular Tags |