From f0f29934b4b55c0669ce1630ff17277b8b1ef243 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Fri, 9 Dec 2022 09:18:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=B2=D0=B5=D1=80=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/FileFormatException.java | 18 ++++++++++++++++++ src/main/java/MapsCollection.java | 12 ++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 src/main/java/FileFormatException.java diff --git a/src/main/java/FileFormatException.java b/src/main/java/FileFormatException.java new file mode 100644 index 0000000..035761b --- /dev/null +++ b/src/main/java/FileFormatException.java @@ -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); + } +} diff --git a/src/main/java/MapsCollection.java b/src/main/java/MapsCollection.java index da96dac..6eb9c19 100644 --- a/src/main/java/MapsCollection.java +++ b/src/main/java/MapsCollection.java @@ -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(); } } }