Skip to content

Commit

Permalink
sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
codingPF committed Oct 30, 2023
1 parent 378225d commit 3330625
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 43 deletions.
2 changes: 0 additions & 2 deletions TestConfig.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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<Filmlist> 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;
//

Expand All @@ -74,10 +60,10 @@ public Optional<Filmlist> 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);
}
}
Expand All @@ -87,7 +73,7 @@ public Optional<Filmlist> 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);

}
Expand All @@ -102,7 +88,7 @@ private boolean recoverParser(JsonReader jsonReader) {
jsonReader.endArray();
return true;
} catch (Exception e) {
// TODO: handle exception
LOG.error(e);
}
return false;
}
Expand All @@ -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();
Expand All @@ -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();
}
Expand Down Expand Up @@ -167,7 +153,7 @@ private void headerColumns(JsonReader jsonReader) throws IOException {
jsonReader.nextString(); // Geo
jsonReader.nextString(); // neu
jsonReader.endArray();
};
}

private Optional<Film> readRecrod(JsonReader jsonReader) throws IOException {
cnt++;
Expand Down Expand Up @@ -226,22 +212,18 @@ private Optional<Film> 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<Resolution,FilmUrl> generateUrls(URL urlNormal, String urlSmall, String urlHd, long size) {
Map<Resolution,FilmUrl> urls = new HashMap<>();
Map<Resolution,FilmUrl> 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;
}
Expand All @@ -256,7 +238,7 @@ private Optional<URL> 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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import org.junit.jupiter.api.Test;

public class FilmlistOldFormatReaderTest {
class FilmlistOldFormatReaderTest {

@Test
void readFilmlistOldFormatIncludingBrokenRecords()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3330625

Please sign in to comment.