Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
9aee1250
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9aee1250
编写于
6月 04, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup data in LocalUriFetcher
上级
dbb67f82
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
84 addition
and
4 deletion
+84
-4
library/robolectric/src/com/bumptech/glide/load/resource/LocalUriFetcherTest.java
...com/bumptech/glide/load/resource/LocalUriFetcherTest.java
+66
-0
library/src/com/bumptech/glide/load/resource/LocalUriFetcher.java
...src/com/bumptech/glide/load/resource/LocalUriFetcher.java
+18
-4
未找到文件。
library/robolectric/src/com/bumptech/glide/load/resource/LocalUriFetcherTest.java
0 → 100644
浏览文件 @
9aee1250
package
com.bumptech.glide.load.resource
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.net.Uri
;
import
com.bumptech.glide.Priority
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.Robolectric
;
import
org.robolectric.RobolectricTestRunner
;
import
java.io.Closeable
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
LocalUriFetcherTest
{
private
TestLocalUriFetcher
fetcher
;
@Before
public
void
setUp
()
{
fetcher
=
new
TestLocalUriFetcher
(
Robolectric
.
application
,
Uri
.
parse
(
"content://empty"
));
}
@Test
public
void
testClosesDataOnCleanup
()
throws
Exception
{
Closeable
closeable
=
fetcher
.
loadResource
(
Priority
.
NORMAL
);
fetcher
.
cleanup
();
verify
(
closeable
).
close
();
}
@Test
public
void
testDoesNotCLoseNullData
()
throws
IOException
{
fetcher
.
cleanup
();
verify
(
fetcher
.
closeable
,
never
()).
close
();
}
@Test
public
void
testHandlesExceptionOnClose
()
throws
Exception
{
Closeable
closeable
=
fetcher
.
loadResource
(
Priority
.
NORMAL
);
doThrow
(
new
IOException
(
"Test"
)).
when
(
closeable
).
close
();
fetcher
.
cleanup
();
verify
(
closeable
).
close
();
}
private
static
class
TestLocalUriFetcher
extends
LocalUriFetcher
<
Closeable
>
{
public
Closeable
closeable
=
mock
(
Closeable
.
class
);
public
TestLocalUriFetcher
(
Context
context
,
Uri
uri
)
{
super
(
context
,
uri
);
}
@Override
protected
Closeable
loadResource
(
Uri
uri
,
ContentResolver
contentResolver
)
throws
FileNotFoundException
{
return
closeable
;
}
}
}
library/src/com/bumptech/glide/load/resource/LocalUriFetcher.java
浏览文件 @
9aee1250
...
...
@@ -3,17 +3,22 @@ package com.bumptech.glide.load.resource;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.net.Uri
;
import
android.util.Log
;
import
com.bumptech.glide.Priority
;
import
java.io.Closeable
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.lang.ref.WeakReference
;
/**
*
*/
public
abstract
class
LocalUriFetcher
<
T
>
implements
ResourceFetcher
<
T
>
{
public
abstract
class
LocalUriFetcher
<
T
extends
Closeable
>
implements
ResourceFetcher
<
T
>
{
private
static
final
String
TAG
=
"LocalUriFetcher"
;
private
final
WeakReference
<
Context
>
contextRef
;
private
final
Uri
uri
;
private
T
data
;
/**
* Opens an input stream for a uri pointing to a local asset. Only certain uris are supported
...
...
@@ -37,14 +42,23 @@ public abstract class LocalUriFetcher<T> implements ResourceFetcher<T> {
throw
new
NullPointerException
(
"Context has been cleared in LocalUriFetcher uri: "
+
uri
);
}
ContentResolver
contentResolver
=
context
.
getContentResolver
();
return
loadResource
(
uri
,
contentResolver
);
data
=
loadResource
(
uri
,
contentResolver
);
return
data
;
}
@Override
public
void
cleanup
()
{
// Do nothing.
}
if
(
data
!=
null
)
{
try
{
data
.
close
();
}
catch
(
IOException
e
)
{
if
(
Log
.
isLoggable
(
TAG
,
Log
.
VERBOSE
))
{
Log
.
v
(
TAG
,
"failed to close data"
,
e
);
}
}
}
}
@Override
public
void
cancel
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录