Package org.h2.store.fs.mem
Class FileMemData
java.lang.Object
org.h2.store.fs.mem.FileMemData
This class contains the data of an in-memory random access file.
Data compression using the LZF algorithm is supported as well.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
This small cache compresses the data if an element leaves the cache.(package private) static class
Points to a block of bytes that needs to be compressed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final int
private static final byte[]
private static final int
private final boolean
private static final FileMemData.Cache
<FileMemData.CompressItem, FileMemData.CompressItem> private static final byte[]
private AtomicReference<byte[]>[]
private final int
private boolean
private boolean
private long
private long
private static final CompressLZF
private String
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) boolean
canWrite()
Check whether writing is allowed.private void
changeLength
(long len) (package private) void
compress
(int page) Compress the data in a byte array.private void
compressLater
(int page) private byte[]
expand
(int page) (package private) int
getId()
(package private) long
Get the last modified time.(package private) String
getName()
Get the file nameprivate byte[]
getPage
(int page) Get the page if it exists.(package private) long
length()
Get the file length.(package private) boolean
Lock the file in exclusive mode if possible.(package private) boolean
Lock the file in shared mode if possible.(package private) long
readWrite
(long pos, byte[] b, int off, int len, boolean write) Read or write.(package private) void
Set the file name.private void
setPage
(int page, byte[] oldData, byte[] newData, boolean force) Set the page data.(package private) boolean
Set the read-only flag.(package private) void
touch
(boolean openReadOnly) Update the last modified time.(package private) void
truncate
(long newLength) Truncate the file.(package private) void
unlock()
Unlock the file.
-
Field Details
-
CACHE_SIZE
private static final int CACHE_SIZE- See Also:
-
BLOCK_SIZE_SHIFT
private static final int BLOCK_SIZE_SHIFT- See Also:
-
BLOCK_SIZE
private static final int BLOCK_SIZE- See Also:
-
BLOCK_SIZE_MASK
private static final int BLOCK_SIZE_MASK- See Also:
-
LZF
-
BUFFER
private static final byte[] BUFFER -
COMPRESSED_EMPTY_BLOCK
private static final byte[] COMPRESSED_EMPTY_BLOCK -
COMPRESS_LATER
private static final FileMemData.Cache<FileMemData.CompressItem,FileMemData.CompressItem> COMPRESS_LATER -
name
-
id
private final int id -
compress
private final boolean compress -
length
private volatile long length -
data
-
lastModified
private long lastModified -
isReadOnly
private boolean isReadOnly -
isLockedExclusive
private boolean isLockedExclusive
-
-
Constructor Details
-
FileMemData
FileMemData(String name, boolean compress)
-
-
Method Details
-
getPage
private byte[] getPage(int page) Get the page if it exists.- Parameters:
page
- the page id- Returns:
- the byte array, or null
-
setPage
private void setPage(int page, byte[] oldData, byte[] newData, boolean force) Set the page data.- Parameters:
page
- the page idoldData
- the old datanewData
- the new dataforce
- whether the data should be overwritten even if the old data doesn't match
-
getId
int getId() -
lockExclusive
boolean lockExclusive()Lock the file in exclusive mode if possible.- Returns:
- if locking was successful
-
unlock
Unlock the file.- Throws:
IOException
-
compressLater
private void compressLater(int page) -
expand
private byte[] expand(int page) -
compress
void compress(int page) Compress the data in a byte array.- Parameters:
page
- which page to compress
-
touch
void touch(boolean openReadOnly) Update the last modified time.- Parameters:
openReadOnly
- if the file was opened in read-only mode
-
length
long length()Get the file length.- Returns:
- the length
-
truncate
void truncate(long newLength) Truncate the file.- Parameters:
newLength
- the new length
-
changeLength
private void changeLength(long len) -
readWrite
long readWrite(long pos, byte[] b, int off, int len, boolean write) Read or write.- Parameters:
pos
- the positionb
- the byte arrayoff
- the offset within the byte arraylen
- the number of byteswrite
- true for writing- Returns:
- the new position
-
setName
Set the file name.- Parameters:
name
- the name
-
getName
String getName()Get the file name- Returns:
- the name
-
getLastModified
long getLastModified()Get the last modified time.- Returns:
- the time
-
canWrite
boolean canWrite()Check whether writing is allowed.- Returns:
- true if it is
-
setReadOnly
boolean setReadOnly()Set the read-only flag.- Returns:
- true
-