Office Hours — Today, November 18

Yesterday, November 17

Mark M.
has entered the room
Mark M.
turned on guest access
Nov 18
7:50 PM
Susheel
has entered the room
Susheel
Hi Mark
Mark M.
hello, Susheel!
(I *so* wish this chat would chime when somebody joins...)
how can I help you today?
Susheel
haha...
So I have two questions...
Mark M.
go right ahead
7:55 PM
Susheel
First, I created a screenshot of my rooted android device and saved the file to my flash drive using the mount path. Normally when I plug the usb to a laptop to check for the png file I find it there. But today I found the file and when I tried to open it, it says png is empty...
This was a one off instance and when I transferred a new png it came properly...
Mark M.
how are you saving the file for the screenshot?
Susheel
I want to be able to check if the png is empty programatically before unplugging my usb from the android device...is there a way to check if a png file is 'empty'? Can we use file size to determine if the file is 'emty'?
bitmap
Mark M.
to try to save it more reliably, call getFD().sync() on your FileOutputStream, after flush() and before close()
to see if the file is empty, try length() on the File object
Susheel
Right, what do you think could be causing this kind of issue? Do you think it could be a memory issue?
Mark M.
well, if the getFD().sync() helps, the problem is that the Linux filesystem is doing write caching
sync() in Java does an fsync() in the POSIX API, a blocking call until the OS has committed all bytes to disk
Susheel
ok
Mark M.
IOW, it's reminiscent of yanking out the thumb drive in a desktop OS, before it has a chance to write everything
that's why you do some sort of "eject" operation as a user, to tell the OS to get all the bytes written ASAP, please
8:00 PM
Mark M.
sync() does the same thing, on a per-file basis, from within the app
I pretty much don't write any files in Java myself without using sync()
Susheel
So is there a callback method or something like that to see when all bytes have been transferred?
Mark M.
no, sync() blocks until the bytes have been saved
and since you're already doing your disk I/O on a background thread (right? RIGHT?!?), you just block a bit longer
Susheel
I am using Asynctask for disk I/O operations
Mark M.
so, in doInBackground(), when you're doing your disk I/O, just call getFD().sync() on the FileOutputStream, between the flush() and close() calls
the only real headache is if you're not using FileOutputStream
Susheel
I am using fileoutputstream
Mark M.
well, that's easy enough, then :-)
Susheel
So does that mean that onpostexecuted I can confirm that the bytes have been transferred?
Mark M.
by definition, if you call sync() in doInBackground(), by the time onPostExecute() is called, the bytes will have been written
again, sync() is a blocking call
Susheel
Sorry the reason I asked you this question is because I guess I do not understand properly what a blocking call means...
Mark M.
it means that control will not continue to the next Java statement until the work done by the call completes
Susheel
oh perfect!
8:05 PM
Susheel
makes sense now :)
8:10 PM
Mark M.
if you have another question, go right ahead
Susheel
I do, I am framing my question
View paste
I am receiving json response for my rest call to an api and one of the json objects 
values(raw value) is a url for an image like this:

"https:\/\/s3-us-west-2.xxxxxx.com\/xxxxx-xxxxx-xxxx-production\/default\/4_yyyyyy_yyyyyyy.jpg"

Now, my nexus device is able to parse this url properly and give me a legit url without the extra characters(forwards slashes and such) just like a chrome rest client is able to. However, my lg device running api 18 is not able to recognize the json response.
Mark M.
yeah, you'll probably need to fix those up
8:15 PM
Susheel
Right...I am using volley's jsonobjectrequest method to get the response. I am not able to even log the json response on my nexus device...
sorry I meant LG device
Mark M.
I would not expect that to be tied to the backslashes, though
Susheel
is there a way to decipher the proper original url?
oh
Mark M.
I don't use Volley, but from the standpoint of JSON parsing, that's just a string
it could be "snicklefritz" for all the JSON parser cares
now, when you try to *use* that value, *then* you may run into problems due to the backslashes
Susheel
Right, I am trying to use logcat statements and it does not show up
Mark M.
what does "it does not show up" mean?
Susheel
I don't see the log statement in the logcat...as if the logcat line never existed in my code...
Mark M.
where is this log statement?
Susheel
in my response callback method...
Mark M.
:: shrug ::
perhaps there's some way to tell Volley to do more logging
Susheel
btw the same logcat works on my nexus phone...and I am able to view the complete response in string format
Mark M.
or, perhaps you have your filters set too tight, and Volley is logging something at INFO or VERBOSE that might help
8:20 PM
Susheel
just not on my lg phone which runs on api level 18
Mark M.
or, if you're using Android Studio, LogCat works poorly on days whose names end in "y"
Susheel
Hahahahaha!!!!!!
You know you have a great sense of humour :)
Mark M.
I try
Susheel
I could tell when I started reading the book
Mark M.
getting back to your problem, I don't use Volley, so I don't have much really to offer you
Susheel
Is there a reason you don't use volley?
Mark M.
it's not really supported by Google
Susheel
I thought it was!
Mark M.
they pretty much threw the bits over the wall
it's not part of the Android SDK
Susheel
true
Mark M.
you're relying upon a bunch of other volunteers for packaging and stuff
personally, I try to stick to libraries where I have clearer support channels, like an issue tracker
so, I'll use the Square stack (OkHttp, Retrofit, Picasso)
Susheel
like retrofit?
cool
Well thanks for the knowledge
Mark M.
happy to be useful!
Susheel
have a good night Mark
Mark M.
you too!
Susheel
thanks
8:25 PM
Susheel
has left the room
8:30 PM
Mark M.
turned off guest access

Yesterday, November 17

 

Office Hours

People in this transcript

  • Mark Murphy
  • Susheel