01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.http;
04:
05: import java.io.*;
06: import fitnesse.util.StreamReader;
07:
08: public class InputStreamResponse extends Response {
09: private StreamReader reader;
10:
11: private int contentSize = 0;
12:
13: public void readyToSend(ResponseSender sender) throws Exception {
14: addStandardHeaders();
15: sender.send(makeHttpHeaders().getBytes());
16: while (!reader.isEof())
17: sender.send(reader.readBytes(1000));
18: reader.close();
19: sender.close();
20: }
21:
22: protected void addSpecificHeaders() {
23: addHeader("Content-Length", getContentSize() + "");
24: }
25:
26: public int getContentSize() {
27: return contentSize;
28: }
29:
30: public void setBody(InputStream input, int size) {
31: reader = new StreamReader(input);
32: contentSize = size;
33: }
34:
35: public void setBody(File file) throws Exception {
36: FileInputStream input = new FileInputStream(file);
37: int size = (int) file.length();
38: setBody(input, size);
39: }
40: }
|