Skip to content
This repository has been archived by the owner on Nov 1, 2019. It is now read-only.

Commit

Permalink
dev合并到master分支 # 请输入一个提交信息以解释此合并的必要性,尤其是将一个更新后的上游分支 # 合并到主题分支。 # # 以 …
Browse files Browse the repository at this point in the history
…'#' 开头的行将被忽略,而且空提交说明将会终止提交。
  • Loading branch information
bruce3x committed Jan 15, 2016
2 parents dbdf0ff + 62bc511 commit 76f3336
Show file tree
Hide file tree
Showing 23 changed files with 472 additions and 399 deletions.
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: me.brucezz.crawler.Main

79 changes: 0 additions & 79 deletions src/db/BarrageDao.java

This file was deleted.

84 changes: 0 additions & 84 deletions src/db/DBUtil.java

This file was deleted.

11 changes: 6 additions & 5 deletions src/Main.java → src/me/brucezz/crawler/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package me.brucezz.crawler;

import config.Config;
import thread.CrawlerThread;
import me.brucezz.crawler.config.Config;
import me.brucezz.crawler.thread.CrawlerThread;

import java.util.Set;

/**
* Created by zero on 2016/01/04.
* Douyu
* Created by Brucezz on 2016/01/04.
* DouyuCrawler
*/
public class Main {
public static void main(String[] args) {
Expand All @@ -16,7 +17,7 @@ public static void main(String[] args) {
Set<String> nameSet = Config.ROOM_MAP.keySet();

for (String name : nameSet) {
new Thread(new CrawlerThread(name, Config.ROOM_MAP.get(name))).start();
new Thread(new CrawlerThread(name, Config.ROOM_MAP.get(name)), "Crawler-"+name).start();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package model;
package me.brucezz.crawler.bean;

import java.util.Date;

/**
* Created by zero on 2016/01/03.
* Douyu
* Created by Brucezz on 2016/01/03.
* DouyuCrawler
*/
public class Barrage {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package model;
package me.brucezz.crawler.bean;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;

/**
* Created by zero on 2016/01/03.
* Douyu
* Created by Brucezz on 2016/01/03.
* DouyuCrawler
*/
public class Message {

Expand All @@ -33,6 +33,9 @@ public Message(String content) {
end = new int[]{0x00};
}

/**
* 计算消息体长度
*/
private int calcMessageLength(String content) {
return 4 + 4 + (content == null ? 0 : content.length()) + 1;
}
Expand Down Expand Up @@ -88,14 +91,13 @@ public String toString() {
'}';
}

private ByteArrayOutputStream baos;

/**
* 把Message对象填充到ByteArrayOutputStream里
*
* @throws IOException
* 将Message对象转化为字节数组
*/
public void putIntoStream(ByteArrayOutputStream baos) throws IOException {
if (baos == null) return;

public byte[] getBytes() throws IOException {
if (baos == null ) baos = new ByteArrayOutputStream();
baos.reset();

for (int b : length) baos.write(b);
Expand All @@ -104,5 +106,6 @@ public void putIntoStream(ByteArrayOutputStream baos) throws IOException {
if (content != null) baos.write(content.getBytes());
for (int b : end) baos.write(b);

return baos.toByteArray();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package model;
package me.brucezz.crawler.bean;

/**
* Created by zero on 2016/01/05.
* Douyu
* Created by Brucezz on 2016/01/05.
* DouyuCrawler
*/
public class Request {
/**
* 程序需要发送的各种请求正文
*/

public static String gid(int roomId, String devid, String rt, String vk) {

return String.format("type@=loginreq/username@=/ct@=0/password@=/roomid@=%d/devid@=%s/rt@=%s/vk@=%s/ver@=20150929/", roomId, devid, rt, vk);
}

Expand All @@ -21,6 +23,5 @@ public static String joinGroup(int rid, int gid) {

public static String keepLive(int tick) {
return String.format("type@=keeplive/tick@=%d/", tick);
// return String.format("type@=mrkl/", tick);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package model;
package me.brucezz.crawler.bean;


/**
* Created by zero on 2016/01/05.
* Douyu
* Created by Brucezz on 2016/01/05.
* DouyuCrawler
*/
public class ServerInfo {
private String host;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package config;
package me.brucezz.crawler.config;


import util.LogUtil;
import me.brucezz.crawler.util.LogUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
* Created by zero on 2016/01/04.
* Douyu
* Created by Brucezz on 2016/01/04.
* DouyuCrawler
*/
public class Config {
private static final String PROPERTIES_NAME = "conf.properties";
public static boolean loadSuccess = false;

public static boolean DEBUG_MODE = true;

public static boolean DB_ENABLE = false;
public static String DB_NAME = null;
public static String DB_USERNAME = null;
public static String DB_PASSWORD = null;

/**
* 键 房间简称( 即room.url.XXX中的XXX )
* 值 房间地址
Expand All @@ -34,20 +42,23 @@ public class Config {

DEBUG_MODE = Boolean.parseBoolean(properties.getProperty("debug"));

DB_ENABLE = Boolean.parseBoolean(properties.getProperty("db.enable"));
DB_NAME = properties.getProperty("db.name");
DB_USERNAME = properties.getProperty("db.username");
DB_PASSWORD = properties.getProperty("db.password");

Set<Object> objects = properties.keySet();
for (Object object : objects) {
String key = (String) object;
if (key.startsWith("room.url.")) {
String name = key.substring(9).trim();
if (name.length() > 0)
ROOM_MAP.put(name, properties.getProperty(key));
}
String key = ((String) object).trim();
if (!key.startsWith("room.url.") || key.length() <= 9) continue;

ROOM_MAP.put(key.substring(9), properties.getProperty(key));
}

loadSuccess = true;
LogUtil.i("读取配置信息成功!");

displayConfig();
showConfig();

} catch (Exception e) {
LogUtil.e(e.toString());
Expand All @@ -63,13 +74,14 @@ public class Config {
}
}

private static void displayConfig() {
private static void showConfig() {
LogUtil.d("Config", "----------------------------------------------------------------");

LogUtil.d("Config", "DEBUG_MODE: " + DEBUG_MODE);
LogUtil.d("Config", "DB_ENABLE: " + DB_ENABLE);
Set<String> nameSet = ROOM_MAP.keySet();
for (String name : nameSet) {
LogUtil.d("Config", "ROOM_URL: " + name +" >> "+ROOM_MAP.get(name));
LogUtil.d("Config", "ROOM_URL: " + name + " >> " + ROOM_MAP.get(name));
}

LogUtil.d("Config", "----------------------------------------------------------------");
Expand Down
Loading

0 comments on commit 76f3336

Please sign in to comment.