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


Java CharBuffer.compact方法代碼示例

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


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

示例1: fill

import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
 * <p>Refill the buffer read from the socket.</p>
 *
 * Preconditions: <br/>
 *   buffer should have position @ beginning of unprocessed data. <br/>
 *   buffer should have limit @ end of unprocessed data. <br/>
 *
 * Postconditions: <br/>
 *   buffer should have position @ beginning of buffer (pos=0). <br/>
 *   buffer should have limit @ end of unprocessed data. <br/>
 *
 * Note: this method blocks on new data arriving.
 *
 * @param buffer The buffer to fill
 * @param reader The Reader to read the data from
 * @return number of characters read
 * @throws IOException
 */
private int fill(CharBuffer buffer, Reader reader)
    throws IOException {

  // move existing data to the front of the buffer
  buffer.compact();

  // pull in as much data as we can from the socket
  int charsRead = reader.read(buffer);
  counterGroup.addAndGet("characters.received", Long.valueOf(charsRead));

  // flip so the data can be consumed
  buffer.flip();

  return charsRead;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:34,代碼來源:NetcatSource.java


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