Hi, I have to make a log server in java, and one task is to send the data compressed. Now I am sending it line by line in plain text, but I must compress it. The server handle "HTTP like" request. For example, I can get a log sending "GET xxx.log". This will entablish a TCP connection to the server, the server response with a header and the log, and close the connection. The client, reads line by line and analyzes each LOG entry. I tried some ways without success. My main problem is that I don't know where each line ends(in the client size). Any idea?
+1
A:
The thing that would make the most sense is something like this
- Client sends GET foo.log
- Server sends "Size: 15042\n"
- Server sends the compressed log file, whole
- Client parses the Size: header (reading until a newline) and then knows how many bytes to expect
- Client then reads all those bytes from the server (15042 in the example)
- Client decompresses the received data
- Client then processes the log (decompressed you'll find the newlines)
Vinko Vrsalovic
2010-06-16 00:19:26
this does not works for me, because I want to proccess lines as fast as possible (log files can be VERY large)
Pizza
2010-06-16 04:05:29
Then do it in chunks, repeat stepts 3 to 6 in chunks of Size bytes
Vinko Vrsalovic
2010-06-16 06:39:32
A:
You might take a look at the HTTP Range header. The client can request a range of bytes, and the server will return only those bytes. Use GZIP compression.
You could have an action that you call from the client that will provide an index, with byte ranges, prior to requesting part of the log.
There is a lot of overhead with HTTP headers, so you might consider sending 100 lines at a time or more.
Finally, look at chunked transfer encoding, which will allow you to stream the data to the client.
Marcus Adams
2010-06-16 00:36:13
+2
A:
Use a GZIPOutputStream at the server and a GZIPInputStream at the client, with an InputStreamReader around that and a BufferedReader around that. Then just read lines.
EJP
2010-06-16 01:37:39
I tried it, but when I try to readline(), it throws this exception:java.io.EOFException: Unexpected end of ZLIB input stream
Pizza
2010-06-16 04:03:07
Then it might be good if you pasted a reproducing code sample in a new question. Streams are indeed a good way to do it.
Vinko Vrsalovic
2010-06-16 07:08:41