forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from dongyuanlongwang/master
第三周的作业终于完成了
- Loading branch information
Showing
7 changed files
with
213 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...3/1360464792/src/main/java/rui/study/coding2017/jobs3/download/api/ConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package rui.study.coding2017.jobs3.download.api; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
|
||
public interface ConnectionManager { | ||
/** | ||
* 给定一个url , 打开一个连接 | ||
* @param url | ||
* @return | ||
*/ | ||
public Connection open(String url) throws ConnectionException; | ||
public Connection open(String url) throws ConnectionException, IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...1360464792/src/test/java/rui/study/coding2017/jobs3/download/impl/ConnectionImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package rui.study.coding2017.jobs3.download.impl; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* 测试链接实现 | ||
* Created by 赵睿 on 2017/3/15. | ||
*/ | ||
public class ConnectionImplTest { | ||
private String url="http://sw.bos.baidu.com/sw-search-sp/software/952c9d6e73f50/QQ_8.9.20029.0_setup.exe"; | ||
|
||
private ConnectionImpl connection=new ConnectionImpl(new URL(url)); | ||
|
||
public ConnectionImplTest() throws IOException { | ||
} | ||
|
||
@Test | ||
public void read() throws Exception { | ||
byte[] bs=connection.read(0,connection.getContentLength()); | ||
System.out.println(bs.length); | ||
FileOutputStream fileOutputStream=new FileOutputStream(new File("D://eee.exe")); | ||
fileOutputStream.write(bs); | ||
fileOutputStream.flush(); | ||
fileOutputStream.close(); | ||
} | ||
|
||
@Test | ||
public void getContentLength() throws Exception { | ||
System.out.println(connection.getContentLength()); | ||
} | ||
|
||
} |