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!
|
Mark M. |
(I *so* wish this chat would chime when somebody joins...)
|
Mark M. |
how can I help you today?
|
Susheel |
haha...
|
Susheel |
So I have two questions...
|
Mark M. |
go right ahead
|
Nov 18 | 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...
|
Susheel |
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'?
|
Susheel |
bitmap
|
Mark M. |
to try to save it more reliably, call getFD().sync() on your FileOutputStream, after flush() and before close()
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
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
|
Nov 18 | 8:00 PM |
Mark M. |
sync() does the same thing, on a per-file basis, from within the app
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
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!
|
Nov 18 | 8:05 PM |
Susheel |
makes sense now :)
|
Nov 18 | 8:10 PM |
Mark M. |
if you have another question, go right ahead
|
Susheel |
I do, I am framing my question
|
Susheel |
View paste
|
Mark M. |
yeah, you'll probably need to fix those up
|
Nov 18 | 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...
|
Susheel |
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?
|
Susheel |
oh
|
Mark M. |
I don't use Volley, but from the standpoint of JSON parsing, that's just a string
|
Mark M. |
it could be "snicklefritz" for all the JSON parser cares
|
Mark M. |
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 ::
|
Mark M. |
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
|
Nov 18 | 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!!!!!!
|
Susheel |
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
|
Mark M. |
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
|
Mark M. |
personally, I try to stick to libraries where I have clearer support channels, like an issue tracker
|
Mark M. |
so, I'll use the Square stack (OkHttp, Retrofit, Picasso)
|
Susheel |
like retrofit?
|
Susheel |
cool
|
Susheel |
Well thanks for the knowledge
|
Mark M. |
happy to be useful!
|
Susheel |
have a good night Mark
|
Mark M. |
you too!
|
Susheel |
thanks
|
Nov 18 | 8:25 PM |
Susheel | has left the room |
Nov 18 | 8:30 PM |
Mark M. | turned off guest access |