本文整理了Java中org.apache.jena.atlas.lib.Bytes
类的一些代码示例,展示了Bytes
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes
类的具体详情如下:
包路径:org.apache.jena.atlas.lib.Bytes
类名称:Bytes
[英]Byte-oriented operations. Packing and unpacking integers is in network order (Big endian - which is the preferred order in Java). See wikipedia Endianness.
[中]面向字节的操作。整数的打包和解包是按网络顺序进行的(Big-endian-这是Java中的首选顺序)。见wikipedia Endianness。
代码示例来源:origin: apache/jena
/** Get an int from a byte array (network order)
* @param b Byte Array
*/
public static final int getInt(byte[]b)
{ return getInt(b, 0) ; }
代码示例来源:origin: apache/jena
/** Put a long value into an allocated byte array.
* @param v
* @return byte[] array
* @see Long#SIZE
*/
public static byte[] longToBytes(long v) {
byte[] bytes = new byte[Long.BYTES] ;
setLong(v, bytes);
return bytes ;
}
代码示例来源:origin: apache/jena
/** Put a long into a byte array from a given position
* @param value The integer
* @param b byte array
* @param idx starting point
*/
public static final void setLong(long value, byte[] b, int idx) {
int lo = (int)(value & 0xFFFFFFFFL) ;
int hi = (int)(value >>> 32) ;
setInt(hi, b, idx) ;
setInt(lo, b, idx + 4) ;
}
代码示例来源:origin: apache/jena
/** 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 ;
}
代码示例来源:origin: apache/jena
@Test public void packInt4()
{
byte[] b = new byte[8] ;
Bytes.setInt(0x01020304,b,0) ;
Bytes.setInt(0x05060708,b,4) ;
int i1 = Bytes.getInt(b,0) ;
int i2 = Bytes.getInt(b,4) ;
assertEquals(0x01020304, i1) ;
assertEquals(0x05060708, i2) ;
}
代码示例来源:origin: apache/jena
@Override
public String toString()
{
return "hash:"+Bytes.asHex(bytes) ;
}
代码示例来源:origin: apache/jena
/** Get a long from a byte array (network order)
* @param b Byte Array
*/
public static final long getLong(byte[]b)
{ return getLong(b, 0) ; }
代码示例来源:origin: apache/jena
@Test public void packLong8()
{
byte[] b = new byte[16] ;
Bytes.setLong(0xF1F2F3F4F5F6F7F8L,b,0) ;
Bytes.setLong(0xA1A2A3A4A5A6A7A8L,b,8) ;
long i1 = Bytes.getLong(b,0) ;
long i2 = Bytes.getLong(b,8) ;
assertEquals(0xF1F2F3F4F5F6F7F8L,i1) ;
assertEquals(0xA1A2A3A4A5A6A7A8L,i2) ;
}
代码示例来源:origin: apache/jena
public static int compareByKeyValue(Record record1, Record record2)
{
checkCompatible(record1, record2) ;
int x = Bytes.compare(record1.key, record2.key) ;
if ( x == 0 )
{
if ( record1.value != null )
x = Bytes.compare(record1.value, record2.value) ;
}
return x ;
}
代码示例来源:origin: apache/jena
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) ;
}
代码示例来源:origin: apache/jena
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;
}
代码示例来源:origin: apache/jena
private static void compare(int expected, byte[] b1, byte[] b2)
{
int x = Bytes.compare(b1, b2) ;
if ( x > 0 && expected > 0 ) return ;
if ( x == 0 && expected == 0 ) return ;
if ( x < 0 && expected < 0 ) return ;
fail("Does not compare: "+Bytes.asHex(b1)+" :: "+Bytes.asHex(b2)) ;
}
代码示例来源:origin: apache/jena
@Override
public Node call() {
return alloc(Bytes.string2bytes(label));
}
};
代码示例来源:origin: org.apache.jena/jena-dboe-trans-data
/** 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 ;
}
代码示例来源:origin: apache/jena
@Test public void packInt3()
{
byte[] b = new byte[4] ;
Bytes.setInt(0xF1F2F3F4,b) ;
int i = Bytes.getInt(b) ;
assertEquals(0xF1F2F3F4, i) ;
}
代码示例来源:origin: apache/jena
@Override
public String toString()
{
return "hash:"+Bytes.asHex(bytes) ;
}
代码示例来源:origin: org.apache.jena/jena-base
/** Get a long from a byte array (network order)
* @param b Byte Array
*/
public static final long getLong(byte[]b)
{ return getLong(b, 0) ; }
代码示例来源:origin: apache/jena
@Test public void packLong7()
{
byte[] b = new byte[8] ;
Bytes.setLong(0xF1F2F3F4F5F6F7F8L,b) ;
long i = Bytes.getLong(b) ;
assertEquals (0xF1F2F3F4F5F6F7F8L,i) ;
}
代码示例来源:origin: apache/jena
public static int compareByKeyValue(Record record1, Record record2)
{
checkCompatible(record1, record2) ;
int x = Bytes.compare(record1.key, record2.key) ;
if ( x == 0 )
{
if ( record1.value != null )
x = Bytes.compare(record1.value, record2.value) ;
}
return x ;
}
代码示例来源:origin: apache/jena
/** 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 ;
}
内容来源于网络,如有侵权,请联系作者删除!