public static synchronized void load() { if (instance == null) { instance = new SQLiteLibraryLoader(); } instance.doLoad(); }
private ByteSource getLibraryByteSource() { return Resources.asByteSource(Resources.getResource(getLibClasspathResourceName())); }
private String getNativesResourcesPathPart() { return getOsPrefix() + "-" + getArchitectureSuffix(); }
public String getLibClasspathResourceName() { return getNativesResourcesPathPart() + "/" + getNativesResourcesFilePart(); }
public void doLoad() { if (loaded) { return; } final long startTime = System.currentTimeMillis(); final File extractedLibrary = getNativeLibraryPath(); if (isExtractedLibUptodate(extractedLibrary)) { loadFromDirectory(extractedLibrary.getParentFile()); } else { extractAndLoad(getLibraryStream(), extractedLibrary); } logWithTime("SQLite natives prepared in", startTime); }
public void doLoad() { if (loaded) { return; } final long startTime = System.currentTimeMillis(); File tempDir = Files.createTempDir(); tempDir.deleteOnExit(); File extractedLibraryPath = new File(tempDir, getLibName()); try (FileOutputStream outputStream = new FileOutputStream(extractedLibraryPath)) { getLibraryByteSource().copyTo(outputStream); } catch (IOException e) { throw new RuntimeException("Cannot extract SQLite library into " + extractedLibraryPath, e); } loadFromDirectory(tempDir); logWithTime("SQLite natives prepared in", startTime); }
@Before public void setUp() { loader = new SQLiteLibraryLoader(); }
private void extractAndLoad(final InputStream input, final File output) { File libPath = output.getParentFile(); if (!libPath.exists() && !libPath.mkdirs()) { throw new RuntimeException("could not create " + libPath); } FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(output); copy(input, outputStream); } catch (IOException e) { throw new RuntimeException("Cannot extractAndLoad SQLite library into " + output, e); } finally { closeQuietly(outputStream); closeQuietly(input); } loadFromDirectory(libPath); }
private String getNativesResourcesFilePart() { return getLibName().replace(".dylib", ".jnilib"); }
@Implementation(maxSdk = O) public static Number nativeOpen(String path, int openFlags, String label, boolean enableTrace, boolean enableProfile) { SQLiteLibraryLoader.load(); return castNativePtr(CONNECTIONS.open(path)); }
public void doLoad() { if (loaded) { return; } final long startTime = System.currentTimeMillis(); final File extractedLibrary = getNativeLibraryPath(); if (isExtractedLibUptodate(extractedLibrary)) { loadFromDirectory(extractedLibrary.getParentFile()); } else { extractAndLoad(getLibraryStream(), extractedLibrary); } logWithTime("SQLite natives prepared in", startTime); }
public void doLoad() { if (loaded) { return; } final long startTime = System.currentTimeMillis(); File tempDir = Files.createTempDir(); tempDir.deleteOnExit(); File extractedLibraryPath = new File(tempDir, getLibName()); try (FileOutputStream outputStream = new FileOutputStream(extractedLibraryPath)) { getLibraryByteSource().copyTo(outputStream); } catch (IOException e) { throw new RuntimeException("Cannot extract SQLite library into " + extractedLibraryPath, e); } loadFromDirectory(tempDir); logWithTime("SQLite natives prepared in", startTime); }
public String getLibClasspathResourceName() { return "/" + getNativesResourcesPathPart() + "/" + getNativesResourcesFilePart(); }
@Test(expected = UnsupportedOperationException.class) public void shouldThrowExceptionIfUnknownNameAndArch() throws Exception { loadLibrary(new SQLiteLibraryLoader(LINUX), "ACME Electronic", "FooBar2000"); }
private void extractAndLoad(final InputStream input, final File output) { File libPath = output.getParentFile(); if (!libPath.exists() && !libPath.mkdirs()) { throw new RuntimeException("could not create " + libPath); } FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(output); copy(input, outputStream); } catch (IOException e) { throw new RuntimeException("Cannot extractAndLoad SQLite library into " + output, e); } finally { closeQuietly(outputStream); closeQuietly(input); } loadFromDirectory(libPath); }
private String getNativesResourcesFilePart() { return getLibName().replace(".dylib", ".jnilib"); }
@Implementation public static long nativeOpen(String path, int openFlags, String label, boolean enableTrace, boolean enableProfile) { SQLiteLibraryLoader.load(); return CONNECTIONS.open(path); }
public void doLoad() { if (loaded) { return; } final long startTime = System.currentTimeMillis(); final File extractedLibrary = getNativeLibraryPath(); if (isExtractedLibUptodate(extractedLibrary)) { loadFromDirectory(extractedLibrary.getParentFile()); } else { extractAndLoad(getLibraryStream(), extractedLibrary); } logWithTime("SQLite natives prepared in", startTime); }
public static synchronized void load() { if (instance == null) { instance = new SQLiteLibraryLoader(); } instance.doLoad(); }