我下载了一张图片供以后离线使用
文件路径:/storage/emulated/0/3a3d95e7b3e84cfb795e4a31bbdf98d1.jpg
我将此异常传递给毕加索时:
java.io.IOException: Invalid marker: ef
at android.media.ExifInterface.getJpegAttributes(ExifInterface.java:1635)
at android.media.ExifInterface.loadAttributes(ExifInterface.java:1344)
at android.media.ExifInterface.<init>(ExifInterface.java:1062)
at com.squareup.picasso.FileRequestHandler.getFileExifRotation(FileRequestHandler.java:46)
....
即使我尝试加载png文件(没有exif),也会发生此异常。我用来存储图像的方法:
public static String okDownloadToFileSync(final String link, final String fileName, final boolean temp, DownloadStatusManager statusManager, ErrorDisplayerInterface errorDisplayerInterface) {
Request request = new Request.Builder()
.url(link)
.build();
if (statusManager != null) {
statusManager.add(Hash.md5(link));
}
OkHttpClient client = Api.getInstance().getOkHttpClient();
OutputStream output = null;
InputStream input = null;
String fileFullName = null;
try {
Response response = client.newCall(request).execute();
final String contentType = response.header("Content-Type");
final String ext = contentTypeMap.get(contentType);
Log.i(TAG, link + "\n --> contentType = " + contentType + "\n --> ext = " + ext);
if (ext == null) {
Log.e(TAG, "-----------\next is null, seems like there is a problem with that url : \n " + link + "\n----------");
return null;
} else if (ext.equals("json")) {
Log.e(TAG, "-----------\ndownloadable file seems to be a json, seems like there is a problem with that url : \n " + link + "\n----------");
return null;
}
//Check if file already exists
if (!temp && fileName != null) {
File test = new File(STORAGE_PATH + fileName + "." + ext);
if (test.exists()) {
Log.i(TAG, "File exists ! : " + test.getPath());
return STORAGE_PATH + fileName + "." + ext;
}
}
// expect HTTP 200 OK, so we don't mistakenly save error report
// instead of the file
if (!response.isSuccessful()) {
Log.e(TAG, "dwnToFileSync bug : connection.getResponseCode() != HttpURLConnection.HTTP_OK");
return null;
}
ResponseBody responseBody = response.body();
if (statusManager != null) {
statusManager.add(Hash.md5(link), responseBody.contentLength());
}
input = responseBody.byteStream();
if (temp) {
//If there is a pb with pdf, add '.pdf' as suffix
File file = File.createTempFile(UUID.randomUUID().toString(), ext, M360Application.getContext().getCacheDir());
fileFullName = file.getPath();
output = new FileOutputStream(file);
} else {
File file = new File(STORAGE_PATH + fileName + "." + ext);
fileFullName = file.getPath();
Log.i(TAG, "File full name : " + fileFullName);
output = new FileOutputStream(file);
}
Log.i(TAG, fileFullName);
byte data[] = new byte[4096];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
total++;
}
return fileFullName;
} catch (IOException e) {
e.printStackTrace();
errorDisplayerInterface.popError(null, e);
} finally {
if (statusManager != null) {
statusManager.finish(Hash.md5(link));
}
try {
if (output != null)
output.close();
if (input != null)
input.close();
} catch (IOException ignored) {
ignored.printStackTrace();
}
}
return null;
}
请注意,此方法还用于下载各自播放器正确读取的所有类型的文件。
你知道这个&#34; ef&#34;可能来自?
如果我尝试使用iv.setImageBitmap(BitmapFactory.decodeFile(file.getPath()));
,我就会收到此消息:
skia: --- SkImageDecoder::Factory returned null
我试着滑行,看看我是否有更清晰的错误信息:
java.lang.RuntimeException: setDataSource failed: status = 0x80000000
at android.media.MediaMetadataRetriever.setDataSource(Native Method)
at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java: 136)
at com.bumptech.glide.load.resource.bitmap.VideoBitmapDecoder.decode(VideoBitmapDecoder.java: 46)
at com.bumptech.glide.load.resource.bitmap.FileDescriptorBitmapDecoder.decode(FileDescriptorBitmapDecoder.java: 45)
at com.bumptech.glide.load.resource.bitmap.FileDescriptorBitmapDecoder.decode(FileDescriptorBitmapDecoder.java: 19)
at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java: 50)
at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java: 20)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeBitmapWrapper(GifBitmapWrapperResourceDecoder.java: 121)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeStream(GifBitmapWrapperResourceDecoder.java: 94)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java: 71)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java: 61)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java: 22)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromSourceData(DecodeJob.java: 190)
at com.bumptech.glide.load.engine.DecodeJob.decodeSource(DecodeJob.java: 177)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromSource(DecodeJob.java: 128)
at com.bumptech.glide.load.engine.EngineRunnable.decodeFromSource(EngineRunnable.java: 122)
at com.bumptech.glide.load.engine.EngineRunnable.decode(EngineRunnable.java: 101)
at com.bumptech.glide.load.engine.EngineRunnable.run(EngineRunnable.java: 58)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java: 423)
at java.util.concurrent.FutureTask.run(FutureTask.java: 237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java: 588)
at java.lang.Thread.run(Thread.java: 818)
at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java: 118)
谢谢!