1 16 package org.outerj.daisy.publisher.clientimpl; 17 18 import org.outerj.daisy.publisher.BlobInfo; 19 import org.outerj.daisy.repository.RepositoryException; 20 import org.apache.commons.httpclient.methods.GetMethod; 21 import org.apache.commons.httpclient.util.DateParser; 22 import org.apache.commons.httpclient.util.DateParseException; 23 24 import java.util.Date ; 25 import java.io.InputStream ; 26 import java.io.IOException ; 27 28 public class BlobInfoImpl implements BlobInfo { 29 private final GetMethod method; 30 private final Date lastModified; 31 private final String mimeType; 32 private final long size; 33 private boolean disposed = false; 34 private static final String DISPOSED_MESSAGE = "This BlobInfo object has been disposed."; 35 36 public BlobInfoImpl(GetMethod method) throws RepositoryException { 37 this.method = method; 38 try { 39 this.lastModified = DateParser.parseDate(method.getResponseHeader("Last-Modified").getValue()); 40 } catch (DateParseException e) { 41 throw new RepositoryException(e); 42 } 43 this.mimeType = method.getResponseHeader("Content-Type").getValue(); 44 this.size = Integer.parseInt(method.getResponseHeader("Content-Length").getValue()); 45 } 46 47 public Date getLastModified() { 48 if (disposed) 49 throw new RuntimeException (DISPOSED_MESSAGE); 50 return lastModified; 51 } 52 53 public String getMimeType() { 54 if (disposed) 55 throw new RuntimeException (DISPOSED_MESSAGE); 56 return mimeType; 57 } 58 59 public long getSize() { 60 if (disposed) 61 throw new RuntimeException (DISPOSED_MESSAGE); 62 return size; 63 } 64 65 public InputStream getInputStream() throws RepositoryException, IOException { 66 if (disposed) 67 throw new RuntimeException (DISPOSED_MESSAGE); 68 return method.getResponseBodyAsStream(); 69 } 70 71 public void dispose() { 72 method.releaseConnection(); 73 this.disposed = true; 74 } 75 } 76 | Popular Tags |