org.apache.jena.atlas.lib.Bytes.toByteBuffer()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中org.apache.jena.atlas.lib.Bytes.toByteBuffer()方法的一些代码示例,展示了Bytes.toByteBuffer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.toByteBuffer()方法的具体详情如下:
包路径:org.apache.jena.atlas.lib.Bytes
类名称:Bytes
方法名:toByteBuffer

Bytes.toByteBuffer介绍

[英]Encode a string into a ByteBuffer : on return position is the end of the encoding
[中]将字符串编码为ByteBuffer:返回时的位置是编码的结尾

代码示例

代码示例来源: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

/** 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 ;
}

代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq

/** 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 ;
}

代码示例来源:origin: org.apache.jena/jena-base

/** 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 ;
}

代码示例来源:origin: org.seaborne.mantis/dboe-trans-data

/**  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);
}

代码示例来源:origin: apache/jena

/**  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);
}

代码示例来源:origin: org.apache.jena/jena-dboe-trans-data

/**  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);
}

代码示例来源:origin: org.seaborne.mantis/dboe-base

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() ;
}

代码示例来源: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) ;
}

相关文章