Skip to main content

Parsing multiple http requests from an InputStream

No replies
Joined: 2007-11-14


I have created a http proxy in Java/Groovy that copies each request/response to separate files and presents the data to the user, similar to tcpmon.

It is working fine as long as the clients closes the connection between the requests.

How can I re-write this code to handle multiple requests without the connection being closed in between?
public void run() {
byte[] block = new byte[BLOCKSIZE];
boolean done = false;
def contentFile = new File(fileNameFullPath)
FileOutputStream fos = new FileOutputStream(contentFile);
while(!done) {
try {
int size =;
println "size: "+size
if(size >0) {
fos.write(block,0,size); // how can I create a new file here for multiple http requests, without the stream being closed between the requests?
if(size == -1) {
done = true;
} catch (IOException e) {
done = true;