Skip to content

Commit

Permalink
Fix #72 and optimize some code (#73)
Browse files Browse the repository at this point in the history
* Fix #72: update class loader to load the dll

* Optimize code to avoid warnings from IDEA
  • Loading branch information
RocketMaDev authored Aug 14, 2022
1 parent a3657d6 commit 7cdeb8d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/melloware/jintellitype/HotkeyListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2005-2019 Emil A. Lefkof III, Melloware Inc.
*
* I always give it my best shot to make a program useful and solid, but
* remeber that there is absolutely no warranty for using this program as
* remember that there is absolutely no warranty for using this program as
* stated in the following terms:
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -39,7 +39,7 @@ public interface HotkeyListener
* Event fired when a WM_HOTKEY message is received that was initiated
* by this application.
* <p>
* @param identifier the unique Identifer the Hotkey was assigned
* @param identifier the unique Identifier the Hotkey was assigned
*/
void onHotKey( int identifier );
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2005-2019 Emil A. Lefkof III, Melloware Inc.
*
* I always give it my best shot to make a program useful and solid, but
* remeber that there is absolutely no warranty for using this program as
* remember that there is absolutely no warranty for using this program as
* stated in the following terms:
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/com/melloware/jintellitype/JIntellitype.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2005-2019 Emil A. Lefkof III, Melloware Inc.
*
* I always give it my best shot to make a program useful and solid, but
* remeber that there is absolutely no warranty for using this program as
* remember that there is absolutely no warranty for using this program as
* stated in the following terms:
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -64,12 +64,12 @@ public final class JIntellitype implements JIntellitypeConstants {
private static JIntellitype jintellitype = null;

/**
* Static variable for double checked thread safety.
* Static variable for double-checked thread safety.
*/
private static boolean isInitialized = false;
private static volatile boolean isInitialized = false;

/**
* Static variable to hold the libary location if set
* Static variable to hold the library location if set
*/
private static String libraryLocation = null;

Expand Down Expand Up @@ -155,17 +155,19 @@ private static void fromJarToFs(String jarPath, String filePath) throws IOExcept
OutputStream os = null;
try {
File file = new File(filePath);
if (file.exists()) {
boolean success = file.delete();
if (!success) {
throw new IOException("Could not delete file: " + filePath);
}
if (file.exists() && !file.delete()) {
throw new IOException("Could not delete file: " + filePath);
}
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
throw new IOException("Could not create dirs for file: " + filePath);
}

is = ClassLoader.getSystemClassLoader().getResourceAsStream(jarPath);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null)
loader = ClassLoader.getSystemClassLoader();
is = loader.getResourceAsStream(jarPath);
if (is == null)
throw new IOException("Could not find dll resource in JAR");
os = new FileOutputStream(filePath);
byte[] buffer = new byte[8192];
int bytesRead;
Expand Down Expand Up @@ -333,7 +335,7 @@ public void removeIntellitypeListener(IntellitypeListener listener) {
* Unregisters a previously registered Hotkey identified by its unique
* identifier.
* <p>
* @param identifier the unique identifer of this Hotkey
* @param identifier the unique identifier of this Hotkey
*/
public void unregisterHotKey(int identifier) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2005-2019 Emil A. Lefkof III, Melloware Inc.
*
* I always give it my best shot to make a program useful and solid, but
* remeber that there is absolutely no warranty for using this program as
* remember that there is absolutely no warranty for using this program as
* stated in the following terms:
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2005-2019 Emil A. Lefkof III, Melloware Inc.
*
* I always give it my best shot to make a program useful and solid, but
* remeber that there is absolutely no warranty for using this program as
* remember that there is absolutely no warranty for using this program as
* stated in the following terms:
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2005-2019 Emil A. Lefkof III, Melloware Inc.
*
* I always give it my best shot to make a program useful and solid, but
* remeber that there is absolutely no warranty for using this program as
* remember that there is absolutely no warranty for using this program as
* stated in the following terms:
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/melloware/jintellitype/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2005-2019 Emil A. Lefkof III, Melloware Inc.
*
* I always give it my best shot to make a program useful and solid, but
* remeber that there is absolutely no warranty for using this program as
* remember that there is absolutely no warranty for using this program as
* stated in the following terms:
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down

0 comments on commit 7cdeb8d

Please sign in to comment.