Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 13, 2021
1 parent 3d97645 commit d83ab13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<description>Jansi is a java library for generating and interpreting ANSI escape sequences.</description>

<properties>
<javadocSource>6</javadocSource>
<javadocSource>7</javadocSource>
<jdkTarget>1.7</jdkTarget>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j-version>1.6.1</slf4j-version>
Expand Down
24 changes: 6 additions & 18 deletions src/main/java/org/fusesource/jansi/internal/JansiLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,43 +174,32 @@ private static boolean extractAndLoadLibraryFile(String libFolderForCurrentOS, S

try {
// Extract a native library file into the target directory
InputStream in = JansiLoader.class.getResourceAsStream(nativeLibraryFilePath);
try {
try (InputStream in = JansiLoader.class.getResourceAsStream(nativeLibraryFilePath)) {
if (!extractedLckFile.exists()) {
new FileOutputStream(extractedLckFile).close();
}
OutputStream out = new FileOutputStream(extractedLibFile);
try {
try (OutputStream out = new FileOutputStream(extractedLibFile)) {
copy(in, out);
} finally {
out.close();
}
} finally {
// Delete the extracted lib file on JVM exit.
extractedLibFile.deleteOnExit();
extractedLckFile.deleteOnExit();
in.close();
}

// Set executable (x) flag to enable Java to load the native library
extractedLibFile.setReadable(true);
extractedLibFile.setWritable(true, true);
extractedLibFile.setWritable(true);
extractedLibFile.setExecutable(true);

// Check whether the contents are properly copied from the resource folder
InputStream nativeIn = JansiLoader.class.getResourceAsStream(nativeLibraryFilePath);
try {
InputStream extractedLibIn = new FileInputStream(extractedLibFile);
try {
try (InputStream nativeIn = JansiLoader.class.getResourceAsStream(nativeLibraryFilePath)) {
try (InputStream extractedLibIn = new FileInputStream(extractedLibFile)) {
String eq = contentsEquals(nativeIn, extractedLibIn);
if (eq != null) {
throw new RuntimeException(String.format("Failed to write a native library file at %s because %s", extractedLibFile, eq));
}
} finally {
extractedLibIn.close();
}
} finally {
nativeIn.close();
}

// Load library
Expand Down Expand Up @@ -244,7 +233,6 @@ private static void copy(InputStream in, OutputStream out) throws IOException {
*/
private static boolean loadNativeLibrary(File libPath) {
if (libPath.exists()) {

try {
String path = libPath.getAbsolutePath();
System.load(path);
Expand Down Expand Up @@ -381,7 +369,7 @@ public static String getVersion() {
Properties versionData = new Properties();
versionData.load(versionFile.openStream());
version = versionData.getProperty("version", version);
version = version.trim().replaceAll("[^0-9\\.]", "");
version = version.trim().replaceAll("[^0-9.]", "");
}
} catch (IOException e) {
System.err.println(e);
Expand Down

0 comments on commit d83ab13

Please sign in to comment.