Skip to content

Package: WrapperAware

WrapperAware

Coverage

1: /*
2: * Copyright (c) 2009, 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: import java.nio.charset.Charset;
21:
22: import org.glassfish.grizzly.Buffer;
23:
24: /**
25: * {@link MemoryManager}s, which implement this interface, are able to convert frequently used Java buffer types to
26: * Grizzly {@link Buffer}.
27: *
28: * @see MemoryUtils
29: * @see MemoryManager
30: *
31: * @author Alexey Stashok
32: */
33: public interface WrapperAware {
34: /**
35: * Returns {@link Buffer}, which wraps the byte array.
36: *
37: * @param data byte array to wrap
38: *
39: * @return {@link Buffer} wrapper on top of passed byte array.
40: */
41: Buffer wrap(byte[] data);
42:
43: /**
44: * Returns {@link Buffer}, which wraps the part of byte array with specific offset and length.
45: *
46: * @param data byte array to wrap
47: * @param offset byte buffer offset
48: * @param length byte buffer length
49: *
50: * @return {@link Buffer} wrapper on top of passed byte array.
51: */
52: Buffer wrap(byte[] data, int offset, int length);
53:
54: /**
55: * Returns {@link Buffer}, which wraps the {@link String}.
56: *
57: * @param s {@link String}
58: *
59: * @return {@link Buffer} wrapper on top of passed {@link String}.
60: */
61: Buffer wrap(String s);
62:
63: /**
64: * Returns {@link Buffer}, which wraps the {@link String} with the specific {@link Charset}.
65: *
66: * @param s {@link String}
67: * @param charset {@link Charset}, which will be used, when converting {@link String} to byte array.
68: *
69: * @return {@link Buffer} wrapper on top of passed {@link String}.
70: */
71: Buffer wrap(String s, Charset charset);
72:
73: /**
74: * Returns {@link Buffer}, which wraps the {@link ByteBuffer}.
75: *
76: * @param byteBuffer {@link ByteBuffer} to wrap
77: *
78: * @return {@link Buffer} wrapper on top of passed {@link ByteBuffer}.
79: */
80: Buffer wrap(ByteBuffer byteBuffer);
81: }