Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/251 #103

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -70,8 +70,11 @@ 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) {
boolean result = false;

final String tempFile = datei + "_temp";
filmlisteSchreibenJson(tempFile, listeFilme);

Expand All @@ -84,18 +87,29 @@ public void filmlisteSchreibenJsonCompressed(String datei, ListeFilme listeFilme
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));

} catch (IOException | InterruptedException ex) {
Log.errorLog(846930144, ex);
Log.sysLog("Komprimieren fehlgeschlagen");
result = false;
}

return result;
}

public void filmlisteSchreibenJson(String datei, ListeFilme listeFilme) {
public boolean filmlisteSchreibenJson(String datei, ListeFilme listeFilme) {
try {
Log.sysLog("Filme schreiben (" + listeFilme.size() + " Filme) :");

Expand Down Expand Up @@ -156,9 +170,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() {
Expand All @@ -167,8 +184,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;
}
}
Expand All @@ -184,7 +202,6 @@ private void compressFile(String inputName, String outputName) throws IOExceptio
final WritableByteChannel outputChannel = Channels.newChannel(output)) {

fastChannelCopy(inputChannel, outputChannel);
} catch (IOException ignored) {
}
}
}