Skip to content

Package: MemoryUtils

MemoryUtils

nameinstructionbranchcomplexitylinemethod
MemoryUtils()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
allocateByteBuffer(MemoryManager, int)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
reallocateByteBuffer(MemoryManager, ByteBuffer, int)
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
releaseByteBuffer(MemoryManager, ByteBuffer)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.glassfish.grizzly.memory;
18:
19: import java.nio.ByteBuffer;
20:
21: import org.glassfish.grizzly.Buffer;
22:
23: /**
24: * Class has useful methods to simplify the work with {@link Buffer}s.
25: *
26: * @see MemoryManager
27: * @see WrapperAware
28: *
29: * @author Alexey Stashok
30: */
31: public class MemoryUtils {
32: public static ByteBuffer allocateByteBuffer(MemoryManager memoryManager, int size) {
33:• if (memoryManager instanceof ByteBufferAware) {
34: return ((ByteBufferAware) memoryManager).allocateByteBuffer(size);
35: }
36:
37: return ByteBuffer.allocate(size);
38: }
39:
40: public static ByteBuffer reallocateByteBuffer(MemoryManager memoryManager, ByteBuffer oldByteBuffer, int size) {
41:• if (memoryManager instanceof ByteBufferAware) {
42: return ((ByteBufferAware) memoryManager).reallocateByteBuffer(oldByteBuffer, size);
43: }
44:
45: return ByteBuffer.allocate(size);
46: }
47:
48: public static void releaseByteBuffer(MemoryManager memoryManager, ByteBuffer byteBuffer) {
49:• if (memoryManager instanceof ByteBufferAware) {
50: ((ByteBufferAware) memoryManager).releaseByteBuffer(byteBuffer);
51: }
52: }
53: }