Search code examples
androiduriarraysinputstreamapache-commons

apache commons IOUtils.toByteArray not compiling for android


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?


Solution

  • Apache commons works fine with the following:

    context.getContentResolver().openInputStream(uri);
    byte[] attachmentBites = IOUtils.toByteArray(in);