Исправление: добавлена ошибка неверного формата
This commit is contained in:
parent
d403b80e3a
commit
f0f29934b4
18
src/main/java/FileFormatException.java
Normal file
18
src/main/java/FileFormatException.java
Normal file
@ -0,0 +1,18 @@
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileFormatException extends IOException {
|
||||
public FileFormatException() {
|
||||
}
|
||||
|
||||
public FileFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public FileFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public FileFormatException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -67,14 +67,14 @@ public class MapsCollection {
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadData(String filename) throws Exception {
|
||||
public void LoadData(String filename) throws IOException {
|
||||
File f = new File(filename);
|
||||
if (!f.exists()) {
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
if (!reader.readLine().contains("MapsCollection"))
|
||||
throw new Exception("Формат данных в файле не правильный");
|
||||
throw new FileFormatException("Формат данных в файле не правильный");
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
var elem = line.split(String.valueOf(separatorDict), -1);
|
||||
@ -93,8 +93,6 @@ public class MapsCollection {
|
||||
_mapStorages.put(elem[0], new MapWithSetArmoredCarsGeneric<>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages.get(elem[0]).LoadData(elem[2].split(String.valueOf(separatorData)));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,14 +117,14 @@ public class MapsCollection {
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadDataMap(String filename) throws Exception{
|
||||
public void LoadDataMap(String filename) throws IOException{
|
||||
File f = new File(filename);
|
||||
if (!f.exists()) {
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
if (!reader.readLine().contains("One Map"))
|
||||
throw new Exception("Формат данных в файле не правильный");
|
||||
throw new FileFormatException("Формат данных в файле не правильный");
|
||||
String line = reader.readLine();
|
||||
var elem = line.split(String.valueOf(separatorDict), -1);
|
||||
AbstractMap map = null;
|
||||
@ -147,8 +145,6 @@ public class MapsCollection {
|
||||
else
|
||||
_mapStorages.put(elem[0], new MapWithSetArmoredCarsGeneric<>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages.get(elem[0]).LoadData(elem[2].split(String.valueOf(separatorData)));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user