0

What I need to do is basically reading a file which is continously growing, but in every interval I just want to read the new that was appended to the file.

I found a lot of ways to do this with a file on my filesystem, but all these require that I download the file before I can do the magic using the RandomAccessFile-Object.

Is there a way to do this with an online-file like http://myurl.com/123.txt? So that I just stream the data added in the last 2 minutes?

Thanks a lot! noise

2
  • This file, is it hosted in a server you own? Commented Oct 20, 2013 at 10:55
  • no. i have no influence on the server or the file. I just know the link. Commented Oct 20, 2013 at 10:59

1 Answer 1

1

If the server supports it, you can use the Range header to request bytes from a given offset. Do this repeatedly to poll the file for new bytes.

Pseudocode:

long offset = 0;
while (true) {
    request.setHeader("Range: bytes=" + offset + "-");
    request.send();
    request.readResponse();
    offset += theNumberOfBytesRead;
    Thread.sleep(someRespectfulAmountOfTime);
}

See this question for details about how the server is likely to respond if it does or doesn't have more bytes available.

To get "data added in the last 2 minutes", you have to keep track of what offset was two minutes ago.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.