001 package railo.commons.io.res.type.s3; 002 003 import java.io.IOException; 004 import java.io.InputStream; 005 import java.io.OutputStream; 006 007 import org.apache.commons.httpclient.methods.RequestEntity; 008 009 import railo.loader.util.Util; 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 InputStream is=null; 051 try{ 052 Util.copy(is=ts.getInputStream(), os); 053 } 054 finally{ 055 Util.closeEL(is); 056 } 057 058 } 059 060 }