forked from maxmind/MaxMind-DB-Reader-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuffer.java
More file actions
117 lines (103 loc) · 2.83 KB
/
Buffer.java
File metadata and controls
117 lines (103 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.maxmind.db;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
/**
* A generic buffer abstraction that supports sequential and random access
* to binary data. Implementations may be backed by a single {@link
* java.nio.ByteBuffer} or multiple buffers for larger capacities.
*
* <p>This interface is designed to provide a long-based API while
* remaining compatible with the limitations of underlying storage.
*/
interface Buffer {
/**
* Returns the total capacity of this buffer in bytes.
*
* @return the capacity
*/
long capacity();
/**
* Returns the current position of this buffer.
*
* @return the position
*/
long position();
/**
* Sets the buffer's position.
*
* @param newPosition the new position
* @return this buffer
*/
Buffer position(long newPosition);
/**
* Returns the current limit of this buffer.
*
* @return the limit
*/
long limit();
/**
* Sets the buffer's limit.
*
* @param newLimit the new limit
* @return this buffer
*/
Buffer limit(long newLimit);
/**
* Reads the next byte at the current position and advances the position.
*
* @return the byte value
*/
byte get();
/**
* Reads bytes into the given array and advances the position.
*
* @param dst the destination array
* @return this buffer
*/
Buffer get(byte[] dst);
/**
* Reads a byte at the given absolute index without changing the position.
*
* @param index the index to read from
* @return the byte value
*/
byte get(long index);
/**
* Reads the next 8 bytes as a double and advances the position.
*
* @return the double value
*/
double getDouble();
/**
* Reads the next 4 bytes as a float and advances the position.
*
* @return the float value
*/
float getFloat();
/**
* Creates a new buffer that shares the same content but has independent
* position, limit, and mark values.
*
* @return a duplicate buffer
*/
Buffer duplicate();
/**
* Reads data from the given channel into this buffer starting at the
* current position.
*
* @param channel the file channel
* @return the number of bytes read
* @throws IOException if an I/O error occurs
*/
long readFrom(FileChannel channel) throws IOException;
/**
* Decodes the buffer's content into a string using the given decoder.
*
* @param decoder the charset decoder
* @return the decoded string
* @throws CharacterCodingException if decoding fails
*/
String decode(CharsetDecoder decoder) throws CharacterCodingException;
}