Reputation: 11780
I want to use the method
byte[] IOUtils.toByteArray(Uri uri)
from org.apache.commons.io.IOUtils
. My Uri is a typical android uri of type android.net.Uri
. Does anyone know how I may fix this? An intermediary might be getting the input stream from the uri. Does anyone know how to do that?
Upvotes: 1
Views: 986
Reputation: 11780
Apache commons works fine with the following:
context.getContentResolver().openInputStream(uri);
byte[] attachmentBites = IOUtils.toByteArray(in);
Upvotes: 1
Reputation: 3508
The method uses a java.net.URI
(ref: IOUtils javadoc), not an android.net.Uri
.
So the example use would be something like:
android.net.URI auri = new android.net.URI(whatever);
java.net.URI juri = new java.net.URI(auri.toString());
try {
byte[] output = IOUtils.toByteArray(juri);
} catch (IOException e) {
e.printStackTrace();
}
(presuming you have already imported and included in your build path the org.apache.commons.io
library)
Upvotes: 1