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.TemporaryStream; 010 011 012 public class TemporaryStreamRequestEntity implements RequestEntity, Entity3 { 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 @Override 026 public long getContentLength() { 027 return ts.length(); 028 } 029 030 @Override 031 public String getContentType() { 032 return contentType; 033 } 034 035 @Override 036 public boolean isRepeatable() { 037 return false; 038 } 039 040 @Override 041 public void writeRequest(OutputStream os) throws IOException { 042 IOUtil.copy(ts.getInputStream(), os,true,false); 043 } 044 @Override 045 public long contentLength() { 046 return getContentLength(); 047 } 048 049 @Override 050 public String contentType() { 051 return getContentType(); 052 } 053 054 }