Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wd1105040417
retrofit
提交
d86f495f
R
retrofit
项目概览
wd1105040417
/
retrofit
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
retrofit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d86f495f
编写于
12月 12, 2010
作者:
E
Eric Burke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TypedFile gets its length from the underlying file now
上级
0edb2af0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
8 deletion
+41
-8
modules/io/src-tests/retrofit/io/TypedFileTest.java
modules/io/src-tests/retrofit/io/TypedFileTest.java
+28
-0
modules/io/src/retrofit/io/AbstractTypedBytes.java
modules/io/src/retrofit/io/AbstractTypedBytes.java
+3
-6
modules/io/src/retrofit/io/TypedByteArray.java
modules/io/src/retrofit/io/TypedByteArray.java
+5
-1
modules/io/src/retrofit/io/TypedFile.java
modules/io/src/retrofit/io/TypedFile.java
+5
-1
未找到文件。
modules/io/src-tests/retrofit/io/TypedFileTest.java
浏览文件 @
d86f495f
...
...
@@ -4,6 +4,8 @@ package retrofit.io;
import
junit.framework.TestCase
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
/** @author Eric Burke (eric@squareup.com) */
public
class
TypedFileTest
extends
TestCase
{
...
...
@@ -29,4 +31,30 @@ public class TypedFileTest extends TestCase {
assertEquals
(
file
.
getAbsolutePath
()
+
" (PNG)"
,
new
TypedFile
(
file
,
MimeType
.
PNG
).
toString
());
}
public
void
testLength
()
throws
IOException
{
File
tempFile
=
File
.
createTempFile
(
"foo"
,
".tmp"
);
try
{
TypedFile
typedFile
=
new
TypedFile
(
tempFile
,
MimeType
.
PNG
);
assertEquals
(
"length"
,
0
,
typedFile
.
length
());
writeToFile
(
tempFile
,
new
byte
[]{
0
,
1
,
2
,
3
,
4
});
assertEquals
(
"file length"
,
5
,
tempFile
.
length
());
assertEquals
(
"typed file length"
,
5
,
typedFile
.
length
());
}
finally
{
//noinspection ResultOfMethodCallIgnored
tempFile
.
delete
();
}
}
private
void
writeToFile
(
File
file
,
byte
[]
data
)
throws
IOException
{
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
try
{
fos
.
write
(
data
);
}
finally
{
fos
.
close
();
}
}
}
\ No newline at end of file
modules/io/src/retrofit/io/AbstractTypedBytes.java
浏览文件 @
d86f495f
...
...
@@ -14,15 +14,13 @@ public abstract class AbstractTypedBytes implements TypedBytes, Serializable {
private
static
final
long
serialVersionUID
=
0
;
private
final
MimeType
mimeType
;
private
final
int
length
;
/**
* Stores the mime type.
*
* @throws NullPointerException if mimeType is null
*/
public
AbstractTypedBytes
(
MimeType
mimeType
,
int
length
)
{
this
.
length
=
length
;
public
AbstractTypedBytes
(
MimeType
mimeType
)
{
this
.
mimeType
=
Objects
.
nonNull
(
mimeType
,
"mimeType"
);
}
...
...
@@ -30,7 +28,6 @@ public abstract class AbstractTypedBytes implements TypedBytes, Serializable {
return
mimeType
;
}
public
int
length
()
{
return
length
;
}
/** Returns the length in bytes. */
public
abstract
int
length
();
}
\ No newline at end of file
modules/io/src/retrofit/io/TypedByteArray.java
浏览文件 @
d86f495f
...
...
@@ -23,7 +23,7 @@ public class TypedByteArray extends AbstractTypedBytes {
* @throws NullPointerException if bytes or mimeType is null
*/
public
TypedByteArray
(
byte
[]
bytes
,
MimeType
mimeType
)
{
super
(
mimeType
,
bytes
.
length
);
super
(
mimeType
);
this
.
bytes
=
Objects
.
nonNull
(
bytes
,
"bytes"
);
}
...
...
@@ -31,6 +31,10 @@ public class TypedByteArray extends AbstractTypedBytes {
out
.
write
(
bytes
);
}
@Override
public
int
length
()
{
return
bytes
.
length
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
...
...
modules/io/src/retrofit/io/TypedFile.java
浏览文件 @
d86f495f
...
...
@@ -23,7 +23,7 @@ public class TypedFile extends AbstractTypedBytes {
* @throws NullPointerException if file or mimeType is null
*/
public
TypedFile
(
File
file
,
MimeType
mimeType
)
{
super
(
mimeType
,
(
int
)
file
.
length
()
);
super
(
mimeType
);
this
.
file
=
Objects
.
nonNull
(
file
,
"file"
);
}
...
...
@@ -70,4 +70,8 @@ public class TypedFile extends AbstractTypedBytes {
public
int
hashCode
()
{
return
file
.
hashCode
();
}
@Override
public
int
length
()
{
return
(
int
)
file
.
length
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录