java.lang.Object
org.rrd4j.core.jrrd.RRDFile
- All Implemented Interfaces:
Constants
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intByte alignment of the values in the file.private static final MethodReflected clean method of the mapped buffer.private static final MethodReflected cleaner method of the mapped buffer.private static final byte[]ConstantFLOAT_COOKIE_BIG_ENDIAN={0x5B, 0x1F, 0x2B, 0x43, (byte) 0xC7, (byte) 0xC0, 0x25, 0x2F}private static final byte[]ConstantFLOAT_COOKIE_LITTLE_ENDIAN={0x2F, 0x25, (byte) 0xC0, (byte) 0xC7, 0x43, 0x2B, 0x1F, 0x5B}private static final MethodReflected unsafe method cleaning a buffer.private intByte size of a long in the file.private final MappedByteBufferMapping of the whole file.private ByteOrderByte order of the values in the file.private final FileInputStreamStream backing the mapped file.private static final ObjectUnsafe instance for unmapping, null if unavailable.Fields inherited from interface Constants
CF_NAM_SIZE, COOKIE, DS_NAM_SIZE, DST_SIZE, FLOAT_COOKIE, LAST_DS_LEN, MAX_SUPPORTED_VERSION, SIZE_OF_DOUBLE, UNDEFINED_VERSION, UNDEFINED_VERSION_AS_INT, VERSION_WITH_LAST_UPDATE_SECModifier and TypeFieldDescriptionstatic final intConstantCF_NAM_SIZE=20static final StringConstantCOOKIE="RRD"static final intConstantDS_NAM_SIZE=20static final intConstantDST_SIZE=20static final doubleConstantFLOAT_COOKIE=8.642135E130static final intConstantLAST_DS_LEN=30static final intConstantMAX_SUPPORTED_VERSION=3static final intConstantSIZE_OF_DOUBLE=8static final StringConstantUNDEFINED_VERSION="UNDEF"static final intConstantUNDEFINED_VERSION_AS_INT=-1static final intConstantVERSION_WITH_LAST_UPDATE_SEC=3Constructor Summary
Method Summary
Modifier and TypeMethodDescription(package private) intalign()Advances the read position to the file's own alignment.(package private) intalign(int boundary) Advances the read position to the given alignment boundary.(package private) voidclose()Close the file(package private) intByte alignment this file was mapped with.(package private) intgetBits()Width of a long in this file, in bits.(package private) longReports the current read position.(package private) UnivalArraygetUnivalArray(int size) Allocates a unival array at the current position.private intindexOf(byte[] pattern, byte[] array) Finds a byte pattern in an array.(package private) longinfo()Reports the current read position.private voidinitDataLayout(File file) Reads the data layout header of the file.(package private) booleanReports the byte order of the mapped file.(package private) voidread(ByteBuffer bb) Read bytes(package private) doubleReads a big-endian 8-byte float at the read position.(package private) intreadInt()Reads a 4-byte integer at the read position.(package private) intreadLong()Reads a long, narrowed to int, honouring this file's long size.(package private) StringreadString(int maxLength) Reads a fixed-width NUL-padded UTF-8 field.voidseek(long position) Moves the read position to an absolute offset.voidMoves the read position to the end of the mapped region.(package private) voidskipBytes(int n) Skip bytesprivate voidUnmaps the file so it can be deleted.
Field Details
FLOAT_COOKIE_BIG_ENDIAN
private static final byte[] FLOAT_COOKIE_BIG_ENDIANConstantFLOAT_COOKIE_BIG_ENDIAN={0x5B, 0x1F, 0x2B, 0x43, (byte) 0xC7, (byte) 0xC0, 0x25, 0x2F}FLOAT_COOKIE_LITTLE_ENDIAN
private static final byte[] FLOAT_COOKIE_LITTLE_ENDIANConstantFLOAT_COOKIE_LITTLE_ENDIAN={0x2F, 0x25, (byte) 0xC0, (byte) 0xC7, 0x43, 0x2B, 0x1F, 0x5B}CLEANER_METHOD
Reflected cleaner method of the mapped buffer.CLEAN_METHOD
Reflected clean method of the mapped buffer.INVOKE_CLEANER
Reflected unsafe method cleaning a buffer.UNSAFE
Unsafe instance for unmapping, null if unavailable.alignment
private int alignmentByte alignment of the values in the file.longSize
private int longSizeByte size of a long in the file.underlying
Stream backing the mapped file.mappedByteBuffer
Mapping of the whole file.order
Byte order of the values in the file.
Constructor Details
RRDFile
RRDFile(String name) throws IOException Open RRD file- Parameters:
name- the filesystem path of the RRD to memory-map- Throws:
IOException- if the file cannot be opened or mapped
RRDFile
RRDFile(File file) throws IOException Open RRD file- Parameters:
file- the RRD to memory-map read-only- Throws:
IOException- if the file cannot be opened or mapped, or if it is larger than 2**31 bytes, which a ByteBuffer cannot address
Method Details
initDataLayout
Reads the data layout header of the file.- Parameters:
file- the RRD file to read- Throws:
IOException- if the file cannot be read
indexOf
private int indexOf(byte[] pattern, byte[] array) Finds a byte pattern in an array.- Parameters:
pattern- the bytes to findarray- the array to search- Returns:
- the position, negative if absent
isBigEndian
boolean isBigEndian()Reports the byte order of the mapped file.- Returns:
- true when the order is big endian
getAlignment
int getAlignment()Byte alignment this file was mapped with.- Returns:
- 4 for 32 bit RRDs, 8 for 64 bit ones
readDouble
double readDouble()Reads a big-endian 8-byte float at the read position.- Returns:
- the big-endian double read from the mapped file, advancing the position by 8 bytes
readInt
int readInt()Reads a 4-byte integer at the read position.- Returns:
- the next 4-byte integer at the read position
readLong
int readLong()Reads a long, narrowed to int, honouring this file's long size.- Returns:
- the value read from the mapped file, narrowed to an int
readString
Reads a fixed-width NUL-padded UTF-8 field.- Parameters:
maxLength- the fixed field width to read, NUL padding included- Returns:
- the next fixed-width field decoded as UTF-8, with the NUL padding trimmed
skipBytes
void skipBytes(int n) Skip bytes- Parameters:
n- the number of bytes to advance the read position by
align
int align(int boundary) Advances the read position to the given alignment boundary.- Parameters:
boundary- the alignment boundary in bytes to advance to- Returns:
- the bytes skipped, 0 if already aligned
align
int align()Advances the read position to the file's own alignment.- Returns:
- the bytes skipped, 0 if already aligned
info
long info()Reports the current read position.- Returns:
- the byte offset of the next read in the mapped file
getFilePointer
long getFilePointer()Reports the current read position.- Returns:
- the byte offset of the next read
unmapFile
private void unmapFile()Unmaps the file so it can be deleted.close
Close the file- Throws:
IOException- if the underlying stream cannot be closed
read
getUnivalArray
Allocates a unival array at the current position.- Parameters:
size- the number of elements the array holds- Returns:
- a new array of size elements
getBits
int getBits()Width of a long in this file, in bits.- Returns:
- 32 or 64, the long size times 8
seek
public void seek(long position) Moves the read position to an absolute offset.- Parameters:
position- the absolute byte offset to read from next
seekToEndOfFile
public void seekToEndOfFile()Moves the read position to the end of the mapped region.