|
| 1 | +package io.ripc.core.io; |
| 2 | + |
| 3 | +import java.nio.ByteBuffer; |
| 4 | +import java.nio.charset.CharsetDecoder; |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +/** |
| 8 | + * Common abstraction to provide additional functionality beyond a traditional {@link java.nio.ByteBuffer} while not |
| 9 | + * restricting the dedicated functionality provided by concrete implementations from various transport libraries that |
| 10 | + * might offer features like zero-copy. |
| 11 | + * <p> |
| 12 | + * A {@code Buffer} can be anything. It is not limited to byte buffers. A {@code Buffer} could represent realized |
| 13 | + * objects descended from raw data. |
| 14 | + * </p> |
| 15 | + */ |
| 16 | +public interface Buffer<B> extends Cloneable, |
| 17 | + AutoCloseable, |
| 18 | + Comparable<Buffer<B>>, |
| 19 | + Iterable<Buffer<B>> { |
| 20 | + |
| 21 | + int position(); |
| 22 | + |
| 23 | + Buffer<B> position(int pos); |
| 24 | + |
| 25 | + int limit(); |
| 26 | + |
| 27 | + Buffer<B> limit(int limit); |
| 28 | + |
| 29 | + int capacity(); |
| 30 | + |
| 31 | + Buffer<B> capacity(int capacity); |
| 32 | + |
| 33 | + int remaining(); |
| 34 | + |
| 35 | + Buffer<B> skip(int len); |
| 36 | + |
| 37 | + Buffer<B> clear(); |
| 38 | + |
| 39 | + Buffer<B> compact(); |
| 40 | + |
| 41 | + Buffer<B> flip(); |
| 42 | + |
| 43 | + Buffer<B> rewind(); |
| 44 | + |
| 45 | + Buffer<B> rewind(int len); |
| 46 | + |
| 47 | + Buffer<B> clone(); |
| 48 | + |
| 49 | + Buffer<B> copy(); |
| 50 | + |
| 51 | + Buffer<B> slice(int start, int len); |
| 52 | + |
| 53 | + Iterable<Buffer<B>> split(byte delimiter); |
| 54 | + |
| 55 | + Iterable<Buffer<B>> split(byte delimiter, boolean stripDelimiter); |
| 56 | + |
| 57 | + Iterable<Buffer<B>> split(byte delimiter, boolean stripDelimiter, List<Buffer<B>> preallocatedList); |
| 58 | + |
| 59 | + Iterable<Buffer<B>> split(Buffer<B> delimiter); |
| 60 | + |
| 61 | + Iterable<Buffer<B>> split(Buffer<B> delimiter, boolean stripDelimiter); |
| 62 | + |
| 63 | + Iterable<Buffer<B>> split(Buffer<B> delimiter, boolean stripDelimiter, List<Buffer<B>> preallocatedList); |
| 64 | + |
| 65 | + Buffer<B> prepend(B data); |
| 66 | + |
| 67 | + Buffer<B> prepend(Buffer<B> buffer); |
| 68 | + |
| 69 | + Buffer<B> prepend(ByteBuffer buffer); |
| 70 | + |
| 71 | + Buffer<B> prepend(CharSequence chars); |
| 72 | + |
| 73 | + Buffer<B> prepend(byte[] bytes); |
| 74 | + |
| 75 | + Buffer<B> prepend(byte b); |
| 76 | + |
| 77 | + Buffer<B> prepend(char c); |
| 78 | + |
| 79 | + Buffer<B> prepend(short s); |
| 80 | + |
| 81 | + Buffer<B> prepend(int i); |
| 82 | + |
| 83 | + Buffer<B> prepend(long l); |
| 84 | + |
| 85 | + Buffer<B> append(B data); |
| 86 | + |
| 87 | + Buffer<B> append(Buffer<B> buffer); |
| 88 | + |
| 89 | + Buffer<B> append(ByteBuffer buffer); |
| 90 | + |
| 91 | + Buffer<B> append(CharSequence chars); |
| 92 | + |
| 93 | + Buffer<B> append(byte[] bytes); |
| 94 | + |
| 95 | + Buffer<B> append(byte b); |
| 96 | + |
| 97 | + Buffer<B> append(char c); |
| 98 | + |
| 99 | + Buffer<B> append(short s); |
| 100 | + |
| 101 | + Buffer<B> append(int i); |
| 102 | + |
| 103 | + Buffer<B> append(long l); |
| 104 | + |
| 105 | + byte readByte(); |
| 106 | + |
| 107 | + void readBytes(byte[] bytes); |
| 108 | + |
| 109 | + short readShort(); |
| 110 | + |
| 111 | + int readInt(); |
| 112 | + |
| 113 | + float readFloat(); |
| 114 | + |
| 115 | + double readDouble(); |
| 116 | + |
| 117 | + long readLong(); |
| 118 | + |
| 119 | + char readChar(); |
| 120 | + |
| 121 | + void readChars(char[] chars); |
| 122 | + |
| 123 | + String readString(); |
| 124 | + |
| 125 | + String readString(CharsetDecoder decoder); |
| 126 | + |
| 127 | + B get(); |
| 128 | + |
| 129 | +} |
0 commit comments