I am using
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
If I call it and the CP can't provide the file, the caller (client) will still get an empty file no matter what I do on the CP side. That is, an exception on the CP-side file provider (I am on the network retrieving files) will never propagate through to the caller resulting in an Exception there. is this solvable on API 14?
Code looks something like this:
ContentProvider:
@Override
public ParcelFileDescriptor openFile(Uri uri, String args) throws FileNotFoundException {
try {
return openPipeHelper(uri, "application/octet-stream", null, null, new FileDeliverer(uri, args)); //FileDeliverer constructor can cause MalformedURLException
} catch (IOException e) {
throw new FileNotFoundException("IOException when connecting!");
}
}
FileDeliverer class (implements ContentProvider.PipeDataWriter) has this overriden method:
@Override
public void writeDataToPipe(ParcelFileDescriptor clientSideParcelFileDescriptor, Uri uri, String s, Bundle bundle, Object o) {
InputStream inputStream;
ParcelFileDescriptor.AutoCloseOutputStream autoCloseOutputStream=null;
BasicHttpURLConnectorToTry basicHttpURLConnectorToTry =new BasicHttpURLConnectorToTry(url, timeOutMs);
try {
RepeatRetries repeatRetries = new RepeatRetries(basicHttpURLConnectorToTry, retries, retryDelayMs);
inputStream = (InputStream) repeatRetries.executeWithRetries();
autoCloseOutputStream=new ParcelFileDescriptor.AutoCloseOutputStream(clientSideParcelFileDescriptor);
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) != -1) {
autoCloseOutputStream.write(buffer, 0, len);
}
} catch (Exception e) {
Log.e("FileDeliverer", "Exception when connecting or delivering data to client!", e);
} finally {
basicHttpURLConnectorToTry.closeStreamAndDisconnect();
try {
autoCloseOutputStream.close();
} catch (Exception e) {
Log.w("FileDeliverer", "Couldn't close OutputStream!", e);
}
}
}