Office Hours — Today, June 21

Tuesday, June 19

Jun 21
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Suleyman
has entered the room
Mark M.
hello, Suleyman!
how can I help you today?
Suleyman
Hi Mark! How are you doing?
Mark M.
OK, and you?
Suleyman
I'm very good, thank you :)
I have a question which concerns Java more than Android, and it may be a stupid question but I'll try :)
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?
7:30 PM
Mark M.
the standard "copy from stream to stream in byte[] chunks" is fairly typical
I tend to use an 8K byte[] (byte[8192])
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
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.
You cleared up everything once again for me :) thanks a lot for your help Mark!
Mark M.
you're welcome!
Suleyman
Have a great day :)
Mark M.
you too!
7:50 PM
Suleyman
has left the room
8:25 PM
Mark M.
turned off guest access

Tuesday, June 19

 

Office Hours

People in this transcript

  • Mark Murphy
  • Suleyman