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.TemporaryStream;
010    
011    
012    public class TemporaryStreamRequestEntity implements RequestEntity {
013    
014            private final TemporaryStream ts;
015            private final String contentType;
016    
017            public TemporaryStreamRequestEntity(TemporaryStream ts) {
018                    this(ts,"application");
019            }
020            public TemporaryStreamRequestEntity(TemporaryStream ts,String contentType) {
021                    this.ts=ts;
022                    this.contentType=contentType;
023            }
024            
025            /**
026             * @see org.apache.commons.httpclient.methods.RequestEntity#getContentLength()
027             */
028            public long getContentLength() {
029                    return ts.length();
030            }
031    
032            /**
033             * @see org.apache.commons.httpclient.methods.RequestEntity#getContentType()
034             */
035            public String getContentType() {
036                    return contentType;
037            }
038    
039            /**
040             * @see org.apache.commons.httpclient.methods.RequestEntity#isRepeatable()
041             */
042            public boolean isRepeatable() {
043                    return false;
044            }
045    
046            /**
047             * @see org.apache.commons.httpclient.methods.RequestEntity#writeRequest(java.io.OutputStream)
048             */
049            public void writeRequest(OutputStream os) throws IOException {
050                    IOUtil.copy(ts.getInputStream(), os,true,false);
051            }
052    
053    }