Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
b838c4e4
Commit
b838c4e4
authored
Nov 08, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#34 Close reader in FileCacheQueueScheduler
parent
d48ccc67
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
13 deletions
+39
-13
release-note.md
release-note.md
+1
-1
BaiduBaike.java
...c/main/java/us/codecraft/webmagic/example/BaiduBaike.java
+8
-0
FileCacheQueueScheduler.java
...codecraft/webmagic/scheduler/FileCacheQueueScheduler.java
+30
-12
No files found.
release-note.md
View file @
b838c4e4
Release Notes
Release Notes
----
----
See
old
versions in
[
https://github.com/code4craft/webmagic/releases
](
https://github.com/code4craft/webmagic/releases
)
See
latest
versions in
[
https://github.com/code4craft/webmagic/releases
](
https://github.com/code4craft/webmagic/releases
)
*2012-9-4*
`version:0.3.0`
*2012-9-4*
`version:0.3.0`
...
...
webmagic-extension/src/main/java/us/codecraft/webmagic/example/BaiduBaike.java
View file @
b838c4e4
...
@@ -46,4 +46,12 @@ public class BaiduBaike{
...
@@ -46,4 +46,12 @@ public class BaiduBaike{
}
}
ooSpider
.
close
();
ooSpider
.
close
();
}
}
public
String
getName
()
{
return
name
;
}
public
String
getDescription
()
{
return
description
;
}
}
}
webmagic-extension/src/main/java/us/codecraft/webmagic/scheduler/FileCacheQueueScheduler.java
View file @
b838c4e4
package
us
.
codecraft
.
webmagic
.
scheduler
;
package
us
.
codecraft
.
webmagic
.
scheduler
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
import
us.codecraft.webmagic.Request
;
import
us.codecraft.webmagic.Request
;
...
@@ -94,6 +95,9 @@ public class FileCacheQueueScheduler implements Scheduler {
...
@@ -94,6 +95,9 @@ public class FileCacheQueueScheduler implements Scheduler {
urls
=
new
LinkedHashSet
<
String
>();
urls
=
new
LinkedHashSet
<
String
>();
readCursorFile
();
readCursorFile
();
readUrlFile
();
readUrlFile
();
}
catch
(
FileNotFoundException
e
)
{
//init
logger
.
info
(
"init cache file "
+
getFileName
(
fileUrlAllName
));
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
logger
.
error
(
"init file error"
,
e
);
logger
.
error
(
"init file error"
,
e
);
}
}
...
@@ -101,7 +105,9 @@ public class FileCacheQueueScheduler implements Scheduler {
...
@@ -101,7 +105,9 @@ public class FileCacheQueueScheduler implements Scheduler {
private
void
readUrlFile
()
throws
IOException
{
private
void
readUrlFile
()
throws
IOException
{
String
line
;
String
line
;
BufferedReader
fileUrlReader
=
new
BufferedReader
(
new
FileReader
(
getFileName
(
fileUrlAllName
)));
BufferedReader
fileUrlReader
=
null
;
try
{
fileUrlReader
=
new
BufferedReader
(
new
FileReader
(
getFileName
(
fileUrlAllName
)));
int
lineReaded
=
0
;
int
lineReaded
=
0
;
while
((
line
=
fileUrlReader
.
readLine
())
!=
null
)
{
while
((
line
=
fileUrlReader
.
readLine
())
!=
null
)
{
urls
.
add
(
line
.
trim
());
urls
.
add
(
line
.
trim
());
...
@@ -110,15 +116,27 @@ public class FileCacheQueueScheduler implements Scheduler {
...
@@ -110,15 +116,27 @@ public class FileCacheQueueScheduler implements Scheduler {
queue
.
add
(
new
Request
(
line
));
queue
.
add
(
new
Request
(
line
));
}
}
}
}
}
finally
{
if
(
fileUrlReader
!=
null
)
{
IOUtils
.
closeQuietly
(
fileUrlReader
);
}
}
}
}
private
void
readCursorFile
()
throws
IOException
{
private
void
readCursorFile
()
throws
IOException
{
BufferedReader
fileCursorReader
=
new
BufferedReader
(
new
FileReader
(
getFileName
(
fileCursor
)));
BufferedReader
fileCursorReader
=
null
;
try
{
new
BufferedReader
(
new
FileReader
(
getFileName
(
fileCursor
)));
String
line
;
String
line
;
//read the last number
//read the last number
while
((
line
=
fileCursorReader
.
readLine
())
!=
null
)
{
while
((
line
=
fileCursorReader
.
readLine
())
!=
null
)
{
cursor
=
new
AtomicInteger
(
NumberUtils
.
toInt
(
line
));
cursor
=
new
AtomicInteger
(
NumberUtils
.
toInt
(
line
));
}
}
}
finally
{
if
(
fileCursorReader
!=
null
)
{
IOUtils
.
closeQuietly
(
fileCursorReader
);
}
}
}
}
private
String
getFileName
(
String
filename
)
{
private
String
getFileName
(
String
filename
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment