Package org.h2.mvstore
Class WriteBuffer
java.lang.Object
org.h2.mvstore.WriteBuffer
An auto-resize buffer to write data into a ByteBuffer.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ByteBuffer
The current buffer (may be replaced if it is too small).private static final int
The maximum size of the buffer in order to be re-used after a clear operation.private static final int
The minimum number of bytes to grow a buffer at a time.private ByteBuffer
The buffer that is used after a clear operation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
capacity()
Get the capacity.clear()
Clear the buffer after use.private ByteBuffer
ensureCapacity
(int len) get
(byte[] dst) Copy the data into the destination array.Get the byte buffer.private void
grow
(int additional) int
limit()
Get the limit.limit
(int newLimit) Set the limit, possibly growing the buffer.int
position()
Get the current position.position
(int newPosition) Set the position.put
(byte x) Put a byte.put
(byte[] bytes) Put a byte array.put
(byte[] bytes, int offset, int length) Put a byte array.put
(ByteBuffer src) Put the contents of a byte buffer.putChar
(char x) Put a character.putDouble
(double x) Put a double.putFloat
(float x) Put a float.putInt
(int x) Put an integer.putInt
(int index, int value) Update an integer at the given index.putLong
(long x) Put a long.putShort
(int index, short value) Update a short at the given index.putShort
(short x) Put a short.putStringData
(String s, int len) Write the characters of a string in a format similar to UTF-8.putVarInt
(int x) Write a variable size integer.putVarLong
(long x) Write a variable size long.
-
Field Details
-
MAX_REUSE_CAPACITY
private static final int MAX_REUSE_CAPACITYThe maximum size of the buffer in order to be re-used after a clear operation.- See Also:
-
MIN_GROW
private static final int MIN_GROWThe minimum number of bytes to grow a buffer at a time.- See Also:
-
reuse
The buffer that is used after a clear operation. -
buff
The current buffer (may be replaced if it is too small).
-
-
Constructor Details
-
WriteBuffer
public WriteBuffer(int initialSize) -
WriteBuffer
public WriteBuffer()
-
-
Method Details
-
putVarInt
Write a variable size integer.- Parameters:
x
- the value- Returns:
- this
-
putVarLong
Write a variable size long.- Parameters:
x
- the value- Returns:
- this
-
putStringData
Write the characters of a string in a format similar to UTF-8.- Parameters:
s
- the stringlen
- the number of characters to write- Returns:
- this
-
put
Put a byte.- Parameters:
x
- the value- Returns:
- this
-
putChar
Put a character.- Parameters:
x
- the value- Returns:
- this
-
putShort
Put a short.- Parameters:
x
- the value- Returns:
- this
-
putInt
Put an integer.- Parameters:
x
- the value- Returns:
- this
-
putLong
Put a long.- Parameters:
x
- the value- Returns:
- this
-
putFloat
Put a float.- Parameters:
x
- the value- Returns:
- this
-
putDouble
Put a double.- Parameters:
x
- the value- Returns:
- this
-
put
Put a byte array.- Parameters:
bytes
- the value- Returns:
- this
-
put
Put a byte array.- Parameters:
bytes
- the valueoffset
- the source offsetlength
- the number of bytes- Returns:
- this
-
put
Put the contents of a byte buffer.- Parameters:
src
- the source buffer- Returns:
- this
-
limit
Set the limit, possibly growing the buffer.- Parameters:
newLimit
- the new limit- Returns:
- this
-
capacity
public int capacity()Get the capacity.- Returns:
- the capacity
-
position
Set the position.- Parameters:
newPosition
- the new position- Returns:
- the new position
-
limit
public int limit()Get the limit.- Returns:
- the limit
-
position
public int position()Get the current position.- Returns:
- the position
-
get
Copy the data into the destination array.- Parameters:
dst
- the destination array- Returns:
- this
-
putInt
Update an integer at the given index.- Parameters:
index
- the indexvalue
- the value- Returns:
- this
-
putShort
Update a short at the given index.- Parameters:
index
- the indexvalue
- the value- Returns:
- this
-
clear
Clear the buffer after use.- Returns:
- this
-
getBuffer
Get the byte buffer.- Returns:
- the byte buffer
-
ensureCapacity
-
grow
private void grow(int additional)
-