11package app .photofox .vipsffm ;
22
3+ import app .photofox .vipsffm .jextract .VipsArea ;
4+ import app .photofox .vipsffm .jextract .VipsRaw ;
5+
6+ import java .lang .foreign .Arena ;
37import java .lang .foreign .MemorySegment ;
8+ import java .nio .ByteBuffer ;
9+
10+ import static app .photofox .vipsffm .jextract .VipsRaw .C_LONG ;
411
512/**
613 * Represents a VipsBlob, boxed to avoid exposing its raw MemorySegment
714 */
815public final class VBlob {
916
17+ private final Arena arena ;
1018 final MemorySegment address ;
1119
12- VBlob (MemorySegment address ) throws VipsError {
20+ VBlob (
21+ Arena arena ,
22+ MemorySegment address
23+ ) throws VipsError {
1324 if (!VipsValidation .isValidPointer (address )) {
1425 throw new VipsError ("invalid pointer used for creation" );
1526 }
27+ this .arena = arena ;
1628 this .address = address ;
1729 }
1830
@@ -24,4 +36,18 @@ public final class VBlob {
2436 public MemorySegment getUnsafeAddress () {
2537 return this .address ;
2638 }
39+
40+ public long byteSize () {
41+ return VipsArea .length (this .address );
42+ }
43+
44+ public ByteBuffer asByteBuffer () {
45+ var lengthOutPointer = arena .allocate (C_LONG );
46+ var dataPointer = VipsRaw .vips_area_get_data (this .address , lengthOutPointer , MemorySegment .NULL , MemorySegment .NULL , MemorySegment .NULL );
47+ var length = lengthOutPointer .get (C_LONG , 0 );
48+ if (length < 0 ) {
49+ throw new VipsError ("unexpected length of vblob data " + length );
50+ }
51+ return dataPointer .asSlice (0 , length ).asByteBuffer ();
52+ }
2753}
0 commit comments