[android-developers] Re: MemoryFile - ParcelFileDescriptor

2013-01-10 Thread Peterdk
Why not use reflection to get the PFD? There is a method for that in the 
MemoryFile class.

Op woensdag 4 juli 2012 09:55:32 UTC+2 schreef rtindru het volgende:

 I have an application that needs to Base64 decode on the fly a bitmap 
 image  render it on the ImageView.
 I am using a custom content provider to do this. When the openFile method 
 is called - I in this case chose to use a normal non-encoded file for 
 testing purpose.
 Now I create a MemoryFile from the imagefile (after decoding)  have to 
 return a ParcelFileDescriptor of the MemoryFile.

 I tried reflection  got the FileDescriptor of the MemoryFile but am 
 unable to get the ParcelFileDescriptor from the FileDescriptor
 I tried the dup, adoptFD methods but the ParcelFileDescriptor was invalid.
 Kindly help me out here.
 Cheers
 Indru

 public ParcelFileDescriptor openFile(Uri uri, String mode)
 throws FileNotFoundException {
 File openFile = new File(uri.toString());
 try {
 MemoryFile file = new MemoryFile(null, (int) 
 openFile.length());
 ParcelFileDescriptor pfd = ParcelFileDescriptor.open(openFile, 
 ParcelFileDescriptor.MODE_READ_ONLY);
 AutoCloseInputStream in = new AutoCloseInputStream(pfd);
 byte[] buffer = new byte[in.available()];
 //Should do decoding here - skipped to test the code
 in.read(buffer, 0, buffer.length);
 file.writeBytes(buffer, 0, 0, buffer.length);
 Method getFileDescriptorMethod = file.getClass().getMethod(
 getFileDescriptor);
 FileDescriptor out = (FileDescriptor) getFileDescriptorMethod
 .invoke(file);
 // I have the FD, now how to return a PFD?? Any ideas? dup  adoptFD dont 
 work - the PFD is invalid.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: MemoryFile - ParcelFileDescriptor

2013-01-10 Thread Streets Of Boston
Why are you using a MemoryFile? If you need to read the file into memory, 
you could just use a byte[] and byte-arrays are parcelable.

Actually, I'd suggest not reading it into memory a all and just pass the 
'Uri uri' from the parcelable producer to the consumer and the consumer can 
read the file (as long as the consumer is not a task running on the main UI 
thread).


On Wednesday, July 4, 2012 3:55:32 AM UTC-4, rtindru wrote:

 I have an application that needs to Base64 decode on the fly a bitmap 
 image  render it on the ImageView.
 I am using a custom content provider to do this. When the openFile method 
 is called - I in this case chose to use a normal non-encoded file for 
 testing purpose.
 Now I create a MemoryFile from the imagefile (after decoding)  have to 
 return a ParcelFileDescriptor of the MemoryFile.

 I tried reflection  got the FileDescriptor of the MemoryFile but am 
 unable to get the ParcelFileDescriptor from the FileDescriptor
 I tried the dup, adoptFD methods but the ParcelFileDescriptor was invalid.
 Kindly help me out here.
 Cheers
 Indru

 public ParcelFileDescriptor openFile(Uri uri, String mode)
 throws FileNotFoundException {
 File openFile = new File(uri.toString());
 try {
 MemoryFile file = new MemoryFile(null, (int) 
 openFile.length());
 ParcelFileDescriptor pfd = ParcelFileDescriptor.open(openFile, 
 ParcelFileDescriptor.MODE_READ_ONLY);
 AutoCloseInputStream in = new AutoCloseInputStream(pfd);
 byte[] buffer = new byte[in.available()];
 //Should do decoding here - skipped to test the code
 in.read(buffer, 0, buffer.length);
 file.writeBytes(buffer, 0, 0, buffer.length);
 Method getFileDescriptorMethod = file.getClass().getMethod(
 getFileDescriptor);
 FileDescriptor out = (FileDescriptor) getFileDescriptorMethod
 .invoke(file);
 // I have the FD, now how to return a PFD?? Any ideas? dup  adoptFD dont 
 work - the PFD is invalid.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: MemoryFile - ParcelFileDescriptor

2013-01-10 Thread Streets Of Boston
Why are you using a MemoryFile? If you need to read the file into memory, 
you could just use a byte[] and byte-arrays are parcelable.

Actually, I'd suggest not reading it into memory a all and just pass the 
'Uri uri' from the parcelable producer process to the consumer process and 
the consumer can read the file.

On Wednesday, July 4, 2012 3:55:32 AM UTC-4, rtindru wrote:

 I have an application that needs to Base64 decode on the fly a bitmap 
 image  render it on the ImageView.
 I am using a custom content provider to do this. When the openFile method 
 is called - I in this case chose to use a normal non-encoded file for 
 testing purpose.
 Now I create a MemoryFile from the imagefile (after decoding)  have to 
 return a ParcelFileDescriptor of the MemoryFile.

 I tried reflection  got the FileDescriptor of the MemoryFile but am 
 unable to get the ParcelFileDescriptor from the FileDescriptor
 I tried the dup, adoptFD methods but the ParcelFileDescriptor was invalid.
 Kindly help me out here.
 Cheers
 Indru

 public ParcelFileDescriptor openFile(Uri uri, String mode)
 throws FileNotFoundException {
 File openFile = new File(uri.toString());
 try {
 MemoryFile file = new MemoryFile(null, (int) 
 openFile.length());
 ParcelFileDescriptor pfd = ParcelFileDescriptor.open(openFile, 
 ParcelFileDescriptor.MODE_READ_ONLY);
 AutoCloseInputStream in = new AutoCloseInputStream(pfd);
 byte[] buffer = new byte[in.available()];
 //Should do decoding here - skipped to test the code
 in.read(buffer, 0, buffer.length);
 file.writeBytes(buffer, 0, 0, buffer.length);
 Method getFileDescriptorMethod = file.getClass().getMethod(
 getFileDescriptor);
 FileDescriptor out = (FileDescriptor) getFileDescriptorMethod
 .invoke(file);
 // I have the FD, now how to return a PFD?? Any ideas? dup  adoptFD dont 
 work - the PFD is invalid.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en