Skip to content

Commit a4e9fc7

Browse files
committed
乱七八糟的改了不少,心烦意乱,妈的睡觉
1 parent 68ec518 commit a4e9fc7

File tree

11 files changed

+79
-11
lines changed

11 files changed

+79
-11
lines changed

cockroach-core/src/main/java/com/zhangyingwei/cockroach/executer/response/TaskErrorResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public TaskErrorResponse(TaskResponse response) throws IOException {
2222
}
2323

2424
@Override
25-
public String getContent() throws IOException {
25+
public ResponseContent getContent() throws IOException {
2626
return this.response.getContent();
2727
}
2828

cockroach-core/src/main/java/com/zhangyingwei/cockroach/executer/response/TaskResponse.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public TaskResponse setTask(Task task) {
6161
return this;
6262
}
6363

64+
public TaskResponse charset(String charset) {
65+
this.content.charset(charset);
66+
return this;
67+
}
68+
6469
public Elements select(String cssSelect) throws IOException {
6570
return this.content.toDocument().select(cssSelect);
6671
}

cockroach-core/src/main/java/com/zhangyingwei/cockroach/store/DescribeStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void store(TaskResponse response) throws Exception {
1313
logger.info("==================desc=================");
1414
logger.info(String.format("task id: %s",response.getTask().getId()));
1515
logger.info(String.format("thread name: %s",Thread.currentThread().getName()));
16-
logger.info(String.format("bytes: %d",response.getContentBytes().length));
16+
logger.info(String.format("bytes: %d",response.getContent().bytes().length));
1717
logger.info("=======================================");
1818
}
1919
}

cockroach-samples/cockroach-samples.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2+
<module type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.zhangyingwei.cockroach.samples.juejin;
2+
3+
import com.zhangyingwei.cockroach.CockroachApplication;
4+
import com.zhangyingwei.cockroach.annotation.AppName;
5+
import com.zhangyingwei.cockroach.annotation.EnableAutoConfiguration;
6+
import com.zhangyingwei.cockroach.annotation.Store;
7+
import com.zhangyingwei.cockroach.annotation.ThreadConfig;
8+
import com.zhangyingwei.cockroach.executer.task.Task;
9+
import com.zhangyingwei.cockroach.queue.CockroachQueue;
10+
import com.zhangyingwei.cockroach.queue.TaskQueue;
11+
import com.zhangyingwei.cockroach.samples.juejin.store.JueJinStore;
12+
13+
/**
14+
* @author: zhangyw
15+
* @date: 2018/2/26
16+
* @time: 下午8:43
17+
* @desc:
18+
*/
19+
20+
@EnableAutoConfiguration
21+
@AppName("掘金")
22+
@ThreadConfig(num = 1,sleep = 500)
23+
@Store(JueJinStore.class)
24+
public class JueJinApplication {
25+
public static void main(String[] args) throws Exception {
26+
CockroachQueue queue = TaskQueue.of();
27+
queue.push(new Task("https://timeline-merger-ms.juejin.im/v1/get_entry_by_rank?src=web&uid=58368a0461ff4b475bd600bc&device_id=1519648660286&token=eyJhY2Nlc3NfdG9rZW4iOiJqQVlaSWxIN1U3aGJnV3YzIiwicmVmcmVzaF90b2tlbiI6IlV5RnA3eDFaVWp4bk9jRVEiLCJ0b2tlbl90eXBlIjoibWFjIiwiZXhwaXJlX2luIjoyNTkyMDAwfQ%3D%3D&limit=20&category=all&recomment=1"));
28+
CockroachApplication.run(JueJinApplication.class, queue);
29+
}
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.zhangyingwei.cockroach.samples.juejin.store;
2+
3+
import com.zhangyingwei.cockroach.executer.response.TaskResponse;
4+
import com.zhangyingwei.cockroach.store.IStore;
5+
import net.sf.json.JSONObject;
6+
7+
/**
8+
* @author: zhangyw
9+
* @date: 2018/2/26
10+
* @time: 下午8:49
11+
* @desc:
12+
*/
13+
public class JueJinStore implements IStore{
14+
@Override
15+
public void store(TaskResponse response) throws Exception {
16+
response.getContent().toJsonObject()
17+
.getJSONObject("d")
18+
.getJSONArray("entrylist")
19+
.forEach(item -> {
20+
JSONObject itemJson = JSONObject.fromObject(item);
21+
System.out.println(itemJson.getString("title"));
22+
});
23+
}
24+
}

cockroach-test/cockroach-test.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2+
<module type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />

cockroach-test/src/test/java/com/zhangyingwei/cockroach/store/ImageStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ImageStore implements IStore {
1111

1212
@Override
1313
public void store(TaskResponse response) throws Exception {
14-
byte[] bytes = response.getContentBytes();
14+
byte[] bytes = response.getContent().bytes();
1515
File file = new File("image.jpeg");
1616
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(file));
1717
outputStream.write(bytes);

cockroach-test/src/test/java/com/zhangyingwei/cockroach/store/MeiZhiStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void store(TaskResponse response) throws Exception {
3232
});
3333
} else {
3434
File file = new File("D://meizitu/"+UUID.randomUUID()+".png");
35-
byte[] bytes = response.getContentBytes();
35+
byte[] bytes = response.getContent().bytes();
3636
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(file));
3737
outputStream.write(bytes);
3838
outputStream.close();

cockroach-test/src/test/java/com/zhangyingwei/cockroach/store/ZhiHuMeiZhi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void store(TaskResponse response) throws Exception {
3232
});
3333
} else {
3434
File file = new File("D://zhihumeizitu2/"+ UUID.randomUUID()+".jpg");
35-
byte[] bytes = response.getContentBytes();
35+
byte[] bytes = response.getContent().bytes();
3636
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(file));
3737
outputStream.write(bytes);
3838
outputStream.close();

0 commit comments

Comments
 (0)