Package edu.caltech.nanodb.storage
Class DBFileWriter
java.lang.Object
edu.caltech.nanodb.storage.DBFileReader
edu.caltech.nanodb.storage.DBFileWriter
- All Implemented Interfaces:
AutoCloseable
A subclass of DBFileReader, this class provides the basic ability
to read and write a DBFile 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
DBPagepinned, 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 implementsAutoCloseableso 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
FieldsModifier and TypeFieldDescriptionprivate static org.apache.logging.log4j.LoggerA 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwriteBoolean(boolean v) voidwriteByte(int v) voidwriteChar(int v) voidwriteDouble(double v) voidwriteFloat(float v) voidwriteInt(int v) voidwriteLong(long v) voidwriteShort(int v) voidwriteVarString255(String value) voidwriteVarString65535(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
-
Field Details
-
logger
private static org.apache.logging.log4j.Logger loggerA logging object for reporting anything interesting that happens.
-
-
Constructor Details
-
DBFileWriter
-
-
Method Details
-
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
-
writeVarString65535
-