Package edu.caltech.nanodb.storage
Class DBFileWriter
- java.lang.Object
-
- edu.caltech.nanodb.storage.DBFileReader
-
- edu.caltech.nanodb.storage.DBFileWriter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class DBFileWriter extends DBFileReader
A subclass of
DBFileReader
, this class provides the basic ability to read and write aDBFile
as a single sequential file, obscuring the fact that it is actually broken into pages. As the file-pointer moves through the file, the Storage Manager is used to load individual pages into the buffer manager.It is certainly possible that a value being read or written might span two adjacent data pages. In these cases, the access will be a little slower, as the operation must access partial data from the first page, and then access the remainder of the data from the next page.
- Design Note:
- This class always has the current
DBPage
pinned, and it will unpin the current page when it moves into the next page. This means that when the writer is closed, it may still have a page that is pinned. Therefore, the class implementsAutoCloseable
so that users can callDBFileReader.close()
on a writer to unpin the last page, or they can use this type with the "try-with-resources" Java syntax.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.-
Fields inherited from class edu.caltech.nanodb.storage.DBFileReader
dbFile, dbPage, extendFile, pageSize, position, storageManager, tmpBuf
-
-
Constructor Summary
Constructors Constructor Description DBFileWriter(DBFile dbFile, StorageManager storageManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
writeBoolean(boolean v)
void
writeByte(int v)
void
writeChar(int v)
void
writeDouble(double v)
void
writeFloat(float v)
void
writeInt(int v)
void
writeLong(long v)
void
writeShort(int v)
void
writeVarString255(java.lang.String value)
void
writeVarString65535(java.lang.String value)
-
Methods inherited from class edu.caltech.nanodb.storage.DBFileReader
checkDBPage, close, getDBFile, getPosition, getPositionPageNo, getPositionPageOffset, movePosition, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readInt, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, readVarString255, readVarString65535, setPosition
-
-
-
-
Constructor Detail
-
DBFileWriter
public DBFileWriter(DBFile dbFile, StorageManager storageManager)
-
-
Method Detail
-
write
public void write(byte[] b, int off, int len)
-
write
public void write(byte[] b)
-
writeBoolean
public void writeBoolean(boolean v)
-
writeByte
public void writeByte(int v)
-
writeShort
public void writeShort(int v)
-
writeChar
public void writeChar(int v)
-
writeInt
public void writeInt(int v)
-
writeLong
public void writeLong(long v)
-
writeFloat
public void writeFloat(float v)
-
writeDouble
public void writeDouble(double v)
-
writeVarString255
public void writeVarString255(java.lang.String value)
-
writeVarString65535
public void writeVarString65535(java.lang.String value)
-
-