From 074c23b482048f837adbbd2a6cd1162178a2fa19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Baptiste=20Onofr=C3=A9?= Date: Wed, 28 Sep 2016 14:38:57 +0200 Subject: [PATCH] Deal with UnsatisfiedLinkError: when native lib can't be loaded, jansi can deal with this case. --- .../java/org/fusesource/jansi/AnsiConsole.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java index a868f10a..096d8bc1 100644 --- a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java +++ b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java @@ -38,7 +38,7 @@ public class AnsiConsole { public static final PrintStream out = new PrintStream( wrapOutputStream( system_out ) ); public static final PrintStream system_err = System.err; - public static final PrintStream err = new PrintStream( wrapOutputStream( system_err, STDERR_FILENO ) ); + public static final PrintStream err = new PrintStream( wrapErrorOutputStream( system_err ) ); private static int installed; @@ -46,7 +46,19 @@ private AnsiConsole() { } public static OutputStream wrapOutputStream(final OutputStream stream) { - return wrapOutputStream(stream, STDOUT_FILENO); + try { + return wrapOutputStream(stream, STDOUT_FILENO); + } catch (Throwable ignore) { + return wrapOutputStream(stream, 0); + } + } + + public static OutputStream wrapErrorOutputStream(final OutputStream stream) { + try { + return wrapOutputStream(stream, STDERR_FILENO); + } catch (Throwable ignore) { + return wrapOutputStream(stream, 0); + } } public static OutputStream wrapOutputStream(final OutputStream stream, int fileno) {