/** Get data as string - convenience operation */ public String getString() { ByteBuffer bb = getBlob() ; if (bb == null ) return null ; int x = bb.position() ; String s = Bytes.fromByteBuffer(bb) ; bb.position(x) ; return s ; }
/** Get data as string - convenience operation */ public String getString() { ByteBuffer bb = getBlob() ; if (bb == null ) return null ; int x = bb.position() ; String s = Bytes.fromByteBuffer(bb) ; bb.position(x) ; return s ; }
/** Get data as string - convenience operation */ public String getString() { ByteBuffer bb = getBlob() ; if (bb == null ) return null ; int x = bb.position() ; String s = Bytes.fromByteBuffer(bb) ; bb.position(x) ; return s ; }
/** Decode a string into a ByteBuffer */ public static String fromByteBuffer(ByteBuffer bb) { //return BlockUTF8.toString(bb) ; // To be removed (Dec 2011) CharsetDecoder dec = Chars.allocDecoder(); String x = fromByteBuffer(bb, dec) ; Chars.deallocDecoder(dec) ; return x ; }
public String read(long id) { ByteBuffer bb = file.read(id) ; String x = Bytes.fromByteBuffer(bb) ; x = decompress(x) ; return x ; }
/** Decode a string into a ByteBuffer */ public static String fromByteBuffer(ByteBuffer bb) { //return BlockUTF8.toString(bb) ; // To be removed (Dec 2011) CharsetDecoder dec = Chars.allocDecoder(); String x = fromByteBuffer(bb, dec) ; Chars.deallocDecoder(dec) ; return x ; }
/** Decode a string into a ByteBuffer */ public static String fromByteBuffer(ByteBuffer bb) { //return BlockUTF8.toString(bb) ; // To be removed (Dec 2011) CharsetDecoder dec = Chars.allocDecoder(); String x = fromByteBuffer(bb, dec) ; Chars.deallocDecoder(dec) ; return x ; }
public String read(long id) { ByteBuffer bb = file.read(id) ; String x = Bytes.fromByteBuffer(bb) ; x = decompress(x) ; return x ; }
public void dump(DumpHandler handler) { long fileIdx = 0 ; while ( true ) { ByteBuffer bb = file.read(fileIdx) ; String str = Bytes.fromByteBuffer(bb) ; handler.handle(fileIdx, str) ; fileIdx = fileIdx + bb.limit() + 4 ; if ( fileIdx >= file.length() ) break ; } }
public void dump(DumpHandler handler) { long fileIdx = 0 ; while ( true ) { ByteBuffer bb = file.read(fileIdx) ; String str = Bytes.fromByteBuffer(bb) ; handler.handle(fileIdx, str) ; fileIdx = fileIdx + bb.limit() + 4 ; if ( fileIdx >= file.position() ) break ; } }
private static void codec(String str) { ByteBuffer bb = ByteBuffer.allocate(16) ; Bytes.toByteBuffer(str, bb) ; bb.flip() ; String str2 = Bytes.fromByteBuffer(bb) ; assertEquals(str, str2) ; }
private static String readOne(Transactional transactional, TransObjectFile transObjectFile, long posn) { return Txn.calculateRead(transactional, ()->{ ByteBuffer bb = transObjectFile.read(posn) ; return Bytes.fromByteBuffer(bb) ; }) ; }
@Test public void transObjectFile_4() { String str1 = "Test4" ; String str2 = "TheNext" ; long x1 = writeOne(transactional, transObjectFile, str1) ; ByteBuffer bb = str2bb(str2) ; long x2 = baseObjectFile.write(bb) ; baseObjectFile.sync(); long x3 = Txn.calculateRead(transactional, ()->transObjectFile.length()) ; assertEquals(x2, x3); assertNotEquals(x3, baseObjectFile.length()); // Fake recovery. ByteBuffer bbj = ByteBuffer.allocate(2*Long.BYTES) ; bbj.putLong(x3) ; bbj.putLong(0) ; bbj.rewind() ; journal.write(JournalEntryType.REDO, transObjectFile.getComponentId(), bbj) ; journal.writeJournal(JournalEntry.COMMIT) ; // Recovery. //transObjectFile.recover(bb); TransactionalBase transBase = (TransactionalBase)TransactionalFactory.createTransactional(journal, transObjectFile) ; ByteBuffer bb1 = Txn.calculateRead(transBase, ()->transObjectFile.read(x3)) ; String s1 = Bytes.fromByteBuffer(bb1) ; assertEquals(str2, s1); // Woot! transBase.getTxnMgr().shutdown(); } }