Skip to content

Package: CompositeBuffer$DisposeOrder

CompositeBuffer$DisposeOrder

nameinstructionbranchcomplexitylinemethod
static {...}
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2010, 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 org.glassfish.grizzly.Buffer;
20:
21: /**
22: *
23: * @author Alexey Stashok
24: */
25: public abstract class CompositeBuffer implements Buffer {
26: /**
27: * The order in which internal {@link Buffer}s will be disposed.
28: */
29: public enum DisposeOrder {
30: LAST_TO_FIRST, FIRST_TO_LAST
31: }
32:
33: protected DisposeOrder disposeOrder = DisposeOrder.LAST_TO_FIRST;
34:
35: /**
36: * Construct <tt>CompositeBuffer</tt>.
37: *
38: * @return new <tt>CompositeBuffer</tt>
39: */
40: public static CompositeBuffer newBuffer() {
41: return BuffersBuffer.create();
42: }
43:
44: public static CompositeBuffer newBuffer(final MemoryManager memoryManager) {
45: return BuffersBuffer.create(memoryManager);
46: }
47:
48: public static CompositeBuffer newBuffer(final MemoryManager memoryManager, final Buffer... buffers) {
49: return BuffersBuffer.create(memoryManager, buffers);
50: }
51:
52: public static CompositeBuffer newBuffer(final MemoryManager memoryManager, final Buffer[] buffers, final boolean isReadOnly) {
53: return BuffersBuffer.create(memoryManager, buffers, isReadOnly);
54: }
55:
56: /**
57: * Returns the order in which internal {@link Buffer}s will be disposed.
58: *
59: * @return {@link DisposeOrder}
60: */
61: public DisposeOrder disposeOrder() {
62: return disposeOrder;
63: }
64:
65: /**
66: * Sets the order in which internal {@link Buffer}s will be disposed.
67: *
68: * @param disposeOrder
69: * @return this buffer
70: */
71: public CompositeBuffer disposeOrder(final DisposeOrder disposeOrder) {
72: this.disposeOrder = disposeOrder;
73: return this;
74: }
75:
76: public abstract CompositeBuffer append(Buffer buffer);
77:
78: @Override
79: public abstract CompositeBuffer prepend(Buffer buffer);
80:
81: @Override
82: public abstract Object[] underlying();
83:
84: /**
85: * Removes underlying {@link Buffer}s, without disposing
86: */
87: public abstract void removeAll();
88:
89: public abstract void allowInternalBuffersDispose(boolean allow);
90:
91: public abstract boolean allowInternalBuffersDispose();
92:
93: /**
94: * Iterates over {@link Buffer} bytes from {@link #position()} to {@link #limit()} and lets {@link BulkOperation}
95: * examine/change the buffer content;
96: *
97: * @param operation {@link BulkOperation}
98: * @return <tt>Buffer</tt> position the processing was stopped on, or <tt>-1</tt>, if processing reached the limit.
99: */
100: public abstract int bulk(BulkOperation operation);
101:
102: /**
103: * Iterates over {@link Buffer} bytes from position to limit and lets {@link BulkOperation} examine/change the buffer
104: * content;
105: *
106: * @param operation {@link BulkOperation}
107: * @return <tt>Buffer</tt> position the processing was stopped on, or <tt>-1</tt>, if processing reached the limit.
108: */
109: public abstract int bulk(BulkOperation operation, int position, int limit);
110:
111: /**
112: * Replace one internal {@link Buffer} with another one.
113: *
114: * @param oldBuffer the {@link Buffer} to replace.
115: * @param newBuffer the new {@link Buffer}.
116: * @return <tt>true</tt>, if the oldBuffer was found and replaced, or <tt>false</tt> otherwise.
117: */
118: public abstract boolean replace(Buffer oldBuffer, Buffer newBuffer);
119:
120: /**
121: * Bulk Buffer operation, responsible for byte-by-byte Buffer processing.
122: */
123: public interface BulkOperation {
124: /**
125: * Method is responsible to examine/change one single Buffer's byte.
126: *
127: * @param setter {@link Setter}
128: * @return <tt>true</tt>, if we want bulk processing stop, or <tt>false</tt> to continue processing.
129: */
130: boolean processByte(byte value, Setter setter);
131: }
132:
133: /**
134: * Setter.
135: */
136: public interface Setter {
137: /**
138: * Set the current byte value.
139: *
140: * @param value value
141: */
142: void set(byte value);
143: }
144: }