Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed Sep 6, 2024
1 parent 4c2a979 commit a7ac437
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/main/java/software/amazon/awssdk/crt/internal/ExtractLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
public class ExtractLib {
private static final String CRT_LIB_NAME = "aws-crt-jni";


/**
* Extract the CRT JNI library on current platform to a specific File
*
* @param extractFile the File extracting to
*/
public static void extractLibrary(File extractFile) {
Expand All @@ -41,12 +41,13 @@ public static void extractLibrary(File extractFile) {
String libraryName = System.mapLibraryName(CRT_LIB_NAME);
String os = CRT.getOSIdentifier();
// open a stream to read the shared lib contents from this JAR
String libResourcePath = "/" + os + "/" + CRT.getArchIdentifier() + "/" + CRT.getCRuntime(os) + "/" + libraryName;
String libResourcePath = "/" + os + "/" + CRT.getArchIdentifier() + "/" + CRT.getCRuntime(os) + "/"
+ libraryName;
// Check whether there is a platform specific resource path to use
CrtPlatform platform = CRT.getPlatformImpl();
if (platform != null){
if (platform != null) {
String platformLibResourcePath = platform.getResourcePath(CRT.getCRuntime(os), libraryName);
if (platformLibResourcePath != null){
if (platformLibResourcePath != null) {
libResourcePath = platformLibResourcePath;
}
}
Expand All @@ -58,8 +59,8 @@ public static void extractLibrary(File extractFile) {
// Copy from jar stream to temp file
try (FileOutputStream out = new FileOutputStream(extractFile)) {
int read;
byte [] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1){
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
}
Expand Down Expand Up @@ -88,6 +89,7 @@ public static void extractLibrary(File extractFile) {

/**
* Extract the CRT JNI library on current platform to a specific path.
*
* @param path the path extracting to
*/
public static void extractLibrary(String path) {
Expand All @@ -96,7 +98,8 @@ public static void extractLibrary(String path) {
try {
extractFile.createNewFile();
} catch (Exception ex) {
CrtRuntimeException rex = new CrtRuntimeException("Unable to create file on path:" + extractFile.getAbsolutePath());
CrtRuntimeException rex = new CrtRuntimeException(
"Unable to create file on path:" + extractFile.getAbsolutePath());
rex.initCause(ex);
throw rex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class NativeFeature implements Feature {

@Override
public void afterImageWrite(AfterImageWriteAccess access) {
new CRT();
ExtractLib.extractLibrary(access.getImagePath().getParent().toString());
new CRT();
ExtractLib.extractLibrary(access.getImagePath().getParent().toString());
}
}

0 comments on commit a7ac437

Please sign in to comment.