Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

8192 bytes when creating file

Tags:

java

bytearray

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.

like image 352
Maksim Avatar asked Jul 10 '09 19:07

Maksim


3 Answers

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.

like image 133
Thorarin Avatar answered Nov 13 '22 09:11

Thorarin


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

like image 23
Saulo Silva Avatar answered Nov 13 '22 08:11

Saulo Silva


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.

like image 1
Edward Kmett Avatar answered Nov 13 '22 09:11

Edward Kmett