How to break bigger chunk into smaller ones to fit into max chunk?

314 views Asked by At

My server is sending me chunked encoded data and I am able to get the chunked response in my client. The problem I am facing is that some chunks are too big, ca 10 MB. I am getting an exception as I have set max chunk size to 2M.

Is there any way to break this bigger chunk into smaller ones?

2

There are 2 answers

0
expert On

Hmm. Not sure what version of Spray you're using but starting from version 1.1 there is incoming-auto-chunking-threshold-size setting (details here). Here is example of service that supports chunked upload.

There are still number of limitations at the moment. You could read relevant discussion in open ticket.

0
Divyang Shah On

you can devide big chunk in smaller chunks by using RandomAccessFile. I had same problem. I resolved it using RandomAccessFile.

you can do it following way.

byte[] bytes;
String filePath = "path";
RandomAccessFile file1 = new RandomAccessFile(filePath, "r");

      file1.seek(0);
      bytes = new byte[(int)file1.length()/3];
      file1.read(bytes);
      file1.close();
      String str = new String(bytes, "UTF-8");