當前位置: 首頁>>代碼示例>>Java>>正文


Java CharBuffer.slice方法代碼示例

本文整理匯總了Java中java.nio.CharBuffer.slice方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.slice方法的具體用法?Java CharBuffer.slice怎麽用?Java CharBuffer.slice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.CharBuffer的用法示例。


在下文中一共展示了CharBuffer.slice方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: slice

import java.nio.CharBuffer; //導入方法依賴的package包/類
public static CharBuffer slice(CharBuffer buf) {
    CharBuffer buffer = buf.slice();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    }
    return buffer;
}
 
開發者ID:LWJGLX,項目名稱:debug,代碼行數:9,代碼來源:RT.java

示例2: assertRoundTrips

import java.nio.CharBuffer; //導入方法依賴的package包/類
private static void assertRoundTrips(String str, int index, int size, byte[] bytes, Memory mem,
      WritableMemory writeMem) throws IOException {
  StringBuilder sb = new StringBuilder();

  mem.getCharsFromUtf8(index, size, sb);
  checkStrings(sb.toString(), new String(bytes, index, size, UTF_8));

  CharBuffer cb = CharBuffer.allocate(bytes.length + 1);
  cb.position(1);
  // Make CharBuffer 1-based, to check correct offset handling
  cb = cb.slice();
  mem.getCharsFromUtf8(index, size, cb);
  cb.flip();
  checkStrings(cb.toString(), new String(bytes, index, size, UTF_8));

  assertEquals(writeMem.putCharsToUtf8(0, str), bytes.length);
  assertEquals(0, writeMem.compareTo(0, bytes.length, mem, 0, bytes.length));

  // Test write overflow
  WritableMemory writeMem2 = WritableMemory.allocate(bytes.length - 1);
  try {
    writeMem2.putCharsToUtf8(0, str);
    fail();
  } catch (Utf8CodingException e) {
    // Expected.
  }
}
 
開發者ID:DataSketches,項目名稱:memory,代碼行數:28,代碼來源:Utf8Test.java

示例3: main

import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
 *
 * @param args
 */
public static void main(String args[]) {
    CharBuffer charBuffer = CharBuffer.allocate(BUF_SIZE);
    File file = new File("temp.txt");
    file.deleteOnExit();

    charBuffer.put(str);
    charBuffer.flip();
    checkFileContent(charBuffer, file, str);
    charBuffer.position(10);
    checkFileContent(charBuffer, file, str.substring(10));
    charBuffer.position(charBuffer.limit());
    checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));

    char arr[] = new char[BUF_SIZE];
    charBuffer = CharBuffer.wrap(arr);
    charBuffer.put(str);
    charBuffer.flip();
    checkFileContent(charBuffer, file, str);
    charBuffer.position(10);
    checkFileContent(charBuffer, file, str.substring(10));
    charBuffer.position(charBuffer.limit());
    checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));

    char secArr[] = new char[BUF_SIZE];
    charBuffer = CharBuffer.wrap(secArr);
    charBuffer.put(str);
    charBuffer.position(5);
    charBuffer.limit(str.length() - 7);
    charBuffer = charBuffer.slice();
    checkFileContent(charBuffer, file, str.substring(5, (str.length() - 7)));
    charBuffer.position(10);
    checkFileContent(charBuffer, file, str.substring(15, (str.length() - 7)));
    charBuffer.position(charBuffer.limit());
    checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));

    charBuffer = ByteBuffer.allocate(BUF_SIZE).asCharBuffer();
    charBuffer.put(str);
    charBuffer.flip();
    checkFileContent(charBuffer, file, str);
    charBuffer.position(10);
    checkFileContent(charBuffer, file, str.substring(10));
    charBuffer.position(charBuffer.limit());
    checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));

    charBuffer = ByteBuffer.allocateDirect(1024).asCharBuffer();
    charBuffer.put(str);
    charBuffer.flip();
    checkFileContent(charBuffer, file, str);
    charBuffer.position(10);
    checkFileContent(charBuffer, file, str.substring(10));
    charBuffer.position(charBuffer.limit());
    checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:58,代碼來源:Bug6856817.java


注:本文中的java.nio.CharBuffer.slice方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。