@@ -234,6 +234,60 @@ public int decompressByteArray(byte[] dstBuff, int dstOffset, int dstSize, byte[
234
234
235
235
private static native long decompressByteArray0 (long nativePtr , byte [] dst , int dstOffset , int dstSize , byte [] src , int srcOffset , int srcSize );
236
236
237
+ public int decompressByteArrayToDirectByteBuffer (ByteBuffer dstBuff , int dstOffset , int dstSize , byte [] srcBuff , int srcOffset , int srcSize ) {
238
+ if (!dstBuff .isDirect ()) {
239
+ throw new IllegalArgumentException ("dstBuff must be a direct buffer" );
240
+ }
241
+
242
+ Objects .checkFromIndexSize (srcOffset , srcSize , srcBuff .length );
243
+ Objects .checkFromIndexSize (dstOffset , dstSize , dstBuff .limit ());
244
+
245
+ ensureOpen ();
246
+ acquireSharedLock ();
247
+
248
+ try {
249
+ long size = decompressByteArrayToDirectByteBuffer0 (nativePtr , dstBuff , dstOffset , dstSize , srcBuff , srcOffset , srcSize );
250
+ if (Zstd .isError (size )) {
251
+ throw new ZstdException (size );
252
+ }
253
+ if (size > Integer .MAX_VALUE ) {
254
+ throw new ZstdException (Zstd .errGeneric (), "Output size is greater than MAX_INT" );
255
+ }
256
+ return (int ) size ;
257
+ } finally {
258
+ releaseSharedLock ();
259
+ }
260
+ }
261
+
262
+ private static native long decompressByteArrayToDirectByteBuffer0 (long nativePtr , ByteBuffer dst , int dstOffset , int dstSize , byte [] src , int srcOffset , int srcSize );
263
+
264
+ public int decompressDirectByteBufferToByteArray (byte [] dstBuff , int dstOffset , int dstSize , ByteBuffer srcBuff , int srcOffset , int srcSize ) {
265
+ if (!srcBuff .isDirect ()) {
266
+ throw new IllegalArgumentException ("srcBuff must be a direct buffer" );
267
+ }
268
+
269
+ Objects .checkFromIndexSize (srcOffset , srcSize , srcBuff .limit ());
270
+ Objects .checkFromIndexSize (dstOffset , dstSize , dstBuff .length );
271
+
272
+ ensureOpen ();
273
+ acquireSharedLock ();
274
+
275
+ try {
276
+ long size = decompressDirectByteBufferToByteArray0 (nativePtr , dstBuff , dstOffset , dstSize , srcBuff , srcOffset , srcSize );
277
+ if (Zstd .isError (size )) {
278
+ throw new ZstdException (size );
279
+ }
280
+ if (size > Integer .MAX_VALUE ) {
281
+ throw new ZstdException (Zstd .errGeneric (), "Output size is greater than MAX_INT" );
282
+ }
283
+ return (int ) size ;
284
+ } finally {
285
+ releaseSharedLock ();
286
+ }
287
+ }
288
+
289
+ private static native long decompressDirectByteBufferToByteArray0 (long nativePtr , byte [] dst , int dstOffset , int dstSize , ByteBuffer src , int srcOffset , int srcSize );
290
+
237
291
/* Covenience methods */
238
292
239
293
/**
@@ -257,16 +311,38 @@ public int decompressByteArray(byte[] dstBuff, int dstOffset, int dstSize, byte[
257
311
*/
258
312
public int decompress (ByteBuffer dstBuf , ByteBuffer srcBuf ) throws ZstdException {
259
313
int size = decompressDirectByteBuffer (dstBuf , // decompress into dstBuf
260
- dstBuf .position (), // write decompressed data at offset position()
261
- dstBuf .limit () - dstBuf .position (), // write no more than limit() - position()
262
- srcBuf , // read compressed data from srcBuf
263
- srcBuf .position (), // read starting at offset position()
264
- srcBuf .limit () - srcBuf .position ()); // read no more than limit() - position()
314
+ dstBuf .position (), // write decompressed data at offset position()
315
+ dstBuf .limit () - dstBuf .position (), // write no more than limit() - position()
316
+ srcBuf , // read compressed data from srcBuf
317
+ srcBuf .position (), // read starting at offset position()
318
+ srcBuf .limit () - srcBuf .position ()); // read no more than limit() - position()
265
319
srcBuf .position (srcBuf .limit ());
266
320
dstBuf .position (dstBuf .position () + size );
267
321
return size ;
268
322
}
269
323
324
+ public int decompress (ByteBuffer dstBuf , byte [] src ) throws ZstdException {
325
+ int size = decompressByteArrayToDirectByteBuffer (dstBuf , // decompress into dstBuf
326
+ dstBuf .position (), // write decompressed data at offset position()
327
+ dstBuf .limit () - dstBuf .position (), // write no more than limit() - position()
328
+ src , // read compressed data from src
329
+ 0 ,
330
+ src .length );
331
+ dstBuf .position (dstBuf .position () + size );
332
+ return size ;
333
+ }
334
+
335
+ public int decompress (byte [] dst , ByteBuffer srcBuf ) throws ZstdException {
336
+ int size = decompressDirectByteBufferToByteArray (dst , // decompress into dst
337
+ 0 ,
338
+ dst .length ,
339
+ srcBuf , // read compressed data from srcBuf
340
+ srcBuf .position (), // read starting at offset position()
341
+ srcBuf .limit () - srcBuf .position ()); // read no more than limit() - position()
342
+ srcBuf .position (srcBuf .limit ());
343
+ return size ;
344
+ }
345
+
270
346
public ByteBuffer decompress (ByteBuffer srcBuf , int originalSize ) throws ZstdException {
271
347
ByteBuffer dstBuf = ByteBuffer .allocateDirect (originalSize );
272
348
int size = decompressDirectByteBuffer (dstBuf , 0 , originalSize , srcBuf , srcBuf .position (), srcBuf .limit () - srcBuf .position ());
0 commit comments