Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
OpenCvLoader.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018-2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.corelibs;
20 
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.opencv.core.Core;
24 
29 public final class OpenCvLoader {
30 
31  // Uses java logger since the Autopsy class logger (Autopsy-core) is not part of this module
32  private static final Logger logger = Logger.getLogger(OpenCvLoader.class.getName());
33  private static boolean openCvLoaded;
34  private static UnsatisfiedLinkError exception = null; // Deprecated
35 
36  static {
37  openCvLoaded = false;
38  try {
39  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
40  openCvLoaded = true;
41  } catch (UnsatisfiedLinkError ex) {
42  logger.log(Level.WARNING, "Failed to load core OpenCV library", ex);
43  /*
44  * Save exception to rethrow later (deprecated).
45  */
46  exception = ex;
47  } catch (Exception ex) {
48  /*
49  * Exception firewall to ensure that runtime exceptions do not cause
50  * the loading of this class by the Java class loader to fail.
51  */
52  logger.log(Level.WARNING, "Failed to load core OpenCV library", ex);
53  }
54 
55  }
56 
62  public static boolean openCvIsLoaded() {
63  return openCvLoaded;
64  }
65 
69  private OpenCvLoader() {
70  }
71 
83  @Deprecated
84  public static boolean isOpenCvLoaded() throws UnsatisfiedLinkError {
85  if (!openCvLoaded) {
86  if (exception != null) {
87  throw exception;
88  } else {
89  throw new UnsatisfiedLinkError("OpenCV native library failed to load");
90  }
91  }
92  return openCvLoaded;
93  }
94 
95 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.