tags:

views:

275

answers:

3

In my Java code I have function that gets file from the client in http request and converts that in to the file. I have this line there:

byte[] buffer = new byte[8192];

what does 8192 bytes (8 kb) means here?

This is one of the responses that I got, and want to make sure that I understand that code.

+1  A: 

If I had to guess, that is the amount of space you are using to read in the file. Without the rest of the code I can't tell if it is trying to read it all and cram it into 8k or if it is reading it in, 8k at a time, and then dumping it into the file.

Edward Kmett
Check this answer: http://stackoverflow.com/questions/1111130/basic-file-upload-in-gwt/1111606#1111606This is where I have that number
Maksim
Then it is reading in 8k at a time and sending that over to the file before grabbing the next 8k chunk. The justification is that 8k is a reasonable trade off between spinning your wheels calling functions, and wasting space when you get to the end of the file, because and it is reasonably close to the block size on many file systems.
Edward Kmett
How could we answer that when you show us no source code except for the array declaration/definition?
Ed Swangren
+1  A: 

This is the size of the array of bytes, meaning that your buffer will hold 8192 bytes at a time.

Saulo Silva
+4  A: 

That it uses a buffer to read and write 8kB blocks at once. The number is fairly arbitary, but for performance reasons it makes sense to use a multiple of 512 bytes when writing a file, and preferably a multiple of the disks cluster size. 8kB is a reasonable buffer size for most purposes.

Thorarin