Skip to content

Commit 33a3602

Browse files
authored
Merge pull request #28 from UglyBarnacle/filter_csv#27
filter for csv in zip archive #27
2 parents 8f467ce + e1afe48 commit 33a3602

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main/java/com/blueconic/browscap/UserAgentService.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ private UserAgentParser createParserWithFields(final Collection<BrowsCapField> f
7575
// http://browscap.org/version-number
7676
try (final InputStream zipStream = getCsvFileStream();
7777
final ZipInputStream zipIn = new ZipInputStream(zipStream)) {
78-
final ZipEntry entry = zipIn.getNextEntry();
79-
80-
// look for the first file that isn't a directory
78+
// look for the first file that isn't a directory and a .csv
8179
// that should be a BrowsCap .csv file
82-
if (!entry.isDirectory()) {
80+
ZipEntry entry = null;
81+
do {
82+
entry = zipIn.getNextEntry();
83+
} while (!(entry == null || entry.getName().endsWith(".csv")));
84+
if (!(entry == null || entry.isDirectory())) {
8385
return UserAgentFileParser.parse(new InputStreamReader(zipIn, UTF_8), fields);
8486
} else {
8587
throw new IOException(

0 commit comments

Comments
 (0)