Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Queue
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Labrador
Queue
Merge requests
!195
Resolve "ArrayIndexOutOfBoundsException with incorrect CSV input"
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Resolve "ArrayIndexOutOfBoundsException with incorrect CSV input"
264-arrayindexoutofboundsexception-with-incorrect-csv-input
into
development
Overview
6
Commits
2
Pipelines
0
Changes
2
All threads resolved!
Show all comments
Merged
Resolve "ArrayIndexOutOfBoundsException with incorrect CSV input"
Otto Visser
requested to merge
264-arrayindexoutofboundsexception-with-incorrect-csv-input
into
development
Oct 31, 2019
Overview
6
Commits
2
Pipelines
0
Changes
2
All threads resolved!
Show all comments
Closes
#264 (closed)
Edited
Nov 4, 2019
by
Otto Visser
0
0
Merge request reports
Compare
development
version 1
feda079e
Oct 31, 2019
development (base)
and
latest version
latest version
b0835144
2 commits,
Nov 1, 2019
version 1
feda079e
1 commit,
Oct 31, 2019
2 files
+
18
−
18
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
src/main/java/nl/tudelft/ewi/queue/helper/CsvUserHelper.java
+
15
−
18
View file @ b0835144
Edit in single-file editor
Open in Web IDE
Show full file
@@ -15,8 +15,7 @@
*/
package
nl.tudelft.ewi.queue.helper
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.Scanner
;
@@ -45,24 +44,22 @@ public class CsvUserHelper {
}
public
static
ArrayList
<
CsvUserHelper
>
readCsv
(
MultipartFile
csvFile
)
throws
IOException
{
InputStream
content
=
csvFile
.
getInputStream
()
;
Scanner
scanner
=
new
Scanner
(
content
).
useDelimiter
(
"\\A"
);
ArrayList
<
CsvUserHelper
>
csvUserHelpersSet
=
new
ArrayList
<>()
;
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
csvFile
.
getInputStream
()
)))
{
if
(
csvFile
.
isEmpty
())
return
null
;
String
csv
=
""
;
if
(
scanner
.
hasNext
())
{
csv
=
scanner
.
next
();
}
String
[]
lines
=
csv
.
split
(
"\n"
);
for
(
String
line
:
lines
)
{
String
[]
currLine
=
line
.
split
(
","
);
if
(
currLine
[
1
].
contains
(
"\r"
))
{
currLine
[
1
]
=
currLine
[
1
].
substring
(
0
,
currLine
[
1
].
length
()
-
1
);
ArrayList
<
CsvUserHelper
>
csvUserHelpersSet
=
new
ArrayList
<>();
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
// not accepting comma as we have students with a comma in their last name...
// TODO switch to a proper CSV library to handle this better
String
[]
currLine
=
line
.
split
(
"[;\t]"
);
csvUserHelpersSet
.
add
(
new
CsvUserHelper
(
currLine
[
0
],
DefaultRole
.
valueOfExt
(
currLine
[
1
])));
}
csvUserHelpersSet
.
add
(
new
CsvUserHelper
(
currLine
[
0
],
DefaultRole
.
valueOfExt
(
currLine
[
1
])));
return
csvUserHelpersSet
;
}
content
.
close
();
return
csvUserHelpersSet
;
}
}
Loading