@@ -55,20 +55,8 @@ public class ZstdByteBuffDecompressor implements ByteBuffDecompressor, CanReinit
55
55
56
56
@ Override
57
57
public boolean canDecompress (ByteBuff output , ByteBuff input ) {
58
- if (!allowByteBuffDecompression ) {
59
- return false ;
60
- }
61
- if (output instanceof SingleByteBuff && input instanceof SingleByteBuff ) {
62
- ByteBuffer nioOutput = output .nioByteBuffers ()[0 ];
63
- ByteBuffer nioInput = input .nioByteBuffers ()[0 ];
64
- if (nioOutput .isDirect () && nioInput .isDirect ()) {
65
- return true ;
66
- } else if (!nioOutput .isDirect () && !nioInput .isDirect ()) {
67
- return true ;
68
- }
69
- }
70
-
71
- return false ;
58
+ return allowByteBuffDecompression && output instanceof SingleByteBuff
59
+ && input instanceof SingleByteBuff ;
72
60
}
73
61
74
62
@ Override
@@ -80,38 +68,35 @@ private int decompressRaw(ByteBuff output, ByteBuff input, int inputLen) throws
80
68
if (output instanceof SingleByteBuff && input instanceof SingleByteBuff ) {
81
69
ByteBuffer nioOutput = output .nioByteBuffers ()[0 ];
82
70
ByteBuffer nioInput = input .nioByteBuffers ()[0 ];
71
+ int origOutputPos = nioOutput .position ();
72
+ int n ;
83
73
if (nioOutput .isDirect () && nioInput .isDirect ()) {
84
- return decompressDirectByteBuffers (nioOutput , nioInput , inputLen );
74
+ n = ctx .decompressDirectByteBuffer (nioOutput , nioOutput .position (),
75
+ nioOutput .limit () - nioOutput .position (), nioInput , nioInput .position (), inputLen );
85
76
} else if (!nioOutput .isDirect () && !nioInput .isDirect ()) {
86
- return decompressHeapByteBuffers (nioOutput , nioInput , inputLen );
77
+ n = ctx .decompressByteArray (nioOutput .array (),
78
+ nioOutput .arrayOffset () + nioOutput .position (), nioOutput .limit () - nioOutput .position (),
79
+ nioInput .array (), nioInput .arrayOffset () + nioInput .position (), inputLen );
80
+ } else if (nioOutput .isDirect () && !nioInput .isDirect ()) {
81
+ n = ctx .decompressByteArrayToDirectByteBuffer (nioOutput , nioOutput .position (),
82
+ nioOutput .limit () - nioOutput .position (), nioInput .array (),
83
+ nioInput .arrayOffset () + nioInput .position (), inputLen );
84
+ } else if (!nioOutput .isDirect () && nioInput .isDirect ()) {
85
+ n = ctx .decompressDirectByteBufferToByteArray (nioOutput .array (),
86
+ nioOutput .arrayOffset () + nioOutput .position (), nioOutput .limit () - nioOutput .position (),
87
+ nioInput , nioInput .position (), inputLen );
88
+ } else {
89
+ throw new IllegalStateException ("Unreachable line" );
87
90
}
88
- }
89
-
90
- throw new IllegalStateException ("One buffer is direct and the other is not, "
91
- + "or one or more not SingleByteBuffs. This is not supported" );
92
- }
93
91
94
- private int decompressDirectByteBuffers ( ByteBuffer output , ByteBuffer input , int inputLen ) {
95
- int origOutputPos = output .position ();
92
+ nioOutput . position ( origOutputPos + n );
93
+ nioInput .position (input . position () + inputLen );
96
94
97
- int n = ctx .decompressDirectByteBuffer (output , output .position (),
98
- output .limit () - output .position (), input , input .position (), inputLen );
99
-
100
- output .position (origOutputPos + n );
101
- input .position (input .position () + inputLen );
102
- return n ;
103
- }
104
-
105
- private int decompressHeapByteBuffers (ByteBuffer output , ByteBuffer input , int inputLen ) {
106
- int origOutputPos = output .position ();
107
-
108
- int n = ctx .decompressByteArray (output .array (), output .arrayOffset () + output .position (),
109
- output .limit () - output .position (), input .array (), input .arrayOffset () + input .position (),
110
- inputLen );
111
-
112
- output .position (origOutputPos + n );
113
- input .position (input .position () + inputLen );
114
- return n ;
95
+ return n ;
96
+ } else {
97
+ throw new IllegalStateException (
98
+ "At least one buffer is not a SingleByteBuff, this is not supported" );
99
+ }
115
100
}
116
101
117
102
@ Override
0 commit comments