1 51 package org.apache.fop.image.analyser; 52 53 import java.io.BufferedInputStream ; 55 import java.io.IOException ; 56 57 61 public class TIFFReader extends AbstractImageReader { 62 protected static final int TIFF_SIG_LENGTH = 8; 63 protected byte[] header; 64 65 public boolean verifySignature(String uri, BufferedInputStream fis) 66 throws IOException { 67 this.imageStream = fis; 68 this.setDefaultHeader(); 69 boolean supported = false; 70 71 if (header[0] == (byte)0x49 72 && header[1] 73 == (byte)0x49) { 75 if (header[2] == 42 && header[3] == 0) 77 supported = true; 78 } 79 80 if (header[0] == (byte)0x4D 81 && header[1] 82 == (byte)0x4D) { 84 if (header[2] == 0 && header[3] == 42) 86 supported = true; 87 } 88 89 if (supported) { 90 setDimension(); 91 return true; 92 } else 93 return false; 94 } 95 96 public String getMimeType() { 97 return "image/tiff"; 98 } 99 100 protected void setDimension() { 101 123 } 124 125 protected void setDefaultHeader() throws IOException { 126 this.header = new byte[TIFF_SIG_LENGTH]; 127 try { 128 this.imageStream.mark(TIFF_SIG_LENGTH + 1); 129 this.imageStream.read(header); 130 this.imageStream.reset(); 131 } catch (IOException ex) { 132 try { 133 this.imageStream.reset(); 134 } catch (IOException exbis) {} 135 throw ex; 136 } 137 } 138 139 } 140 141 | Popular Tags |