View Javadoc
1   /*
2    * Copyright 2021 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.handler.codec.quic;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.ByteBufAllocator;
20  import io.netty.buffer.CompositeByteBuf;
21  
22  final class DirectIoByteBufAllocator implements ByteBufAllocator {
23  
24      private final ByteBufAllocator wrapped;
25  
26      DirectIoByteBufAllocator(ByteBufAllocator wrapped) {
27          if (wrapped instanceof DirectIoByteBufAllocator) {
28              wrapped = ((DirectIoByteBufAllocator) wrapped).wrapped();
29          }
30          this.wrapped = wrapped;
31      }
32  
33      ByteBufAllocator wrapped() {
34          return wrapped;
35      }
36  
37      @Override
38      public ByteBuf buffer() {
39          return wrapped.buffer();
40      }
41  
42      @Override
43      public ByteBuf buffer(int initialCapacity) {
44          return wrapped.buffer(initialCapacity);
45      }
46  
47      @Override
48      public ByteBuf buffer(int initialCapacity, int maxCapacity) {
49          return wrapped.buffer(initialCapacity, maxCapacity);
50      }
51  
52      @Override
53      public ByteBuf ioBuffer() {
54          return directBuffer();
55      }
56  
57      @Override
58      public ByteBuf ioBuffer(int initialCapacity) {
59          return directBuffer(initialCapacity);
60      }
61  
62      @Override
63      public ByteBuf ioBuffer(int initialCapacity, int maxCapacity) {
64          return directBuffer(initialCapacity, maxCapacity);
65      }
66  
67      @Override
68      public ByteBuf heapBuffer() {
69          return wrapped.heapBuffer();
70      }
71  
72      @Override
73      public ByteBuf heapBuffer(int initialCapacity) {
74          return wrapped.heapBuffer(initialCapacity);
75      }
76  
77      @Override
78      public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) {
79          return wrapped.heapBuffer(initialCapacity, maxCapacity);
80      }
81  
82      @Override
83      public ByteBuf directBuffer() {
84          return wrapped.directBuffer();
85      }
86  
87      @Override
88      public ByteBuf directBuffer(int initialCapacity) {
89          return wrapped.directBuffer(initialCapacity);
90      }
91  
92      @Override
93      public ByteBuf directBuffer(int initialCapacity, int maxCapacity) {
94          return wrapped.directBuffer(initialCapacity, maxCapacity);
95      }
96  
97      @Override
98      public CompositeByteBuf compositeBuffer() {
99          return wrapped.compositeBuffer();
100     }
101 
102     @Override
103     public CompositeByteBuf compositeBuffer(int maxNumComponents) {
104         return wrapped.compositeBuffer(maxNumComponents);
105     }
106 
107     @Override
108     public CompositeByteBuf compositeHeapBuffer() {
109         return wrapped.compositeHeapBuffer();
110     }
111 
112     @Override
113     public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
114         return wrapped.compositeHeapBuffer(maxNumComponents);
115     }
116 
117     @Override
118     public CompositeByteBuf compositeDirectBuffer() {
119         return wrapped.compositeDirectBuffer();
120     }
121 
122     @Override
123     public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {
124         return wrapped.compositeDirectBuffer(maxNumComponents);
125     }
126 
127     @Override
128     public boolean isDirectBufferPooled() {
129         return wrapped.isDirectBufferPooled();
130     }
131 
132     @Override
133     public int calculateNewCapacity(int minNewCapacity, int maxCapacity) {
134         return wrapped.calculateNewCapacity(minNewCapacity, maxCapacity);
135     }
136 }