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