Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
aa3a1b7
Merge remote-tracking branch 'refs/remotes/origin/master' into jodie-…
jiangshaojie Feb 26, 2017
41b0d91
Merge remote-tracking branch 'refs/remotes/origin/master' into jodie-…
jiangshaojie Mar 4, 2017
4dd4bf9
Merge pull request #2 from jodie-zss/master
jiangshaojie Mar 4, 2017
7c9d0bd
test
jiangshaojie Mar 4, 2017
e2ee3c2
Merge branch 'master' into work
jiangshaojie Mar 4, 2017
c160c41
Merge remote-tracking branch 'refs/remotes/jodie-zss/master'
Jayzyyzyy Mar 5, 2017
68e7e2d
Merge pull request #2 from jodie-zss/master
oneces Mar 6, 2017
433bdc1
Merge branch 'master' of https://github.com/jodie-zss/coding2017
Jayzyyzyy Mar 6, 2017
54b71be
Jayzyyzyy Mar 6, 2017
73247db
Merge remote-tracking branch 'refs/remotes/origin/master' into jodie-…
Jayzyyzyy Mar 6, 2017
2490de9
c
Jayzyyzyy Mar 6, 2017
60419fd
c
Jayzyyzyy Mar 6, 2017
6c299a2
Merge remote-tracking branch 'refs/remotes/origin/master'
Jayzyyzyy Mar 6, 2017
6d54d40
xuweijay
Jayzyyzyy Mar 6, 2017
5754b7f
Merge remote-tracking branch 'origin/master'
oneces Mar 6, 2017
f436aa7
20170305布置作业 更新
oneces Mar 6, 2017
e25cff9
Merge remote-tracking branch 'refs/remotes/jodie-zss/master'
gabywong Mar 6, 2017
0bc8f17
Merge remote-tracking branch 'refs/remotes/jodie-zss/master'
gabywong Mar 6, 2017
4390e26
0305
gabywong Mar 6, 2017
3310ab9
0305-2
gabywong Mar 6, 2017
c18f10f
Merge branch 'master' of https://github.com/jodie-zss/coding2017 into…
jiangshaojie Mar 6, 2017
2481fb4
Merge branch 'jodie-zss/master'
jiangshaojie Mar 6, 2017
67e1f64
保存
oneces Mar 7, 2017
457016e
c
Jayzyyzyy Mar 7, 2017
cacf1a0
1510-bruce:update the homework0226
MedalJiao Mar 7, 2017
d46bcc5
Merge branch 'master' of https://github.com/jodie-zss/coding2017
MedalJiao Mar 7, 2017
cd8dfd8
xuweijay
Jayzyyzyy Mar 8, 2017
d7419d0
多线程下载
gabywong Mar 10, 2017
ac95a2f
0312_LinkedList
Gropingzy Mar 10, 2017
e304717
作业一半
hiei17 Mar 10, 2017
92ac30b
Update Struts.java
Gropingzy Mar 10, 2017
31cbc81
xuweijay
Jayzyyzyy Mar 10, 2017
c1926d0
xuweijay
Jayzyyzyy Mar 10, 2017
f629b4c
xuweijay
Jayzyyzyy Mar 11, 2017
e772f9f
xuweijay
Jayzyyzyy Mar 11, 2017
80413b3
xuweijay
Jayzyyzyy Mar 11, 2017
38469f6
3.12作业
gabywong Mar 11, 2017
95b8f57
保存
oneces Mar 11, 2017
c3669b9
3.12
gabywong Mar 11, 2017
8ce617a
Merge pull request #35 from gabywong/master
jodie-zss Mar 11, 2017
3f1686a
Merge pull request #33 from Gropingzy/origin
jodie-zss Mar 11, 2017
3f6240d
Merge remote-tracking branch 'refs/remotes/onlyliuxin/master'
jodie-zss Mar 11, 2017
a029230
Merge branch 'master' of https://github.com/jodie-zss/coding2017
jodie-zss Mar 11, 2017
90d29ae
3.12作业
jjyyjjyy Mar 11, 2017
dd9b22a
Merge remote-tracking branch 'jodie-zss/master'
hiei17 Mar 12, 2017
0652ca3
下载
hiei17 Mar 12, 2017
11d707b
xuweijay
Jayzyyzyy Mar 12, 2017
2847902
c
Jayzyyzyy Mar 12, 2017
2aff282
c
Jayzyyzyy Mar 12, 2017
e40632f
c
Jayzyyzyy Mar 12, 2017
b460336
0312作业
lyz337959725 Mar 12, 2017
c2119c1
homework0312
MedalJiao Mar 12, 2017
2c10b0d
Merge pull request #39 from brucejiao1/master
jodie-zss Mar 12, 2017
ff4895d
Merge pull request #38 from lyz337959725/master
jodie-zss Mar 12, 2017
91eb89f
Merge pull request #37 from Jayzyyzyy/master
jodie-zss Mar 12, 2017
f41fdf4
Merge pull request #36 from jy97799/master
jodie-zss Mar 12, 2017
39af7ad
add download
jiangshaojie Mar 12, 2017
ef1ab8f
作业3.12
hiei17 Mar 12, 2017
031546b
Merge pull request #40 from hiei17/master
jodie-zss Mar 13, 2017
83ac7a7
task3和包目录调整
oneces Mar 13, 2017
145b59e
Merge pull request #41 from wa122as/master
jodie-zss Mar 13, 2017
1508170
homework0312
MedalJiao Mar 28, 2017
eafc9cc
Merge branch 'master' of https://github.com/jodie-zss/coding2016
MedalJiao Mar 28, 2017
9cb1cf1
Merge remote-tracking branch 'refs/remotes/jodie-zss/master'
gabywong Mar 29, 2017
9295418
170402作业&重构文件目录
gabywong Mar 29, 2017
c99a7b8
补交作业
jiangshaojie Mar 29, 2017
f089e21
补交作业
jiangshaojie Mar 29, 2017
b659f4d
补交作业
jiangshaojie Mar 29, 2017
07d5ec9
add file
jiangshaojie Mar 30, 2017
26bfff2
Merge remote-tracking branch 'upstream/master'
jiangshaojie Mar 30, 2017
6433478
Merge remote-tracking branch 'refs/remotes/origin/master' into onlyli…
jodie-zss Mar 31, 2017
b91ac58
Merge pull request #45 from onlyliuxin/master
jodie-zss Apr 1, 2017
ef53d76
Merge pull request #42 from gabywong/master
jodie-zss Apr 1, 2017
500c11d
delete some temporary file
MedalJiao Apr 2, 2017
c1967ef
Merge branch 'master' of https://github.com/jodie-zss/coding2017
MedalJiao Apr 2, 2017
4e5adfc
4.2作业 LRU&ClassFileLoader
jjyyjjyy Apr 2, 2017
fae45f5
3.27作业
jiangshaojie Apr 2, 2017
f9b49bb
Merge branch 'work'
jiangshaojie Apr 2, 2017
62f51e3
删除非必要文件
jiangshaojie Apr 2, 2017
36ce885
删除文件
jiangshaojie Apr 2, 2017
c5351d2
Delete test.jpg
jiangshaojie Apr 2, 2017
398347f
Delete LinkedListTest.java
jiangshaojie Apr 2, 2017
2a3085b
Delete LinkedListbakTest.java
jiangshaojie Apr 2, 2017
b39ff69
Delete testss.java
jiangshaojie Apr 2, 2017
b79d926
Delete ArrayList.java
jiangshaojie Apr 2, 2017
8b4c00d
Delete Iterator.java
jiangshaojie Apr 2, 2017
50d0003
Delete LinkedList.java
jiangshaojie Apr 2, 2017
1fcb28a
Delete LinkedListbak.java
jiangshaojie Apr 2, 2017
c2d3dca
Delete List.java
jiangshaojie Apr 2, 2017
802541f
Delete Queue.java
jiangshaojie Apr 2, 2017
ab672d0
Delete Stack.java
jiangshaojie Apr 2, 2017
6102c85
Delete test.java
jiangshaojie Apr 2, 2017
40cc2e0
Delete ArrayUtil.java
jiangshaojie Apr 2, 2017
19d3d85
Delete ArrayUtilTest.java
jiangshaojie Apr 2, 2017
2a26efc
Delete DownloadThread.java
jiangshaojie Apr 2, 2017
8fbd102
Delete FileDownloader.java
jiangshaojie Apr 2, 2017
d172248
Delete FileDownloaderTest.java
jiangshaojie Apr 2, 2017
a093db7
Delete ConnectionImpl.java
jiangshaojie Apr 2, 2017
efcaa53
Delete ConnectionManagerImpl.java
jiangshaojie Apr 2, 2017
4b39626
Delete Connection.java
jiangshaojie Apr 2, 2017
7a91980
Delete ConnectionException.java
jiangshaojie Apr 2, 2017
9064f0d
Delete ConnectionManager.java
jiangshaojie Apr 2, 2017
48b3195
Delete DownloadListener.java
jiangshaojie Apr 2, 2017
3fb447c
Delete LoginAction.java
jiangshaojie Apr 2, 2017
4a154e5
Delete Struts.java
jiangshaojie Apr 2, 2017
8b7da4d
Delete StrutsTest.java
jiangshaojie Apr 2, 2017
4ffb52f
Delete View.java
jiangshaojie Apr 2, 2017
7f4548b
Delete struts.xml
jiangshaojie Apr 2, 2017
bfc0033
Merge pull request #47 from jiangshaojie/master
jodie-zss Apr 4, 2017
4c79772
Merge pull request #46 from jy97799/master
jodie-zss Apr 4, 2017
88e0583
2017.04.04
MedalJiao Apr 4, 2017
e51e577
Merge pull request #48 from brucejiao1/master
jodie-zss Apr 6, 2017
6f90ec5
Merge pull request #50 from onlyliuxin/master
jodie-zss Apr 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<result name="success">/jsp/homepage.jsp</result>
<result name="fail">/jsp/showLogin.jsp</result>
</action>
<action name="logout" class="com.coderising.action.LogoutAction">
<action name="logout" class="com.coderising.litestruts.LogoutAction">
<result name= "success">/jsp/welcome.jsp</result>
<result name= "error">/jsp/error.jsp</result>
</action>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.coderising.download;

import com.coderising.download.api.Connection;

import java.io.*;

public class DownloadThread extends Thread{

Connection conn;
int startPos;
int endPos;

public DownloadThread(Connection conn, int startPos, int endPos){
this.conn = conn;
this.startPos = startPos;
this.endPos = endPos;
System.out.println(startPos + "---->" + endPos);
}
public void run(){
try {
File file = new File("test.jpg");
RandomAccessFile out = null;
if (file != null) {
out = new RandomAccessFile(file,"rwd");
}

byte[] buffer = new byte[1024];
/* out.seek(startPos);
out.write(conn.read(startPos,endPos));*/
InputStream in = conn.getHttpURLConnection().getInputStream();
in.skip(startPos);
int len = 0;
while ((len = in.read(buffer)) != 1) {
if (len < 0) {
break;
}else {
//System.out.println("len length"+len);
out.write(buffer, 0, len);
}
}

out.close();

} catch (IOException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.coderising.download;

import com.coderising.download.api.Connection;
import com.coderising.download.api.ConnectionException;
import com.coderising.download.api.ConnectionManager;
import com.coderising.download.api.DownloadListener;
import java.io.IOException;
import java.io.RandomAccessFile;


public class FileDownloader {

String url;

DownloadListener listener;

ConnectionManager cm;


public FileDownloader(String _url) {
this.url = _url;

}
public static synchronized void writefile(int index, RandomAccessFile randomAccessFile, byte[] bytes) throws IOException {
randomAccessFile.seek(index);
randomAccessFile.write(bytes);
}

public void execute(int threadnum) throws IOException {
// 在这里实现你的代码, 注意: 需要用多线程实现下载
// 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
// (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
// (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
// 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
// 具体的实现思路:
// 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
// 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
// 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
// 3. 把byte数组写入到文件中
// 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法

// 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
Connection conn = null;


try {

conn = cm.open(this.url);

int filelength = conn.getContentLength();
//randomAccessFile.setLength(filelength);
int[] index = new int[threadnum+1];
for (int i = 0; i <index.length-1 ; i++) {
index[i] = 0 + i * (filelength / threadnum);
}
index[index.length - 1]=filelength;
DownloadThread thread;
for (int i = 0; i <threadnum ; i++) {

thread=new DownloadThread(conn, index[i], index[i+1]);
thread.start();
thread.join();
}

listener.notifyFinished();
} catch (ConnectionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally{
if(conn != null){

conn.close();

}
}




}

public void setListener(DownloadListener listener) {
this.listener = listener;
}



public void setConnectionManager(ConnectionManager ucm){
this.cm = ucm;
}

public DownloadListener getListener(){
return this.listener;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.coderising.download;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.coderising.download.api.ConnectionManager;
import com.coderising.download.api.DownloadListener;
import com.coderising.download.impl.ConnectionManagerImpl;

import java.io.IOException;

public class FileDownloaderTest {
boolean downloadFinished = false;
/* @Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}*/

@Test
public void testDownload() throws IOException {

// String url = "http://localhost:8080/test.jpg";
String url="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1489083998807&di=5bd3803161f80b5f9ef6f3277398c4ac&imgtype=0&src=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fbba1cd11728b47101489df48c0cec3fdfd03238b.jpg";

FileDownloader downloader = new FileDownloader(url);


ConnectionManager cm = new ConnectionManagerImpl();
downloader.setConnectionManager(cm);

downloader.setListener(new DownloadListener() {
@Override
public void notifyFinished() {
downloadFinished = true;
}

});


downloader.execute(5);

// 等待多线程下载程序执行完毕
while (!downloadFinished) {
try {
System.out.println("download is not finished,thread sleep five seconds");
//休眠5秒
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("the download finished !");



}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.coderising.download.api;

import java.io.IOException;
import java.net.HttpURLConnection;

public interface Connection {
/**
* 给定开始和结束位置, 读取数据, 返回值是字节数组
* @param startPos 开始位置, 从0开始
* @param endPos 结束位置
* @return
*/
public byte[] read(int startPos, int endPos) throws IOException;
/**
* 得到数据内容的长度
* @return
*/
public int getContentLength();

/**
* 关闭连接
*/
public void close();
public HttpURLConnection

getHttpURLConnection();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.coderising.download.api;

public class ConnectionException extends Exception {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.coderising.download.api;

import java.io.IOException;
import java.net.MalformedURLException;

public interface ConnectionManager {
/**
* 给定一个url , 打开一个连接
* @param url
* @return
*/
public Connection open(String url) throws ConnectionException, IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.coderising.download.api;

public interface DownloadListener {
public void notifyFinished();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.coderising.download.impl;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.Arrays;

import com.coderising.download.api.Connection;

public class ConnectionImpl implements Connection {
HttpURLConnection httpURLConnection;
static final int BUFFER_SIZE = 1024;
@Override
public byte[] read(int startPos, int endPos) throws IOException {
//byte[] data = new byte[endPos - startPos];
//httpURLConnection.setRequestProperty("Range", "bytes=" + startPos + "-" + endPos);
InputStream fis=httpURLConnection.getInputStream();
fis.skip(startPos);
byte[] buff = new byte[BUFFER_SIZE];
int totalLen = endPos - startPos + 1;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (baos.size() < totalLen) {
int len = fis.read(buff);
if (len < 0) {
break;
}
baos.write(buff,0,len);
}
if (baos.size() > totalLen) {
byte[] datas = baos.toByteArray();
return Arrays.copyOf(datas, totalLen);
}


return baos.toByteArray();
}

@Override
public int getContentLength() {
int length = httpURLConnection.getContentLength();
return length;
}

@Override
public void close() {
httpURLConnection.disconnect();

}

public void setHttpURLConnection(HttpURLConnection httpURLConnection) {
this.httpURLConnection = httpURLConnection;
}

public HttpURLConnection getHttpURLConnection() {
return httpURLConnection;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.coderising.download.impl;

import com.coderising.download.api.Connection;
import com.coderising.download.api.ConnectionException;
import com.coderising.download.api.ConnectionManager;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class ConnectionManagerImpl implements ConnectionManager {

@Override
public Connection open(String url) throws ConnectionException, IOException {
URL url1 = new URL(url);
HttpURLConnection conn = (HttpURLConnection) url1.openConnection();
conn.setRequestMethod("GET");
//conn.setRequestProperty();
conn.setConnectTimeout(10*1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
ConnectionImpl connection = new ConnectionImpl();
connection.setHttpURLConnection(conn);
//conn.connect();
//conn.getContentLength();
return connection;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<struts>
<action name="login" class="com.coderising.litestruts.LoginAction">
<result name="success">/jsp/homepage.jsp</result>
<result name="fail">/jsp/showLogin.jsp</result>
</action>
<action name="logout" class="com.coderising.litestruts.LogoutAction">
<result name= "success">/jsp/welcome.jsp</result>
<result name= "error">/jsp/error.jsp</result>
</action>
</struts>
Loading