3

We tried following ways in server side,

It takes to write around 55 Secs for 2.5 MB file content from MS-Amazon server to Java Client Code, Android Client code and IOS client code

Server Sample code 1

servletOutputStream = response.getOutputStream(); servletOutputStream.write(fileData); servletOutputStream.flush(); servletOutputStream.close(); 

Server Sample code 2

BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream); bufferedOutputStream.write(fileData); bufferedOutputStream.flush(); bufferedOutputStream.close();` 

Client side reader code

inputStream = httpConnection.getInputStream(); .... int nRead; byte[] data = new byte[1024]; while ((nRead = inputStream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); buffer.close(); 

Please share your ideas to improve download speed

Thanks in advance

1 Answer 1

2

Adding the BufferedOutputStream won't make any difference. By default a servlet output stream is actually a ByteArrayOutputStream because the servlet container has to see the entire response before it writes any headers, so it can write a Content-Length header. This adds latency, but not 5 seconds worth. You can get around whatever latency it does add by using fixed-length or chunked response encoding. See the Servlet API for details. However I think you have a larger problem that you need to solve first, possibly a network or DNS or clock skew problem.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.