From 33306251d6ccd290532c006431db3ba4d561ca88 Mon Sep 17 00:00:00 2001 From: CodingPF Date: Mon, 30 Oct 2023 20:36:28 +0100 Subject: [PATCH] sonarcloud --- TestConfig.yaml | 2 - .../reader/FilmlistOldFormatReader.java | 58 +++++++------------ .../writer/FilmlistOldFormatWriter.java | 2 +- .../FilmlistOldFormatReaderTest.java | 2 +- .../FilmlistOldFormatWriterTest.java | 2 +- 5 files changed, 23 insertions(+), 43 deletions(-) delete mode 100644 TestConfig.yaml diff --git a/TestConfig.yaml b/TestConfig.yaml deleted file mode 100644 index 9b389a4c..00000000 --- a/TestConfig.yaml +++ /dev/null @@ -1,2 +0,0 @@ -valueWithDefault: TestValue -valueWithoutDefault: Some other test value diff --git a/src/main/java/de/mediathekview/mlib/filmlisten/reader/FilmlistOldFormatReader.java b/src/main/java/de/mediathekview/mlib/filmlisten/reader/FilmlistOldFormatReader.java index 042765e1..155efcf9 100644 --- a/src/main/java/de/mediathekview/mlib/filmlisten/reader/FilmlistOldFormatReader.java +++ b/src/main/java/de/mediathekview/mlib/filmlisten/reader/FilmlistOldFormatReader.java @@ -14,8 +14,6 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -31,7 +29,6 @@ import java.time.format.DateTimeParseException; import java.util.*; -import static java.lang.String.format; import static java.time.format.FormatStyle.MEDIUM; public class FilmlistOldFormatReader extends AbstractFilmlistReader { @@ -47,23 +44,12 @@ public class FilmlistOldFormatReader extends AbstractFilmlistReader { private String sender = ""; private String thema = ""; private String debug = ""; - int cnt = 0; + private int cnt = 0; - public static void main(String[] args) throws FileNotFoundException { - new FilmlistOldFormatReader().read(new FileInputStream("C:/Users/steph/Desktop/Mediathek/oldFormat/Filmliste-akt-oldformat.json")); - } - @Override public Optional read(InputStream aInputStream) { long start = System.currentTimeMillis(); - /* - String bigFile = "C:/Users/steph/Desktop/Mediathek/oldFormat/Filmliste-akt-oldformat.json"; - String medium = "C:/Users/steph/Desktop/Mediathek/oldFormat/Filmlist - Kopie.json"; - String smallFile = "C:/Users/steph/Desktop/Mediathek/oldFormat/Filmlist.json"; - String broken = "C:/Users/steph/Desktop/Mediathek/oldFormat/Filmlist-broken.json"; - */ Filmlist filmlist = new Filmlist(); - int cnt = 0; debug = "LINE " + cnt; // @@ -74,10 +60,10 @@ public Optional read(InputStream aInputStream) { while (jsonReader.peek() != JsonToken.END_OBJECT) { try { - readRecrod(jsonReader).ifPresent(aFilm -> {filmlist.add(aFilm);}); + readRecrod(jsonReader).ifPresent(filmlist::add); } catch (Exception e) { if (!recoverParser(jsonReader)) { - System.out.println("error after " + ((System.currentTimeMillis()-start)/1000) + " on " + cnt + " elements (" + filmlist.getFilms().size()+")"); + LOG.error("error after {} sec on element {} of {} elements", ((System.currentTimeMillis()-start)/1000), cnt, filmlist.getFilms().size()); throw(e); } } @@ -87,7 +73,7 @@ public Optional read(InputStream aInputStream) { LOG.error(e); return Optional.of(filmlist); } - LOG.debug("done reading in " + ((System.currentTimeMillis()-start)/1000) + "sec for " + cnt + " elements (" + filmlist.getFilms().size()+")"); + LOG.debug("done reading in {} sec for {} elements resulting in {} elements", ((System.currentTimeMillis()-start)/1000), cnt, filmlist.getFilms().size()); return Optional.of(filmlist); } @@ -102,7 +88,7 @@ private boolean recoverParser(JsonReader jsonReader) { jsonReader.endArray(); return true; } catch (Exception e) { - // TODO: handle exception + LOG.error(e); } return false; } @@ -126,7 +112,7 @@ private LocalDateTime readHeader01CreationDate(String in) { try { return LocalDateTime.parse(in, FILMLIST_CREATIONDATE_PATTERN); } catch (DateTimeParseException e) { - LOG.warn(format("Error readHeader01CreationDate format string %s on line %s throws %s", in, debug, e )); + LOG.warn("Error readHeader01CreationDate format string {} on line {} thorws {}", in, debug, e ); } } return LocalDateTime.now(); @@ -138,7 +124,7 @@ private UUID readHeader05Hash(String in) { try { return UUID.fromString(in); } catch (Exception e) { - LOG.warn("Error readHeader05Hash format string " + in); + LOG.warn("Error readHeader05Hash format string {}", in); } return UUID.randomUUID(); } @@ -167,7 +153,7 @@ private void headerColumns(JsonReader jsonReader) throws IOException { jsonReader.nextString(); // Geo jsonReader.nextString(); // neu jsonReader.endArray(); - }; + } private Optional readRecrod(JsonReader jsonReader) throws IOException { cnt++; @@ -226,22 +212,18 @@ private Optional readRecrod(JsonReader jsonReader) throws IOException { if (f.getUrls().size() > 0) { return Optional.of(f); } else { - LOG.warn(format("Error no urls for film %s", debug)); + LOG.warn("Error no urls for film {}", debug); return Optional.empty(); } } private Map generateUrls(URL urlNormal, String urlSmall, String urlHd, long size) { - Map urls = new HashMap<>(); + Map urls = new EnumMap<>(Resolution.class); if (urlNormal != null) { urls.put(Resolution.NORMAL, new FilmUrl(urlNormal, size)); - rebuildUrl(urlNormal, urlSmall).ifPresent( u -> { - urls.put(Resolution.SMALL, new FilmUrl(u, 0L)); - }); - rebuildUrl(urlNormal, urlHd).ifPresent( u -> { - urls.put(Resolution.HD, new FilmUrl(u, 0L)); - }); + rebuildUrl(urlNormal, urlSmall).ifPresent( u -> urls.put(Resolution.SMALL, new FilmUrl(u, 0L))); + rebuildUrl(urlNormal, urlHd).ifPresent( u -> urls.put(Resolution.HD, new FilmUrl(u, 0L))); } return urls; } @@ -256,7 +238,7 @@ private Optional rebuildUrl(URL urlNromal, String targetUrl) { } return Optional.of(new URL(targetUrl)); } catch (Exception e) { - LOG.warn(format("Error rebuildUrl format string %s on line %s throws %s", targetUrl, debug, e )); + LOG.warn("Error rebuildUrl format string {} on line {} throws {}", targetUrl, debug, e ); } } return Optional.empty(); @@ -289,7 +271,7 @@ protected LocalDate readRecord04Datum(String in) { try { return LocalDate.parse(in, DATE_FORMATTER); } catch (DateTimeParseException e) { - LOG.warn(format("Error readRecord04Datum format string %s on line %s throws %s", in, debug, e )); + LOG.warn("Error readRecord04Datum format string {} on line {} throws {}", in, debug, e ); } } return DEFAULT_DATE; @@ -300,7 +282,7 @@ protected LocalTime readRecord05Zeit(String in) { try { return LocalTime.parse(in, TIME_FORMATTER); } catch (DateTimeParseException e) { - LOG.warn(format("Error readRecord05Zeit format string %s on line %s throws %s", in, debug, e )); + LOG.warn("Error readRecord05Zeit format string {} on line {} throws {}", in, debug, e ); } } return LocalTime.MIDNIGHT; @@ -311,7 +293,7 @@ protected Duration readRecord06Dauer(String in) { try { return Duration.between(LocalTime.MIDNIGHT, LocalTime.parse(in)); } catch (DateTimeException | ArithmeticException e) { - LOG.info(format("Error readRecord06Dauer format string %s on line %s throws %s", in, debug, e )); + LOG.warn("Error readRecord06Dauer format string {} on line {} throws {}", in, debug, e ); } } return Duration.ZERO; @@ -322,7 +304,7 @@ protected long readRecord07Groesse(String in) { try { return Long.parseLong(in)*1024; // oldFilmlist format is MB - new DM is KB } catch (NumberFormatException e) { - LOG.warn(format("Error readRecord07Groesse format string %s on line %s throws %s", in, debug, e )); + LOG.warn("Error readRecord07Groesse format string {} on line {} throws {}", in, debug, e ); } } return 0L; @@ -337,7 +319,7 @@ protected URL readRecord09Url(String in) { try { return new URL(in); } catch (final MalformedURLException e) { - LOG.warn(format("Error readRecord09Url format string %s on line %s throws %s", in, debug, e )); + LOG.warn("Error readRecord09Url format string {} on line {} throws {}", in, debug, e ); } } return null; @@ -348,7 +330,7 @@ protected URL readRecord10Website(String in) { try { return new URL(in); } catch (final MalformedURLException e) { - LOG.warn(format("Error readRecord10Website format string %s on line %s throws %s", in, debug, e )); + LOG.warn("Error readRecord10Website format string {} on line {} throws {}", in, debug, e ); } } return null; @@ -359,7 +341,7 @@ protected URL readRecord11Untertitel(String in) { try { return new URL(in); } catch (final MalformedURLException e) { - LOG.warn(format("Error readRecord11Untertitel format string %s on line %s throws %s", in, debug, e )); + LOG.warn("Error readRecord11Untertitel format string {} on line {} throws {}", in, debug, e ); } } return null; diff --git a/src/main/java/de/mediathekview/mlib/filmlisten/writer/FilmlistOldFormatWriter.java b/src/main/java/de/mediathekview/mlib/filmlisten/writer/FilmlistOldFormatWriter.java index dc9647cf..c17d2a46 100644 --- a/src/main/java/de/mediathekview/mlib/filmlisten/writer/FilmlistOldFormatWriter.java +++ b/src/main/java/de/mediathekview/mlib/filmlisten/writer/FilmlistOldFormatWriter.java @@ -62,7 +62,7 @@ public boolean write(Filmlist filmlist, OutputStream outputStream) throws IOExce }); jsonWriter.endObject(); jsonWriter.flush(); - LOG.info("done writting in " + ((System.currentTimeMillis()-start)/1000) + "sec for " + cnt + " elements (" + filmlist.getFilms().size()+")"); + LOG.info("done writting in {} sec reading {} elements resulting in {} elements", ((System.currentTimeMillis()-start)/1000), cnt, filmlist.getFilms().size()); } catch (IOException e) { LOG.error(e); return false; diff --git a/src/test/java/de/mediathekview/mlib/filmlisten/FilmlistOldFormatReaderTest.java b/src/test/java/de/mediathekview/mlib/filmlisten/FilmlistOldFormatReaderTest.java index 9ada0f36..9cda1dae 100644 --- a/src/test/java/de/mediathekview/mlib/filmlisten/FilmlistOldFormatReaderTest.java +++ b/src/test/java/de/mediathekview/mlib/filmlisten/FilmlistOldFormatReaderTest.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; -public class FilmlistOldFormatReaderTest { +class FilmlistOldFormatReaderTest { @Test void readFilmlistOldFormatIncludingBrokenRecords() diff --git a/src/test/java/de/mediathekview/mlib/filmlisten/FilmlistOldFormatWriterTest.java b/src/test/java/de/mediathekview/mlib/filmlisten/FilmlistOldFormatWriterTest.java index 0f01bf54..25138a32 100644 --- a/src/test/java/de/mediathekview/mlib/filmlisten/FilmlistOldFormatWriterTest.java +++ b/src/test/java/de/mediathekview/mlib/filmlisten/FilmlistOldFormatWriterTest.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -public class FilmlistOldFormatWriterTest { +class FilmlistOldFormatWriterTest { @TempDir Path tempDir;