public long write(String str) { str = compress(str) ; ByteBuffer bb = ByteBuffer.allocate(4*str.length()); int len = Bytes.toByteBuffer(str, bb) ; bb.flip() ; long x = file.write(bb) ; return x; }
/** Encode a string into a ByteBuffer : on return position is the end of the encoding */ public static int toByteBuffer(CharSequence s, ByteBuffer bb) { //BlockUTF8.fromChars(s, bb) ; CharsetEncoder enc = Chars.allocEncoder(); int x = toByteBuffer(s, bb, enc) ; Chars.deallocEncoder(enc) ; return x ; }
/** Encode a string into a ByteBuffer : on return position is the end of the encoding */ public static int toByteBuffer(CharSequence s, ByteBuffer bb) { //BlockUTF8.fromChars(s, bb) ; // To be removed (Dec 2011) CharsetEncoder enc = Chars.allocEncoder(); int x = toByteBuffer(s, bb, enc) ; Chars.deallocEncoder(enc) ; return x ; }
/** Encode a string into a ByteBuffer : on return position is the end of the encoding */ public static int toByteBuffer(CharSequence s, ByteBuffer bb) { //BlockUTF8.fromChars(s, bb) ; CharsetEncoder enc = Chars.allocEncoder(); int x = toByteBuffer(s, bb, enc) ; Chars.deallocEncoder(enc) ; return x ; }
/** Set data from string - convenience operation */ public void setString(String dataStr) { checkWriteTxn(); if ( dataStr == null ) { setBlob(null); return ; } // Attempt to reuse the write-transaction byte buffer // We can't reuse if it's the blobRef (shared by other transactions) // but if it's a new to this write transaction buffer we can reuse. int maxNeeded = dataStr.length()*4 ; ByteBuffer bb = getDataState().getByteBuffer() ; if ( bb == blobRef.get() ) bb = ByteBuffer.allocate(maxNeeded) ; else if ( bb.capacity() >= maxNeeded ) bb.clear() ; else bb = ByteBuffer.allocate(maxNeeded) ; Bytes.toByteBuffer(dataStr, bb) ; bb.flip() ; setBlob(bb); }
/** Set data from string - convenience operation */ public void setString(String dataStr) { checkWriteTxn(); if ( dataStr == null ) { setBlob(null); return ; } // Attempt to reuse the write-transaction byte buffer // We can't reuse if it's the blobRef (shared by other transactions) // but if it's a new to this write transaction buffer we can reuse. int maxNeeded = dataStr.length()*4 ; ByteBuffer bb = getDataState().getByteBuffer() ; if ( bb == blobRef.get() ) bb = ByteBuffer.allocate(maxNeeded) ; else if ( bb.capacity() >= maxNeeded ) bb.clear() ; else bb = ByteBuffer.allocate(maxNeeded) ; Bytes.toByteBuffer(dataStr, bb) ; bb.flip() ; setBlob(bb); }
/** Set data from string - convenience operation */ public void setString(String dataStr) { checkWriteTxn(); if ( dataStr == null ) { setBlob(null); return ; } // Attempt to reuse the write-transaction byte buffer // We can't reuse if it's the blobRef (shared by other transactions) // but if it's a new to this write transaction buffer we can reuse. int maxNeeded = dataStr.length()*4 ; ByteBuffer bb = getDataState().getByteBuffer() ; if ( bb == blobRef.get() ) bb = ByteBuffer.allocate(maxNeeded) ; else if ( bb.capacity() >= maxNeeded ) bb.clear() ; else bb = ByteBuffer.allocate(maxNeeded) ; Bytes.toByteBuffer(dataStr, bb) ; bb.flip() ; setBlob(bb); }
public long write(String str) { str = compress(str) ; Block block = file.allocWrite(4*str.length()) ; int len = Bytes.toByteBuffer(str, block.getByteBuffer()) ; block.getByteBuffer().flip() ; file.completeWrite(block) ; return block.getId() ; }
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) ; }