001 package railo.commons.net; 002 003 import java.io.IOException; 004 import java.io.OutputStream; 005 006 import org.apache.commons.httpclient.methods.RequestEntity; 007 008 import railo.commons.io.IOUtil; 009 import railo.commons.io.res.Resource; 010 011 /** 012 * A RequestEntity that represents a Resource. 013 */ 014 public class ResourceRequestEntity implements RequestEntity { 015 016 final Resource res; 017 final String contentType; 018 019 public ResourceRequestEntity(final Resource res, final String contentType) { 020 this.res = res; 021 this.contentType = contentType; 022 } 023 public long getContentLength() { 024 return this.res.length(); 025 } 026 027 public String getContentType() { 028 return this.contentType; 029 } 030 031 public boolean isRepeatable() { 032 return true; 033 } 034 035 public void writeRequest(final OutputStream out) throws IOException { 036 IOUtil.copy(res.getInputStream(), out,true,false); 037 } 038 039 }