1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.unix;
17
18 import io.netty.util.internal.CleanableDirectBuffer;
19 import io.netty.util.internal.PlatformDependent;
20 import io.netty.util.internal.UnstableApi;
21
22 import java.nio.ByteBuffer;
23 import java.nio.ByteOrder;
24
25 @UnstableApi
26 public final class Buffer {
27
28 private Buffer() { }
29
30
31
32
33
34 @Deprecated
35 public static void free(ByteBuffer buffer) {
36 PlatformDependent.freeDirectBuffer(buffer);
37 }
38
39
40
41
42
43 @Deprecated
44 public static ByteBuffer allocateDirectWithNativeOrder(int capacity) {
45 return ByteBuffer.allocateDirect(capacity).order(
46 PlatformDependent.BIG_ENDIAN_NATIVE_ORDER ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
47 }
48
49
50
51
52
53 public static CleanableDirectBuffer allocateDirectBufferWithNativeOrder(int capacity) {
54 CleanableDirectBuffer cleanableDirectBuffer = PlatformDependent.allocateDirect(capacity);
55 cleanableDirectBuffer.buffer().order(
56 PlatformDependent.BIG_ENDIAN_NATIVE_ORDER ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
57 return cleanableDirectBuffer;
58 }
59
60
61
62
63 public static long memoryAddress(ByteBuffer buffer) {
64 assert buffer.isDirect();
65 if (PlatformDependent.hasUnsafe()) {
66 return PlatformDependent.directBufferAddress(buffer);
67 }
68 return memoryAddress0(buffer);
69 }
70
71
72
73
74 public static int addressSize() {
75 if (PlatformDependent.hasUnsafe()) {
76 return PlatformDependent.addressSize();
77 }
78 return addressSize0();
79 }
80
81
82 private static native int addressSize0();
83 private static native long memoryAddress0(ByteBuffer buffer);
84
85 public static ByteBuffer wrapMemoryAddressWithNativeOrder(long memoryAddress, int capacity) {
86 return wrapMemoryAddress(memoryAddress, capacity).order(ByteOrder.nativeOrder());
87 }
88
89 public static native ByteBuffer wrapMemoryAddress(long memoryAddress, int capacity);
90 }