本文整理汇总了Java中jnr.ffi.Pointer类的典型用法代码示例。如果您正苦于以下问题:Java Pointer类的具体用法?Java Pointer怎么用?Java Pointer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pointer类属于jnr.ffi包,在下文中一共展示了Pointer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: write
import jnr.ffi.Pointer; //导入依赖的package包/类
/**
* Writes up to {@code num} bytes from {@code buf} from {@code offset} into the current file
*
* @param buf Buffer
* @param num Number of bytes to write
* @param offset Position of first byte to write at
* @return Actual number of bytes written
* TODO: only the bytes which contains information or also some filling zeros?
* @throws IOException If an exception occurs during write.
*/
public synchronized int write(Pointer buf, long num, long offset) throws IOException {
ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
long written = 0;
channel.position(offset);
do {
long remaining = num - written;
bb.clear();
int len = (int) Math.min(remaining, bb.capacity());
buf.get(written, bb.array(), 0, len);
bb.limit(len);
channel.write(bb); // TODO check return value
written += len;
} while (written < num);
return (int) written; // TODO wtf cast
}
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:26,代码来源:OpenFile.java
示例2: setupLogger
import jnr.ffi.Pointer; //导入依赖的package包/类
private void setupLogger(Pointer codec) {
if (LOGGER.isInfoEnabled()) {
if (!lib.opj_set_info_handler(codec, infoLogFn)) {
throw new RuntimeException("Could not set info logging handler");
}
}
if (LOGGER.isWarnEnabled()) {
if (!lib.opj_set_warning_handler(codec, warnLogFn)) {
throw new RuntimeException("Could not set warning logging handler");
}
}
if (LOGGER.isErrorEnabled()) {
if (!lib.opj_set_error_handler(codec, errorLogFn)) {
throw new RuntimeException("Could not set error logging handler");
}
}
}
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:18,代码来源:OpenJpeg.java
示例3: getInfo
import jnr.ffi.Pointer; //导入依赖的package包/类
private Info getInfo(Pointer codecPointer, opj_image img) {
opj_codestream_info_v2 csInfo = null;
try {
csInfo = lib.opj_get_cstr_info(codecPointer);
Info info = new Info();
info.setWidth(img.x1.intValue());
info.setHeight(img.y1.intValue());
info.setNumComponents(csInfo.nbcomps.intValue());
info.setNumTilesX(csInfo.tw.intValue());
info.setNumTilesY(csInfo.th.intValue());
info.setTileWidth(csInfo.tdx.intValue());
info.setTileHeight(csInfo.tdy.intValue());
info.setTileOriginX(csInfo.tx0.intValue());
info.setTileOriginY(csInfo.ty0.intValue());
info.setNumResolutions(csInfo.m_default_tile_info.tccp_info.get().numresolutions.intValue());
return info;
} finally {
if (csInfo != null) csInfo.free(lib);
}
}
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:21,代码来源:OpenJpeg.java
示例4: open
import jnr.ffi.Pointer; //导入依赖的package包/类
/**
* Opens the environment.
*
* @param path file system destination
* @param mode Unix permissions to set on created files and semaphores
* @param flags the flags for this new environment
* @return an environment ready for use
*/
public Env<T> open(final File path, final int mode,
final EnvFlags... flags) {
requireNonNull(path);
if (opened) {
throw new AlreadyOpenException();
}
opened = true;
final PointerByReference envPtr = new PointerByReference();
checkRc(LIB.mdb_env_create(envPtr));
final Pointer ptr = envPtr.getValue();
try {
checkRc(LIB.mdb_env_set_mapsize(ptr, mapSize));
checkRc(LIB.mdb_env_set_maxdbs(ptr, maxDbs));
checkRc(LIB.mdb_env_set_maxreaders(ptr, maxReaders));
final int flagsMask = mask(flags);
final boolean readOnly = isSet(flagsMask, MDB_RDONLY_ENV);
checkRc(LIB.mdb_env_open(ptr, path.getAbsolutePath(), flagsMask, mode));
return new Env<>(proxy, ptr, readOnly); // NOPMD
} catch (final LmdbNativeException e) {
LIB.mdb_env_close(ptr);
throw e;
}
}
开发者ID:lmdbjava,项目名称:lmdbjava,代码行数:32,代码来源:Env.java
示例5: Txn
import jnr.ffi.Pointer; //导入依赖的package包/类
Txn(final Env<T> env, final Txn<T> parent, final BufferProxy<T> proxy,
final TxnFlags... flags) {
this.proxy = proxy;
this.keyVal = proxy.keyVal();
final int flagsMask = mask(flags);
this.readOnly = isSet(flagsMask, MDB_RDONLY_TXN);
if (env.isReadOnly() && !this.readOnly) {
throw new EnvIsReadOnly();
}
this.parent = parent;
if (parent != null && parent.isReadOnly() != this.readOnly) {
throw new IncompatibleParent();
}
final Pointer txnPtr = allocateDirect(RUNTIME, ADDRESS);
final Pointer txnParentPtr = parent == null ? null : parent.ptr;
checkRc(LIB.mdb_txn_begin(env.pointer(), txnParentPtr, flagsMask, txnPtr));
ptr = txnPtr.getPointer(0);
state = READY;
}
开发者ID:lmdbjava,项目名称:lmdbjava,代码行数:21,代码来源:Txn.java
示例6: Dbi
import jnr.ffi.Pointer; //导入依赖的package包/类
Dbi(final Env<T> env, final Txn<T> txn, final byte[] name,
final Comparator<T> comparator, final DbiFlags... flags) {
this.env = env;
this.name = name == null ? null : Arrays.copyOf(name, name.length);
final int flagsMask = mask(flags);
final Pointer dbiPtr = allocateDirect(RUNTIME, ADDRESS);
checkRc(LIB.mdb_dbi_open(txn.pointer(), name, flagsMask, dbiPtr));
ptr = dbiPtr.getPointer(0);
if (comparator == null) {
proxy = null;
compFunc = null;
compKeyA = null;
compKeyB = null;
} else {
this.proxy = txn.getProxy();
this.compFunc = comparator;
this.compKeyA = proxy.allocate();
this.compKeyB = proxy.allocate();
final ComparatorCallback ccb = (keyA, keyB) -> {
proxy.out(compKeyA, keyA, keyA.address());
proxy.out(compKeyB, keyB, keyB.address());
return compFunc.compare(compKeyA, compKeyB);
};
LIB.mdb_set_compare(txn.pointer(), ptr, ccb);
}
}
开发者ID:lmdbjava,项目名称:lmdbjava,代码行数:27,代码来源:Dbi.java
示例7: delete
import jnr.ffi.Pointer; //导入依赖的package包/类
/**
* Removes key/data pairs from the database.
*
* <p>
* If the database does not support sorted duplicate data items
* ({@link DbiFlags#MDB_DUPSORT}) the value parameter is ignored. If the
* database supports sorted duplicates and the value parameter is null, all of
* the duplicate data items for the key will be deleted. Otherwise, if the
* data parameter is non-null only the matching data item will be deleted.
*
* @param txn transaction handle (not null; not committed; must be R-W)
* @param key key to delete from the database (not null)
* @param val value to delete from the database (null permitted)
* @return true if the key/data pair was found, false otherwise
*/
public boolean delete(final Txn<T> txn, final T key, final T val) {
if (SHOULD_CHECK) {
requireNonNull(txn);
requireNonNull(key);
txn.checkReady();
txn.checkWritesAllowed();
}
txn.kv().keyIn(key);
Pointer data = null;
if (val != null) {
txn.kv().valIn(val);
data = txn.kv().pointerVal();
}
final int rc = LIB.mdb_del(txn.pointer(), ptr, txn.kv().pointerKey(), data);
if (rc == MDB_NOTFOUND) {
return false;
}
checkRc(rc);
return true;
}
开发者ID:lmdbjava,项目名称:lmdbjava,代码行数:38,代码来源:Dbi.java
示例8: putMultiple
import jnr.ffi.Pointer; //导入依赖的package包/类
/**
* Put multiple values into the database in one <code>MDB_MULTIPLE</code>
* operation.
*
* <p>
* The database must have been opened with {@link DbiFlags#MDB_DUPFIXED}. The
* buffer must contain fixed-sized values to be inserted. The size of each
* element is calculated from the buffer's size divided by the given element
* count. For example, to populate 10 X 4 byte integers at once, present a
* buffer of 40 bytes and specify the element as 10.
*
* @param key key to store in the database (not null)
* @param val value to store in the database (not null)
* @param elements number of elements contained in the passed value buffer
* @param op options for operation (must set <code>MDB_MULTIPLE</code>)
*/
public void putMultiple(final T key, final T val, final int elements,
final PutFlags... op) {
if (SHOULD_CHECK) {
requireNonNull(txn);
requireNonNull(key);
requireNonNull(val);
txn.checkReady();
txn.checkWritesAllowed();
}
final int mask = mask(op);
if (SHOULD_CHECK && !isSet(mask, MDB_MULTIPLE)) {
throw new IllegalArgumentException("Must set " + MDB_MULTIPLE + " flag");
}
txn.kv().keyIn(key);
final Pointer dataPtr = txn.kv().valInMulti(val, elements);
final int rc = LIB.mdb_cursor_put(ptrCursor, txn.kv().pointerKey(),
dataPtr, mask);
checkRc(rc);
}
开发者ID:lmdbjava,项目名称:lmdbjava,代码行数:36,代码来源:Cursor.java
示例9: read
import jnr.ffi.Pointer; //导入依赖的package包/类
@Override
public int read(String path, Pointer buf, @size_t long size, @off_t long offset, FuseFileInfo fi) {
try {
Path node = resolvePath(path);
assert Files.exists(node);
return fileHandler.read(node, buf, size, offset, fi);
} catch (RuntimeException e) {
LOG.error("read failed.", e);
return -ErrorCodes.EIO();
}
}
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:12,代码来源:ReadOnlyAdapter.java
示例10: destroy
import jnr.ffi.Pointer; //导入依赖的package包/类
@Override
public void destroy(Pointer initResult) {
try {
close();
} catch (IOException | RuntimeException e) {
LOG.error("destroy failed.", e);
}
}
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:9,代码来源:ReadOnlyAdapter.java
示例11: write
import jnr.ffi.Pointer; //导入依赖的package包/类
@Override
public int write(String path, Pointer buf, @size_t long size, @off_t long offset, FuseFileInfo fi) {
try {
Path node = resolvePath(path);
return fileHandler.write(node, buf, size, offset, fi);
} catch (RuntimeException e) {
LOG.error("write failed.", e);
return -ErrorCodes.EIO();
}
}
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:11,代码来源:ReadWriteAdapter.java
示例12: readdir
import jnr.ffi.Pointer; //导入依赖的package包/类
public int readdir(Path path, Pointer buf, FuseFillDir filler, long offset, FuseFileInfo fi) throws IOException {
// fill in names and basic file attributes - however only the filetype is used...
// Files.walkFileTree(node, EnumSet.noneOf(FileVisitOption.class), 1, new SimpleFileVisitor<Path>() {
//
// @Override
// public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// FileStat stat = attrUtil.basicFileAttributesToFileStat(attrs);
// if (attrs.isDirectory()) {
// stat.st_mode.set(FileStat.S_IFDIR | FileStat.ALL_READ | FileStat.S_IXUGO);
// } else {
// stat.st_mode.set(FileStat.S_IFREG | FileStat.ALL_READ);
// }
// filter.apply(buf, file.getFileName().toString(), stat, 0);
// return FileVisitResult.CONTINUE;
// }
// });
// just fill in names, getattr gets called for each entry anyway
try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) {
Iterator<Path> sameAndParent = Iterators.forArray(SAME_DIR, PARENT_DIR);
Iterator<Path> iter = Iterators.concat(sameAndParent, ds.iterator());
while (iter.hasNext()) {
String fileName = iter.next().getFileName().toString();
if (filler.apply(buf, fileName, null, 0) != 0) {
return -ErrorCodes.ENOMEM();
}
}
return 0;
} catch (DirectoryIteratorException e) {
throw new IOException(e);
}
}
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:33,代码来源:ReadOnlyDirectoryHandler.java
示例13: read
import jnr.ffi.Pointer; //导入依赖的package包/类
public int read(Path path, Pointer buf, long size, long offset, FuseFileInfo fi) {
OpenFile file = openFiles.get(fi.fh.get());
if (file == null) {
LOG.warn("Attempted to read from file with illegal fileHandle {}: {}", fi.fh.get(), path);
return -ErrorCodes.EBADF();
}
try {
return file.read(buf, size, offset);
} catch (IOException e) {
LOG.error("Reading file failed.", e);
return -ErrorCodes.EIO();
}
}
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:14,代码来源:ReadOnlyFileHandler.java
示例14: write
import jnr.ffi.Pointer; //导入依赖的package包/类
public int write(Path path, Pointer buf, long size, long offset, FuseFileInfo fi) {
OpenFile file = openFiles.get(fi.fh.get());
if (file == null) {
LOG.warn("write: File not opened: {}", path);
return -ErrorCodes.EBADFD();
}
try {
return file.write(buf, size, offset);
} catch (IOException e) {
LOG.error("Writing to file failed.", e);
return -ErrorCodes.EIO();
}
}
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:14,代码来源:ReadWriteFileHandler.java
示例15: read
import jnr.ffi.Pointer; //导入依赖的package包/类
@Override
public int read(String path, Pointer buf, @size_t long size, @off_t long offset, FuseFileInfo fi) {
if (size >= Integer.MAX_VALUE) {
return -ErrorCodes.EINVAL();
}
return delegate.read(path, (data) -> buf.put(0, data, 0, data.length), (int) size, offset, fi.fh.intValue());
}
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:8,代码来源:JnrFuseWrapperFileSystem.java
示例16: getInfo
import jnr.ffi.Pointer; //导入依赖的package包/类
/** Return information about the JPEG image in the input buffer **/
public Info getInfo(byte[] jpegData) throws TurboJpegException {
Pointer codec = null;
try {
codec = lib.tjInitDecompress();
IntByReference width = new IntByReference();
IntByReference height = new IntByReference();
IntByReference jpegSubsamp = new IntByReference();
int rv = lib.tjDecompressHeader2(
codec, ByteBuffer.wrap(jpegData), jpegData.length, width, height, jpegSubsamp);
if (rv != 0) {
throw new TurboJpegException(lib.tjGetErrorStr());
}
IntByReference numRef = new IntByReference();
Pointer factorPtr = lib.tjGetScalingFactors(numRef);
tjscalingfactor[] factors = new tjscalingfactor[numRef.getValue()];
for (int i=0; i < numRef.getValue(); i++) {
tjscalingfactor f = new tjscalingfactor(runtime);
factorPtr = factorPtr.slice(i * Struct.size(f));
f.useMemory(factorPtr);
factors[i] = f;
}
return new Info(width.getValue(), height.getValue(), jpegSubsamp.getValue(), factors);
} finally {
if (codec != null && codec.address() != 0) lib.tjDestroy(codec);
}
}
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:30,代码来源:TurboJpeg.java
示例17: decode
import jnr.ffi.Pointer; //导入依赖的package包/类
/** Decode the JPEG image in the input buffer into a BufferedImage.
*
* @param jpegData JPEG data input buffer
* @param info Information about the JPEG image in the buffer
* @param size Target decompressed dimensions, must be among the available sizes (see {@link Info#getAvailableSizes()})
* @return The decoded image
* @throws TurboJpegException
*/
public BufferedImage decode(byte[] jpegData, Info info, Dimension size) throws TurboJpegException {
Pointer codec = null;
try {
codec = lib.tjInitDecompress();
int width = info.getWidth();
int height = info.getHeight();
if (size != null) {
if (!info.getAvailableSizes().contains(size)) {
throw new IllegalArgumentException(String.format(
"Invalid size, must be one of %s", info.getAvailableSizes()));
} else {
width = size.width;
height = size.height;
}
}
boolean isGray = info.getSubsampling() == TJSAMP.TJSAMP_GRAY.intValue();
int imgType;
if (isGray) {
imgType = BufferedImage.TYPE_BYTE_GRAY;
} else {
imgType = BufferedImage.TYPE_3BYTE_BGR;
}
BufferedImage img = new BufferedImage(width, height, imgType);
// Wrap the underlying data buffer of the image with a ByteBuffer so we can pass it over the ABI
ByteBuffer outBuf = ByteBuffer.wrap(((DataBufferByte) img.getRaster().getDataBuffer()).getData())
.order(runtime.byteOrder());
int rv = lib.tjDecompress2(
codec, ByteBuffer.wrap(jpegData), jpegData.length, outBuf,
width, isGray ? width : width * 3, height, isGray ? TJPF.TJPF_GRAY : TJPF.TJPF_BGR, 0);
if (rv != 0) {
LOG.error("Could not decompress JPEG (dimensions: {}x{}, gray: {})", width, height, isGray);
throw new TurboJpegException(lib.tjGetErrorStr());
}
return img;
} finally {
if (codec != null && codec.address() != 0) lib.tjDestroy(codec);
}
}
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:47,代码来源:TurboJpeg.java
示例18: getCodec
import jnr.ffi.Pointer; //导入依赖的package包/类
private Pointer getCodec(int reduceFactor) throws IOException {
Pointer codec = lib.opj_create_decompress(CODEC_FORMAT.OPJ_CODEC_JP2);
setupLogger(codec);
opj_dparameters params = new opj_dparameters(Runtime.getRuntime(lib));
lib.opj_set_default_decoder_parameters(params);
params.cp_reduce.set(reduceFactor);
if (!lib.opj_setup_decoder(codec, params)) {
throw new IOException("Error setting up decoder!");
}
return codec;
}
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:12,代码来源:OpenJpeg.java
示例19: getImage
import jnr.ffi.Pointer; //导入依赖的package包/类
private opj_image getImage(InStreamWrapper wrapper, Pointer codec) throws IOException {
opj_image img = new opj_image(Runtime.getRuntime(lib));
PointerByReference imgPtr = new PointerByReference();
if (!lib.opj_read_header(wrapper.getNativeStream(), codec, imgPtr)) {
throw new IOException("Error while reading header.");
}
img.useMemory(imgPtr.getValue());
return img;
}
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:10,代码来源:OpenJpeg.java
示例20: encode
import jnr.ffi.Pointer; //导入依赖的package包/类
public void encode(Raster img, OutStreamWrapper output, opj_cparameters params) throws IOException {
opj_image image = null;
Pointer codec = null;
try {
image = createImage(img);
// Disable MCT for grayscale images
if (image.numcomps.get() == 1) {
params.tcp_mct.set(0);
}
codec = lib.opj_create_compress(CODEC_FORMAT.OPJ_CODEC_JP2);
setupLogger(codec);
if (params == null) {
params = new opj_cparameters(runtime);
lib.opj_set_default_encoder_parameters(params);
}
if (!lib.opj_setup_encoder(codec, params, image)) {
throw new IOException("Could not setup encoder!");
}
if (!lib.opj_start_compress(codec, image, output.getNativeStream())) {
throw new IOException("Could not start encoding");
}
if (!lib.opj_encode(codec, output.getNativeStream())) {
throw new IOException("Could not encode");
}
if (!lib.opj_end_compress(codec, output.getNativeStream())) {
throw new IOException("Could not finish encoding.");
}
} finally {
if (image != null) image.free(lib);
if (codec != null) lib.opj_destroy_codec(codec);
if (output != null) output.close();
}
}
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:39,代码来源:OpenJpeg.java
注:本文中的jnr.ffi.Pointer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论