From 845009d38f55e0bf2501d9de870d0d4feb350edd Mon Sep 17 00:00:00 2001 From: pidoubleyou Date: Mon, 9 Oct 2017 22:02:29 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Fix=20Pr=C3=BCfung=20auf=20vorhandenes=20xz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java b/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java index 68ee0398..5227cd82 100644 --- a/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java +++ b/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java @@ -167,8 +167,9 @@ private Path testNativeXz() { Path xz = null; for (String path : paths) { - xz = Paths.get(path); - if (Files.isExecutable(xz)) { + Path temp = Paths.get(path); + if (Files.isExecutable(temp)) { + xz = temp; break; } } From 4ca1c058b36f9ded8ad522b3f866b9529df63516 Mon Sep 17 00:00:00 2001 From: pidoubleyou Date: Mon, 9 Oct 2017 22:13:02 +0200 Subject: [PATCH 2/4] Rethrow Exception in interner Logik und Logging --- .../de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java b/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java index 5227cd82..b35b4a90 100644 --- a/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java +++ b/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java @@ -91,6 +91,7 @@ public void filmlisteSchreibenJsonCompressed(String datei, ListeFilme listeFilme Files.deleteIfExists(Paths.get(tempFile)); } catch (IOException | InterruptedException ex) { + Log.errorLog(846930144, ex); Log.sysLog("Komprimieren fehlgeschlagen"); } } @@ -185,7 +186,8 @@ private void compressFile(String inputName, String outputName) throws IOExceptio final WritableByteChannel outputChannel = Channels.newChannel(output)) { fastChannelCopy(inputChannel, outputChannel); - } catch (IOException ignored) { + } catch (IOException ex) { + throw ex; } } } From dcb6a8e25c70a62293db187422f9c113b90d0c74 Mon Sep 17 00:00:00 2001 From: pidoubleyou Date: Mon, 9 Oct 2017 22:41:51 +0200 Subject: [PATCH 3/4] =?UTF-8?q?R=C3=BCckgabewert=20f=C3=BCr=20filmlisteSch?= =?UTF-8?q?reiben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mlib/filmlisten/WriteFilmlistJson.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java b/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java index b35b4a90..0bf45080 100644 --- a/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java +++ b/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java @@ -41,7 +41,7 @@ import java.nio.file.StandardCopyOption; public class WriteFilmlistJson { - + private void fastChannelCopy(final ReadableByteChannel src, final WritableByteChannel dest) throws IOException { final ByteBuffer buffer = ByteBuffer.allocateDirect(64 * 1024); while (src.read(buffer) != -1) { @@ -70,8 +70,9 @@ protected JsonGenerator getJsonGenerator(OutputStream os) throws IOException { * * @param datei file path * @param listeFilme film data + * @return true, if writing the file was successful, else false */ - public void filmlisteSchreibenJsonCompressed(String datei, ListeFilme listeFilme) { + public boolean filmlisteSchreibenJsonCompressed(String datei, ListeFilme listeFilme) { final String tempFile = datei + "_temp"; filmlisteSchreibenJson(tempFile, listeFilme); @@ -90,13 +91,16 @@ public void filmlisteSchreibenJsonCompressed(String datei, ListeFilme listeFilme } Files.deleteIfExists(Paths.get(tempFile)); + return true; } catch (IOException | InterruptedException ex) { Log.errorLog(846930144, ex); Log.sysLog("Komprimieren fehlgeschlagen"); } + + return false; } - public void filmlisteSchreibenJson(String datei, ListeFilme listeFilme) { + public boolean filmlisteSchreibenJson(String datei, ListeFilme listeFilme) { try { Log.sysLog("Filme schreiben (" + listeFilme.size() + " Filme) :"); @@ -157,9 +161,12 @@ public void filmlisteSchreibenJson(String datei, ListeFilme listeFilme) { jg.writeEndObject(); Log.sysLog(" --> geschrieben!"); } + return true; } catch (Exception ex) { Log.errorLog(846930145, ex, "nach: " + datei); } + + return false; } private Path testNativeXz() { @@ -186,8 +193,6 @@ private void compressFile(String inputName, String outputName) throws IOExceptio final WritableByteChannel outputChannel = Channels.newChannel(output)) { fastChannelCopy(inputChannel, outputChannel); - } catch (IOException ex) { - throw ex; } } } From 1bbc7d7f364e32ef08cda3c2f6d8302d14b8bb41 Mon Sep 17 00:00:00 2001 From: pidoubleyou Date: Mon, 9 Oct 2017 23:06:19 +0200 Subject: [PATCH 4/4] ExitCode von XZ bei Fehler loggen und Fixes Returncode --- .../mlib/filmlisten/WriteFilmlistJson.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java b/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java index 0bf45080..7092450a 100644 --- a/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java +++ b/src/main/java/de/mediathekview/mlib/filmlisten/WriteFilmlistJson.java @@ -73,6 +73,8 @@ protected JsonGenerator getJsonGenerator(OutputStream os) throws IOException { * @return true, if writing the file was successful, else false */ public boolean filmlisteSchreibenJsonCompressed(String datei, ListeFilme listeFilme) { + boolean result = false; + final String tempFile = datei + "_temp"; filmlisteSchreibenJson(tempFile, listeFilme); @@ -85,19 +87,26 @@ public boolean filmlisteSchreibenJsonCompressed(String datei, ListeFilme listeFi final int exitCode = p.waitFor(); if (exitCode == 0) { Files.move(Paths.get(tempFile + ".xz"), Paths.get(datei), StandardCopyOption.REPLACE_EXISTING); + result = true; + } else { + Log.sysLog("Komprimieren mit XZ fehlgeschlagen. ExitCode: " + exitCode); + result = false; } - } else + } else { compressFile(tempFile, datei); + result = true; + } } Files.deleteIfExists(Paths.get(tempFile)); - return true; + } catch (IOException | InterruptedException ex) { Log.errorLog(846930144, ex); Log.sysLog("Komprimieren fehlgeschlagen"); + result = false; } - return false; + return result; } public boolean filmlisteSchreibenJson(String datei, ListeFilme listeFilme) {