FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-imdb-db-parser/ImdbReaderImpl.java at master · ns/java-imdb-db-parser · GitHub
ns
/
java-imdb-db-parser
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
java-imdb-db-parser
/
ImdbReaderImpl.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
177 lines (140 loc) · 5.36 KB
Breadcrumbs
java-imdb-db-parser
/
ImdbReaderImpl.java
Copy path
File metadata and controls
177 lines (140 loc) · 5.36 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import
java
.
util
.
List
;
import
javax
.
xml
.
parsers
.*;
import
javax
.
xml
.
transform
.*;
import
javax
.
xml
.
transform
.
dom
.*;
import
javax
.
xml
.
transform
.
stream
.*;
import
org
.
w3c
.
dom
.*;
import
java
.
util
.
ArrayList
;
import
java
.
io
.
BufferedOutputStream
;
import
java
.
io
.
FileOutputStream
;
import
java
.
io
.
OutputStream
;
class
ImdbReaderImpl
implements
ImdbReader
{
private
ArrayList
<
MovieData
>
movies
=
new
ArrayList
<
MovieData
>();
private
ArrayList
<
ActorData
>
actors
=
new
ArrayList
<
ActorData
>();
private
ArrayList
<
ActorData
>
actresses
=
new
ArrayList
<
ActorData
>();
public
void
newActors
(
final
List
<
ActorData
>
actorList
)
{
for
(
ActorData
actorData
:
actorList
)
{
if
(!
actorData
.
isActress
()) {
actors
.
add
(
actorData
);
}
else
{
actresses
.
add
(
actorData
);
}
}
}
public
void
newMovies
(
final
List
<
MovieData
>
movieList
)
{
for
(
MovieData
movieData
:
movieList
)
{
movies
.
add
(
movieData
);
}
}
public
void
writeMoviesXML
(
final
String
path
)
throws
Exception
{
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
documentBuilder
=
documentBuilderFactory
.
newDocumentBuilder
();
Document
document
=
documentBuilder
.
newDocument
();
Element
rootElement
=
document
.
createElement
(
"movies"
);
document
.
appendChild
(
rootElement
);
for
(
MovieData
m
:
movies
) {
String
element
=
"movie"
;
Element
em
=
document
.
createElement
(
element
);
String
elementTitle
=
"title"
;
Element
title
=
document
.
createElement
(
elementTitle
);
title
.
appendChild
(
document
.
createTextNode
(
m
.
getTitle
()));
String
elementYear
=
"year"
;
Element
year
=
document
.
createElement
(
elementYear
);
year
.
appendChild
(
document
.
createTextNode
(
m
.
getYear
() +
""
));
em
.
appendChild
(
title
);
em
.
appendChild
(
year
);
rootElement
.
appendChild
(
em
);
}
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
();
Transformer
transformer
=
transformerFactory
.
newTransformer
();
DOMSource
source
=
new
DOMSource
(
document
);
StreamResult
result
=
new
StreamResult
(
path
);
transformer
.
transform
(
source
,
result
);
}
public
void
writeActorsXML
(
final
String
path
)
throws
Exception
{
OutputStream
out
=
null
;
try
{
OutputStream
outFile
=
new
FileOutputStream
(
path
);
out
=
new
BufferedOutputStream
(
outFile
);
out
.
write
(
"<actors>"
.
getBytes
());
for
(
int
i
=
0
;
i
<
actors
.
size
();
i
++) {
ActorData
a
=
actors
.
get
(
i
);
out
.
write
(
"<actor>"
.
getBytes
());
out
.
write
(
"<name>"
.
getBytes
());
out
.
write
(
a
.
getName
().
getBytes
());
out
.
write
(
"</name>"
.
getBytes
());
out
.
write
(
"<roles>"
.
getBytes
());
for
(
RoleData
movieRole
:
a
.
getMovieRoles
() )
{
if
(
movieRole
==
null
||
movieRole
.
getRole
() ==
null
) {
}
else
{
out
.
write
(
"<role>"
.
getBytes
());
out
.
write
(
movieRole
.
getRole
().
getBytes
());
out
.
write
(
"</role>"
.
getBytes
());
}
out
.
write
(
"<movie>"
.
getBytes
());
out
.
write
(
movieRole
.
getTitle
().
getBytes
());
out
.
write
(
"</movie>"
.
getBytes
());
}
out
.
write
(
"</roles>"
.
getBytes
());
out
.
write
(
"</actor>"
.
getBytes
());
int
j
=
1000
;
if
(
i
%
j
==
0
) {
System
.
out
.
println
(
i
+
""
);
}
}
out
.
write
(
"</actors>"
.
getBytes
());
}
finally
{
if
(
out
!=
null
) {
out
.
close
();
}
}
}
public
void
writeActressesXML
(
final
String
path
)
throws
Exception
{
OutputStream
out
=
null
;
try
{
OutputStream
outFile
=
new
FileOutputStream
(
path
);
out
=
new
BufferedOutputStream
(
outFile
);
out
.
write
(
"<actresses>"
.
getBytes
());
for
(
int
i
=
0
;
i
<
actresses
.
size
();
i
++) {
ActorData
a
=
actresses
.
get
(
i
);
out
.
write
(
"<actress>"
.
getBytes
());
out
.
write
(
"<name>"
.
getBytes
());
out
.
write
(
a
.
getName
().
getBytes
());
out
.
write
(
"</name>"
.
getBytes
());
out
.
write
(
"<roles>"
.
getBytes
());
for
(
RoleData
movieRole
:
a
.
getMovieRoles
() )
{
if
(
movieRole
==
null
||
movieRole
.
getRole
() ==
null
) {
}
else
{
out
.
write
(
"<role>"
.
getBytes
());
out
.
write
(
movieRole
.
getRole
().
getBytes
());
out
.
write
(
"</role>"
.
getBytes
());
}
out
.
write
(
"<movie>"
.
getBytes
());
out
.
write
(
movieRole
.
getTitle
().
getBytes
());
out
.
write
(
"</movie>"
.
getBytes
());
}
out
.
write
(
"</roles>"
.
getBytes
());
out
.
write
(
"</actress>"
.
getBytes
());
int
j
=
1000
;
if
(
i
%
j
==
0
) {
System
.
out
.
println
(
i
+
""
);
}
}
out
.
write
(
"</actresses>"
.
getBytes
());
}
finally
{
if
(
out
!=
null
) {
out
.
close
();
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL