1 51 package org.apache.fop.image.analyser; 52 53 import java.io.BufferedInputStream ; 55 import java.io.IOException ; 56 57 61 public class GIFReader extends AbstractImageReader { 62 protected static final int GIF_SIG_LENGTH = 10; 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 = ((header[0] == 'G') && (header[1] == 'I') 70 && (header[2] == 'F') && (header[3] == '8') 71 && (header[4] == '7' || header[4] == '9') 72 && (header[5] == 'a')); 73 if (supported) { 74 setDimension(); 75 return true; 76 } else 77 return false; 78 } 79 80 public String getMimeType() { 81 return "image/gif"; 82 } 83 84 protected void setDimension() { 85 int byte1 = header[6] & 0xff; 87 int byte2 = header[7] & 0xff; 88 this.width = ((byte2 << 8) | byte1) & 0xffff; 89 90 byte1 = header[8] & 0xff; 91 byte2 = header[9] & 0xff; 92 this.height = ((byte2 << 8) | byte1) & 0xffff; 93 } 94 95 protected void setDefaultHeader() throws IOException { 96 this.header = new byte[GIF_SIG_LENGTH]; 97 try { 98 this.imageStream.mark(GIF_SIG_LENGTH + 1); 99 this.imageStream.read(header); 100 this.imageStream.reset(); 101 } catch (IOException ex) { 102 try { 103 this.imageStream.reset(); 104 } catch (IOException exbis) {} 105 throw ex; 106 } 107 } 108 109 } 110 111 | Popular Tags |