
org.fusesource.lmdbjni.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lmdbjni-osx64 Show documentation
Show all versions of lmdbjni-osx64 Show documentation
The lmdbjni osx 64 bit native libraries
The newest version!
/**
* Copyright (C) 2013, RedHat, Inc.
*
* http://www.redhat.com/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fusesource.lmdbjni;
import java.nio.charset.Charset;
import static org.fusesource.lmdbjni.JNI.mdb_strerror;
import static org.fusesource.lmdbjni.JNI.strlen;
/**
* Some miscellaneous utility functions.
*
* @author Hiram Chirino
*/
class Util {
public static final boolean isAndroid = isAndroid();
public static String string(long ptr) {
if (ptr == 0)
return null;
return new String(NativeBuffer.create(ptr, strlen(ptr)).toByteArray(),
Charset.defaultCharset());
}
public static void checkErrorCode(int rc) {
if (rc != 0) {
String msg = string(mdb_strerror(rc));
throw new LMDBException(msg, rc);
}
}
public static void checkArgNotNull(Object value, String name) {
if (value == null) {
throw new IllegalArgumentException("The " + name + " argument cannot be null");
}
}
static boolean isAndroid() {
try {
Class.forName("android.os.Process");
return true;
} catch (Throwable ignored) {
return false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy