001    package railo.commons.net.http.httpclient3.entity;
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, Entity3 {
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            @Override
039            public long contentLength() {
040                    return getContentLength();
041            }
042    
043            @Override
044            public String contentType() {
045                    return getContentType();
046            }  
047        
048    }