-
Notifications
You must be signed in to change notification settings - Fork 641
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 #46 from maishihang/master
complete all homework
- Loading branch information
Showing
26 changed files
with
1,116 additions
and
273 deletions.
There are no files selected for viewing
31 changes: 28 additions & 3 deletions
31
group12/446031103/src/com/coderising/download/DownloadThread.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,20 +1,45 @@ | ||
package com.coderising.download; | ||
|
||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import java.util.concurrent.BrokenBarrierException; | ||
import java.util.concurrent.CyclicBarrier; | ||
|
||
import com.coderising.download.api.Connection; | ||
|
||
public class DownloadThread extends Thread{ | ||
|
||
Connection conn; | ||
int startPos; | ||
int endPos; | ||
|
||
public DownloadThread( Connection conn, int startPos, int endPos){ | ||
CyclicBarrier barrier; | ||
String localFile; | ||
public DownloadThread( Connection conn, int startPos, int endPos, String localFile, CyclicBarrier barrier){ | ||
|
||
this.conn = conn; | ||
this.startPos = startPos; | ||
this.endPos = endPos; | ||
this.localFile = localFile; | ||
this.barrier = barrier; | ||
} | ||
public void run(){ | ||
|
||
try { | ||
byte[] data =conn.read(startPos, endPos); | ||
RandomAccessFile file = new RandomAccessFile(localFile,"rw"); | ||
file.seek(startPos); | ||
file.write(data); | ||
file.close(); | ||
conn.close(); | ||
barrier.await(); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (InterruptedException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (BrokenBarrierException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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
53 changes: 48 additions & 5 deletions
53
group12/446031103/src/com/coderising/download/impl/ConnectionImpl.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
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
53 changes: 53 additions & 0 deletions
53
group12/446031103/src/com/coderising/download/test/ConnectionTest.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,53 @@ | ||
package com.coderising.download.test; | ||
|
||
|
||
|
||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.coderising.download.api.Connection; | ||
import com.coderising.download.api.ConnectionManager; | ||
import com.coderising.download.impl.ConnectionManagerImpl; | ||
|
||
public class ConnectionTest { | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
public void testContentLength() throws Exception{ | ||
ConnectionManager connMan = new ConnectionManagerImpl(); | ||
Connection conn = connMan.open("http://www.hinews.cn/pic/0/13/91/26/13912621_821796.jpg"); | ||
Assert.assertEquals(35470, conn.getContentLength()); | ||
} | ||
|
||
@Test | ||
public void testRead() throws Exception{ | ||
|
||
ConnectionManager connMan = new ConnectionManagerImpl(); | ||
Connection conn = connMan.open("http://www.hinews.cn/pic/0/13/91/26/13912621_821796.jpg"); | ||
|
||
byte[] data = conn.read(0, 35469); | ||
|
||
Assert.assertEquals(35470, data.length); | ||
|
||
data = conn.read(0, 1023); | ||
|
||
Assert.assertEquals(1024, data.length); | ||
|
||
data = conn.read(1024, 2023); | ||
|
||
Assert.assertEquals(1000, data.length); | ||
|
||
|
||
// 测试不充分,没有断言内容是否正确 | ||
} | ||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
group12/446031103/src/com/coderising/jvm/loader/ClassFileLoader.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,43 @@ | ||
package com.coderising.jvm.loader; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
|
||
public class ClassFileLoader { | ||
|
||
private List<String> clzPaths = new ArrayList<String>(); | ||
|
||
public byte[] readBinaryCode(String className) { | ||
|
||
return null; | ||
|
||
|
||
} | ||
|
||
private byte[] loadClassFile(String clzFileName) { | ||
|
||
return null; | ||
} | ||
|
||
|
||
|
||
public void addClassPath(String path) { | ||
|
||
} | ||
|
||
public String getClassPath_V1(){ | ||
|
||
return null; | ||
} | ||
|
||
public String getClassPath(){ | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.