Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
767087d4
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,体验更适合开发者的 AI 搜索 >>
提交
767087d4
编写于
11月 02, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid I/O in DecodeJobTest
上级
2293cb27
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
11 deletion
+32
-11
library/src/androidTest/java/com/bumptech/glide/load/engine/DecodeJobTest.java
...st/java/com/bumptech/glide/load/engine/DecodeJobTest.java
+7
-4
library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java
...c/main/java/com/bumptech/glide/load/engine/DecodeJob.java
+25
-7
未找到文件。
library/src/androidTest/java/com/bumptech/glide/load/engine/DecodeJobTest.java
浏览文件 @
767087d4
...
...
@@ -19,6 +19,7 @@ import org.robolectric.RobolectricTestRunner;
import
org.robolectric.annotation.Config
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Arrays
;
...
...
@@ -44,7 +45,7 @@ public class DecodeJobTest {
private
Harness
harness
;
@Before
public
void
setUp
()
{
public
void
setUp
()
throws
FileNotFoundException
{
harness
=
new
Harness
();
}
...
...
@@ -594,15 +595,17 @@ public class DecodeJobTest {
ResourceEncoder
<
Object
>
resultEncoder
=
mock
(
ResourceEncoder
.
class
);
ResourceDecoder
<
Object
,
Object
>
sourceDecoder
=
mock
(
ResourceDecoder
.
class
);
Encoder
<
Object
>
sourceEncoder
=
mock
(
Encoder
.
class
);
DecodeJob
.
FileOpener
fileOpener
=
mock
(
DecodeJob
.
FileOpener
.
class
);
DiskCacheStrategy
diskCacheStrategy
;
public
Harness
()
{
public
Harness
()
throws
FileNotFoundException
{
this
(
DiskCacheStrategy
.
RESULT
);
}
public
Harness
(
DiskCacheStrategy
diskCacheStrategy
)
{
public
Harness
(
DiskCacheStrategy
diskCacheStrategy
)
throws
FileNotFoundException
{
this
.
diskCacheStrategy
=
diskCacheStrategy
;
when
(
fileOpener
.
open
(
any
(
File
.
class
))).
thenReturn
(
mock
(
OutputStream
.
class
));
when
(
key
.
getOriginalKey
()).
thenReturn
(
originalKey
);
when
(
transcoder
.
transcode
(
eq
(
resource
))).
thenReturn
(
resource
);
when
(
transformation
.
transform
(
eq
(
resource
),
eq
(
width
),
eq
(
height
))).
thenReturn
(
resource
);
...
...
@@ -614,7 +617,7 @@ public class DecodeJobTest {
public
DecodeJob
<
Object
,
Object
,
Object
>
getJob
()
{
return
new
DecodeJob
<
Object
,
Object
,
Object
>(
key
,
width
,
height
,
dataFetcher
,
loadProvider
,
transformation
,
transcoder
,
diskCache
,
diskCacheStrategy
,
priority
);
transcoder
,
diskCache
,
diskCacheStrategy
,
priority
,
fileOpener
);
}
}
...
...
library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java
浏览文件 @
767087d4
...
...
@@ -28,6 +28,7 @@ import java.io.OutputStream;
*/
class
DecodeJob
<
A
,
T
,
Z
>
{
private
static
final
String
TAG
=
"DecodeJob"
;
private
static
final
FileOpener
DEFAULT_FILE_OPENER
=
new
FileOpener
();
private
final
EngineKey
resultKey
;
private
final
int
width
;
...
...
@@ -39,11 +40,21 @@ class DecodeJob<A, T, Z> {
private
final
DiskCacheStrategy
diskCacheStrategy
;
private
final
DiskCache
diskCache
;
private
final
Priority
priority
;
private
final
FileOpener
fileOpener
;
private
volatile
boolean
isCancelled
;
public
DecodeJob
(
EngineKey
resultKey
,
int
width
,
int
height
,
DataFetcher
<
A
>
fetcher
,
DataLoadProvider
<
A
,
T
>
loadProvider
,
Transformation
<
T
>
transformation
,
ResourceTranscoder
<
T
,
Z
>
transcoder
,
DiskCache
diskCache
,
DiskCacheStrategy
diskCacheStrategy
,
Priority
priority
)
{
this
(
resultKey
,
width
,
height
,
fetcher
,
loadProvider
,
transformation
,
transcoder
,
diskCache
,
diskCacheStrategy
,
priority
,
DEFAULT_FILE_OPENER
);
}
// Visible for testing.
DecodeJob
(
EngineKey
resultKey
,
int
width
,
int
height
,
DataFetcher
<
A
>
fetcher
,
DataLoadProvider
<
A
,
T
>
loadProvider
,
Transformation
<
T
>
transformation
,
ResourceTranscoder
<
T
,
Z
>
transcoder
,
DiskCache
diskCache
,
DiskCacheStrategy
diskCacheStrategy
,
Priority
priority
,
FileOpener
fileOpener
)
{
this
.
resultKey
=
resultKey
;
this
.
width
=
width
;
this
.
height
=
height
;
...
...
@@ -54,6 +65,7 @@ class DecodeJob<A, T, Z> {
this
.
diskCacheStrategy
=
diskCacheStrategy
;
this
.
diskCache
=
diskCache
;
this
.
priority
=
priority
;
this
.
fileOpener
=
fileOpener
;
}
/**
...
...
@@ -233,12 +245,16 @@ class DecodeJob<A, T, Z> {
return
transcoder
.
transcode
(
transformed
);
}
static
class
SourceWriter
<
T
>
implements
DiskCache
.
Writer
{
private
void
logWithTimeAndKey
(
String
message
,
long
startTime
)
{
Log
.
v
(
TAG
,
message
+
" in "
+
LogTime
.
getElapsedMillis
(
startTime
)
+
resultKey
);
}
class
SourceWriter
<
DataType
>
implements
DiskCache
.
Writer
{
private
final
Encoder
<
T
>
encoder
;
private
final
T
data
;
private
final
Encoder
<
DataType
>
encoder
;
private
final
DataType
data
;
public
SourceWriter
(
Encoder
<
T
>
encoder
,
T
data
)
{
public
SourceWriter
(
Encoder
<
DataType
>
encoder
,
DataType
data
)
{
this
.
encoder
=
encoder
;
this
.
data
=
data
;
}
...
...
@@ -248,7 +264,7 @@ class DecodeJob<A, T, Z> {
boolean
success
=
false
;
OutputStream
os
=
null
;
try
{
os
=
new
BufferedOutputStream
(
new
FileOutputStream
(
file
)
);
os
=
fileOpener
.
open
(
file
);
success
=
encoder
.
encode
(
data
,
os
);
}
catch
(
FileNotFoundException
e
)
{
if
(
Log
.
isLoggable
(
TAG
,
Log
.
DEBUG
))
{
...
...
@@ -267,7 +283,9 @@ class DecodeJob<A, T, Z> {
}
}
private
void
logWithTimeAndKey
(
String
message
,
long
startTime
)
{
Log
.
v
(
TAG
,
message
+
" in "
+
LogTime
.
getElapsedMillis
(
startTime
)
+
resultKey
);
static
class
FileOpener
{
public
OutputStream
open
(
File
file
)
throws
FileNotFoundException
{
return
new
BufferedOutputStream
(
new
FileOutputStream
(
file
));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录