public class Data extends Object
Modifier and Type | Field and Description |
---|---|
static int |
LENGTH_INT
The length of an integer value.
|
Modifier and Type | Method and Description |
---|---|
void |
checkCapacity(int plus)
Check if there is still enough capacity in the buffer.
|
static void |
copyString(Reader source,
OutputStream target)
Copy a String from a reader to an output stream.
|
static Data |
create(DataHandler handler,
byte[] buff)
Create a new buffer using the given data for the given handler.
|
static Data |
create(DataHandler handler,
int capacity)
Create a new buffer for the given handler.
|
void |
fillAligned()
Fill up the buffer with empty space and an (initially empty) checksum
until the size is a multiple of Constants.FILE_BLOCK_SIZE.
|
byte[] |
getBytes()
Get the byte array used for this page.
|
DataHandler |
getHandler() |
static int |
getStringLen(String s)
Get the length of a String.
|
int |
getValueLen(Value v)
Calculate the number of bytes required to encode the given value.
|
static int |
getVarLongLen(long x)
The number of bytes required for a variable size long.
|
int |
length()
Get the current write position of this buffer, which is the current
length.
|
void |
read(byte[] buff,
int off,
int len)
Copy a number of bytes to the given buffer from the current position.
|
byte |
readByte()
Read one single byte.
|
int |
readInt()
Read an integer at the current position.
|
long |
readLong()
Read a long value.
|
short |
readShortInt()
Read an short integer at the current position.
|
String |
readString()
Read a String value.
|
Value |
readValue()
Read a value.
|
int |
readVarInt()
Read a variable size int.
|
long |
readVarLong()
Read a variable size long.
|
void |
reset()
Set the position to 0.
|
void |
setInt(int pos,
int x)
Update an integer at the given position.
|
void |
setPos(int pos)
Set the current read / write position.
|
void |
truncate(int size)
Shrink the array to this size.
|
void |
write(byte[] buff,
int off,
int len)
Append a number of bytes to this buffer.
|
void |
writeByte(byte x)
Append one single byte.
|
void |
writeInt(int x)
Write an integer at the current position.
|
void |
writeLong(long x)
Append a long value.
|
void |
writeShortInt(int x)
Write a short integer at the current position.
|
void |
writeString(String s)
Write a String.
|
void |
writeValue(Value v)
Append a value.
|
void |
writeVarInt(int x)
Write a variable size int.
|
void |
writeVarLong(long x)
Write a variable size long.
|
public static final int LENGTH_INT
public void setInt(int pos, int x)
pos
- the positionx
- the valuepublic void writeInt(int x)
x
- the valuepublic int readInt()
public static int getStringLen(String s)
s
- the stringpublic String readString()
public void writeString(String s)
s
- the valuepublic static Data create(DataHandler handler, int capacity)
handler
- the data handlercapacity
- the initial capacity of the bufferpublic static Data create(DataHandler handler, byte[] buff)
handler
- the data handlerbuff
- the datapublic int length()
public byte[] getBytes()
public void reset()
public void write(byte[] buff, int off, int len)
buff
- the dataoff
- the offset in the datalen
- the length in bytespublic void read(byte[] buff, int off, int len)
buff
- the output bufferoff
- the offset in the output bufferlen
- the number of bytes to copypublic void writeByte(byte x)
x
- the valuepublic byte readByte()
public long readLong()
public void writeLong(long x)
x
- the valuepublic void writeValue(Value v)
v
- the valuepublic Value readValue()
public int getValueLen(Value v)
v
- the valuepublic void setPos(int pos)
pos
- the new positionpublic void writeShortInt(int x)
x
- the valuepublic short readShortInt()
public void truncate(int size)
size
- the new sizepublic void writeVarInt(int x)
x
- the valuepublic int readVarInt()
public static int getVarLongLen(long x)
x
- the valuepublic void writeVarLong(long x)
x
- the valuepublic long readVarLong()
public void checkCapacity(int plus)
plus
- the number of additional bytes requiredpublic void fillAligned()
public static void copyString(Reader source, OutputStream target) throws IOException
source
- the readertarget
- the output streamIOException
public DataHandler getHandler()
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.