@Override public void close() { channel.close() ; }
public void truncate(long size) { channel.truncate(size) ; }
@Test public void storage_05() { ByteBuffer b1 = data(blkSize) ; ByteBuffer b1a = ByteBuffer.allocate(blkSize) ; ByteBuffer b2 = data(blkSize/2) ; ByteBuffer b2a = ByteBuffer.allocate(blkSize/2) ; store.write(b1) ; store.write(b2) ; store.position(0) ; store.read(b1a) ; assertTrue(same(b1, b1a)) ; store.read(b2a) ; assertTrue(same(b2, b2a)) ; }
throw new IllegalArgumentException("ObjectFile.read[" + file.getLabel() + "]: Bad read: " + loc); throw new IllegalArgumentException("ObjectFileStorage.read[" + file.getLabel() + "]: Bad read: location=" + loc + " >= max=" + (filesize + writeBuffer.position())); int offset = (int)(loc - filesize); int x = file.read(lengthBuffer, loc); if ( x != 4 ) { String msg = "ObjectFileStorage.read[" + file.getLabel() + "](" + loc + ")[filesize=" + filesize + "]" + "[file.size()=" + file.size() + "]: Failed to read the length : got " + x + " bytes"; lengthBuffer.clear(); int x1 = file.read(lengthBuffer, loc); throw new FileException(msg); String msg = "ObjectFileStorage.read[" + file.getLabel() + "](" + loc + ")[filesize=" + filesize + "][file.size()=" + file.size() + "]: Impossibly large object : " + len + " bytes > filesize-(loc+SizeOfInt)=" + (filesize - (loc + SizeOfInt)); throw new FileException(msg); x = file.read(bb, loc + SizeOfInt); bb.flip(); if ( x != len )
private long rawWrite(ByteBuffer bb) { if ( logging ) log("RW %s", bb); int len = bb.limit() - bb.position(); writeLengthBuffer.rewind(); writeLengthBuffer.putInt(len); writeLengthBuffer.flip(); long location = file.position(); file.write(writeLengthBuffer); int x = file.write(bb); if ( x != len ) throw new FileException(); filesize = filesize + x + SizeOfInt; if ( logging ) { log("Posn: %d", file.position()); log("RW ->0x%X", location); } return location; }
public IteratorEntries(long startPosition) { iterPosn = startPosition ; endPoint = channel.size() ; }
public long position() { return channel.position() ; }
private void flushOutputBuffer() { if ( logging ) log("Flush"); if ( writeBuffer == null ) return; if ( writeBuffer.position() == 0 ) return; long location = filesize; writeBuffer.flip(); int x = file.write(writeBuffer); filesize += x; writeBuffer.clear(); }
private JournalEntry _read() int lenRead = channel.read(header) ; if ( lenRead == -1 ) lenRead = channel.read(bb) ; if ( lenRead != len) throw new TDBTransactionException("Failed to read the journal entry: wanted "+len+" bytes, got "+lenRead) ; lenRead = channel.read(crcTrailer) ; if ( lenRead != SizeofCRC ) throw new TDBTransactionException("Failed to read block checksum (got "+lenRead+" bytes, not "+SizeofCRC+").") ;
@Override public void sync() { channel.sync() ; }
@Override public String getLabel() { return file.getLabel(); }
public String getFilename() { return channel.getFilename() ; } }