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


Java Reader.skip方法代碼示例

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


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

示例1: skipFully

import java.io.Reader; //導入方法依賴的package包/類
/**
 * Discards {@code n} characters of data from the reader. This method will block until the full
 * amount has been skipped. Does not close the reader.
 *
 * @param reader the reader to read from
 * @param n the number of characters to skip
 * @throws EOFException if this stream reaches the end before skipping all the characters
 * @throws IOException if an I/O error occurs
 */
public static void skipFully(Reader reader, long n) throws IOException {
  checkNotNull(reader);
  while (n > 0) {
    long amt = reader.skip(n);
    if (amt == 0) {
      throw new EOFException();
    }
    n -= amt;
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:20,代碼來源:CharStreams.java

示例2: countBySkipping

import java.io.Reader; //導入方法依賴的package包/類
private long countBySkipping(Reader reader) throws IOException {
  long count = 0;
  long read;
  while ((read = reader.skip(Long.MAX_VALUE)) != 0) {
    count += read;
  }
  return count;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:9,代碼來源:CharSource.java

示例3: extractString

import java.io.Reader; //導入方法依賴的package包/類
/**
 * Extracts a portion of the contents of the given reader/stream as a string.
 *
 * @param characterStream The reader for the content
 * @param start The start position/offset (0-based, per general stream/reader contracts).
 * @param length The amount to extract
 *
 * @return The content as string
 */
private static String extractString(Reader characterStream, long start, int length) {
	if ( length == 0 ) {
		return "";
	}
	StringBuilder stringBuilder = new StringBuilder( length );
	try {
		long skipped = characterStream.skip( start );
		if ( skipped != start ) {
			throw new HibernateException( "Unable to skip needed bytes" );
		}
		final int bufferSize = getSuggestedBufferSize( length );
		char[] buffer = new char[bufferSize];
		int charsRead = 0;
		while ( true ) {
			int amountRead = characterStream.read( buffer, 0, bufferSize );
			if ( amountRead == -1 ) {
				break;
			}
			stringBuilder.append( buffer, 0, amountRead );
			if ( amountRead < bufferSize ) {
				// we have read up to the end of stream
				break;
			}
			charsRead += amountRead;
			if ( charsRead >= length ) {
				break;
			}
		}
	}
	catch ( IOException ioe ) {
		throw new HibernateException( "IOException occurred reading a binary value", ioe );
	}
	return stringBuilder.toString();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:44,代碼來源:DataHelper.java


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