Mark M. |
how can I help you today?
|
Suleyman |
Hi Mark! How are you doing?
|
Suleyman |
I'm very good, thank you :)
|
Suleyman |
I have a question which concerns Java more than Android, and it may be a stupid question but I'll try :)
|
Suleyman |
In my application I'm using ACTION_GET_CONTENT intent to retrieve an image from the system, which I then want to copy to my app's public directory. So I'm getting an InputStream using a ContentResolver in onActivityResult from the Intent. My problem is with copying the file, the standard way using Java I/O is to loop through the bytes and write them to the output stream, but for that a byte array needs to be defined and I'm not sure about the size of it. My question is, is it the optimal way?
|
Mark M. |
the standard "copy from stream to stream in byte[] chunks" is fairly typical
|
Mark M. |
I tend to use an 8K byte[] (byte[8192])
|
Mark M. |
but, you might want to do some profiling and see if you get better results with other values, bearing in mind that you don't want to go too large on the buffer
|
Suleyman |
Ok, got it, I'll test different buffer sizes, and is it worth performing it on a separate thread?
|
Mark M. |
well, it certainly should be done on a background thread -- do not do I/O on the main application thread
|
Mark M. |
whether this is a thread that you are also using for other purposes, or some dedicated thread for this copy operation, is up to you
|
Suleyman |
yeah, you are right, it makes sense.
|
Suleyman |
You cleared up everything once again for me :) thanks a lot for your help Mark!
|