public void compactRange(byte[] begin, byte[] end) { NativeBuffer keyBuffer = NativeBuffer.create(begin); try { NativeBuffer valueBuffer = NativeBuffer.create(end); try { compactRange(keyBuffer, valueBuffer); } finally { if( valueBuffer!=null ) { valueBuffer.delete(); } } } finally { if( keyBuffer!=null ) { keyBuffer.delete(); } } }
public NativeBuffer slice(long offset, long length) { assertAllocated(); if( length < 0 ) throw new IllegalArgumentException("length cannot be negative"); if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative"); if( offset+length >= capacity) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of this buffer"); return new NativeBuffer(allocation, PointerMath.add(self, offset), length); }
public NativeComparator() { super(ComparatorJNI.create()); try { name_buffer = NativeBuffer.create(name()); globalRef = NativeDB.DBJNI.NewGlobalRef(this); if( globalRef==0 ) { throw new RuntimeException("jni call failed: NewGlobalRef"); } ComparatorJNI struct = new ComparatorJNI(); struct.compare_method = NativeDB.DBJNI.GetMethodID(this.getClass(), "compare", "(JJ)I"); if( struct.compare_method==0 ) { throw new RuntimeException("jni call failed: GetMethodID"); } struct.target = globalRef; struct.name = name_buffer.pointer(); ComparatorJNI.memmove(self, struct, ComparatorJNI.SIZEOF); } catch (RuntimeException e) { delete(); throw e; } }
public long[] getApproximateSizes(NativeRange... ranges) { if( ranges==null ) { return null; } long rc[] = new long[ranges.length]; NativeRange.RangeJNI structs[] = new NativeRange.RangeJNI[ranges.length]; if( rc.length> 0 ) { NativeBuffer range_array = NativeRange.RangeJNI.arrayCreate(ranges.length); try { for(int i=0; i < ranges.length; i++) { structs[i] = new NativeRange.RangeJNI(ranges[i]); structs[i].arrayWrite(range_array.pointer(), i); } DBJNI.GetApproximateSizes(self,range_array.pointer(), ranges.length, rc); } finally { for(int i=0; i < ranges.length; i++) { if( structs[i] != null ) { structs[i].delete(); } } range_array.delete(); } } return rc; }
static public NativeBuffer create(byte[] data) { if( data == null ) { return null; } else { return create(data, 0 , data.length); } }
static public NativeBuffer create(long capacity) { Pool pool = CURRENT_POOL.get(); if( pool == null ) { Allocation allocation = new Allocation(capacity); return new NativeBuffer(allocation, allocation.self, capacity); } else { return pool.create(capacity); } }
public void write(long at, byte []source, int offset, int length) { assertAllocated(); if( length < 0 ) throw new IllegalArgumentException("length cannot be negative"); if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative"); if( at < 0 ) throw new IllegalArgumentException("at cannot be negative"); if( at+length > capacity ) throw new ArrayIndexOutOfBoundsException("at + length exceeds the capacity of this object"); if( offset+length > source.length) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of the source buffer"); NativeBufferJNI.buffer_copy(source, offset, self, at, length); }
public byte[] toByteArray() { if( capacity > Integer.MAX_VALUE ) { throw new OutOfMemoryError("Native buffer larger than the largest allowed Java byte[]"); } byte [] rc = new byte[(int) capacity]; read(0, rc, 0, rc.length); return rc; } }
public static void popMemoryPool() { NativeBuffer.popMemoryPool(); } }
public static void pushMemoryPool(int size) { NativeBuffer.pushMemoryPool(size); }
public NativeBuffer slice(long offset, long length) { assertAllocated(); if( length < 0 ) throw new IllegalArgumentException("length cannot be negative"); if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative"); if( offset+length >= capacity) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of this buffer"); return new NativeBuffer(allocation, PointerMath.add(self, offset), length); }
public NativeComparator() { super(ComparatorJNI.create()); try { name_buffer = NativeBuffer.create(name()); globalRef = NativeDB.DBJNI.NewGlobalRef(this); if( globalRef==0 ) { throw new RuntimeException("jni call failed: NewGlobalRef"); } ComparatorJNI struct = new ComparatorJNI(); struct.compare_method = NativeDB.DBJNI.GetMethodID(this.getClass(), "compare", "(JJ)I"); if( struct.compare_method==0 ) { throw new RuntimeException("jni call failed: GetMethodID"); } struct.target = globalRef; struct.name = name_buffer.pointer(); ComparatorJNI.memmove(self, struct, ComparatorJNI.SIZEOF); } catch (RuntimeException e) { delete(); throw e; } }
public long[] getApproximateSizes(NativeRange... ranges) { if( ranges==null ) { return null; } long rc[] = new long[ranges.length]; NativeRange.RangeJNI structs[] = new NativeRange.RangeJNI[ranges.length]; if( rc.length> 0 ) { NativeBuffer range_array = NativeRange.RangeJNI.arrayCreate(ranges.length); try { for(int i=0; i < ranges.length; i++) { structs[i] = new NativeRange.RangeJNI(ranges[i]); structs[i].arrayWrite(range_array.pointer(), i); } DBJNI.GetApproximateSizes(self,range_array.pointer(), ranges.length, rc); } finally { for(int i=0; i < ranges.length; i++) { if( structs[i] != null ) { structs[i].delete(); } } range_array.delete(); } } return rc; }
static public NativeBuffer create(byte[] data) { if( data == null ) { return null; } else { return create(data, 0 , data.length); } }
static public NativeBuffer create(long capacity) { Pool pool = CURRENT_POOL.get(); if( pool == null ) { Allocation allocation = new Allocation(capacity); return new NativeBuffer(allocation, allocation.self, capacity); } else { return pool.create(capacity); } }