View Javadoc
1   /*
2    * Copyright 2018 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.channel.unix;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.ByteBufAllocator;
20  import io.netty.buffer.CompositeByteBuf;
21  import io.netty.util.internal.UnstableApi;
22  
23  @UnstableApi
24  public final class PreferredDirectByteBufAllocator implements ByteBufAllocator {
25      private ByteBufAllocator allocator;
26  
27      public void updateAllocator(ByteBufAllocator allocator) {
28          this.allocator = allocator;
29      }
30  
31      @Override
32      public ByteBuf buffer() {
33          return allocator.directBuffer();
34      }
35  
36      @Override
37      public ByteBuf buffer(int initialCapacity) {
38          return allocator.directBuffer(initialCapacity);
39      }
40  
41      @Override
42      public ByteBuf buffer(int initialCapacity, int maxCapacity) {
43          return allocator.directBuffer(initialCapacity, maxCapacity);
44      }
45  
46      @Override
47      public ByteBuf ioBuffer() {
48          return allocator.directBuffer();
49      }
50  
51      @Override
52      public ByteBuf ioBuffer(int initialCapacity) {
53          return allocator.directBuffer(initialCapacity);
54      }
55  
56      @Override
57      public ByteBuf ioBuffer(int initialCapacity, int maxCapacity) {
58          return allocator.directBuffer(initialCapacity, maxCapacity);
59      }
60  
61      @Override
62      public ByteBuf heapBuffer() {
63          return allocator.heapBuffer();
64      }
65  
66      @Override
67      public ByteBuf heapBuffer(int initialCapacity) {
68          return allocator.heapBuffer(initialCapacity);
69      }
70  
71      @Override
72      public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) {
73          return allocator.heapBuffer(initialCapacity, maxCapacity);
74      }
75  
76      @Override
77      public ByteBuf directBuffer() {
78          return allocator.directBuffer();
79      }
80  
81      @Override
82      public ByteBuf directBuffer(int initialCapacity) {
83          return allocator.directBuffer(initialCapacity);
84      }
85  
86      @Override
87      public ByteBuf directBuffer(int initialCapacity, int maxCapacity) {
88          return allocator.directBuffer(initialCapacity, maxCapacity);
89      }
90  
91      @Override
92      public CompositeByteBuf compositeBuffer() {
93          return allocator.compositeDirectBuffer();
94      }
95  
96      @Override
97      public CompositeByteBuf compositeBuffer(int maxNumComponents) {
98          return allocator.compositeDirectBuffer(maxNumComponents);
99      }
100 
101     @Override
102     public CompositeByteBuf compositeHeapBuffer() {
103         return allocator.compositeHeapBuffer();
104     }
105 
106     @Override
107     public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
108         return allocator.compositeHeapBuffer(maxNumComponents);
109     }
110 
111     @Override
112     public CompositeByteBuf compositeDirectBuffer() {
113         return allocator.compositeDirectBuffer();
114     }
115 
116     @Override
117     public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {
118         return allocator.compositeDirectBuffer(maxNumComponents);
119     }
120 
121     @Override
122     public boolean isDirectBufferPooled() {
123         return allocator.isDirectBufferPooled();
124     }
125 
126     @Override
127     public int calculateNewCapacity(int minNewCapacity, int maxCapacity) {
128         return allocator.calculateNewCapacity(minNewCapacity, maxCapacity);
129     }
130 }