Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,20 @@ public abstract class GtfsInput implements Closeable {
*/
public static GtfsInput createFromPath(Path path, NoticeContainer noticeContainer)
throws IOException {
ZipFile zipFile;
if (!Files.exists(path)) {
throw new FileNotFoundException(path.toString());
}
if (Files.isDirectory(path)) {
return new GtfsUnarchivedInput(path);
}
String fileName = path.getFileName().toString().replace(".zip", "");
if (path.getFileSystem().equals(FileSystems.getDefault())) {
// Read from a local ZIP file.
zipFile = new ZipFile(path.toFile());
if (hasSubfolderWithGtfsFile(path)) {
noticeContainer.addValidationNotice(
new InvalidInputFilesInSubfolderNotice(invalidInputMessage));
}
ZipFile zipFile =
path.getFileSystem().equals(FileSystems.getDefault())
// Read from a local ZIP file.
? new ZipFile(path.toFile())
// Load a remote ZIP file to memory.
: new ZipFile(new SeekableInMemoryByteChannel(Files.readAllBytes(path)));

return new GtfsZipFileInput(zipFile, fileName);
}
// Load a remote ZIP file to memory.
zipFile = new ZipFile(new SeekableInMemoryByteChannel(Files.readAllBytes(path)));
if (hasSubfolderWithGtfsFile(path)) {
noticeContainer.addValidationNotice(
new InvalidInputFilesInSubfolderNotice(invalidInputMessage));
Expand Down Expand Up @@ -98,23 +92,13 @@ public static boolean hasSubfolderWithGtfsFile(Path path) throws IOException {
*/
private static boolean containsGtfsFileInSubfolder(ZipInputStream zipInputStream)
throws IOException {
boolean containsSubfolder = false;
String subfolder = null;
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
String entryName = entry.getName();

if (entry.isDirectory()) {
subfolder = entryName;
containsSubfolder = true;
}
if (containsSubfolder && entryName.contains(subfolder) && entryName.endsWith(".txt")) {
String[] files = entryName.split("/");
String lastElement = files[files.length - 1];

if (GtfsFiles.containsGtfsFile(lastElement)) {
return true;
}
String[] nameParts = entry.getName().split("/");
boolean isInSubfolder = nameParts.length > 1;
boolean isGtfsFile = GtfsFiles.containsGtfsFile(nameParts[nameParts.length - 1]);
if (isInSubfolder && isGtfsFile) {
return true;
}
}
return false;
Expand Down
Loading