当前位置: 首页>>代码示例>>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;未经允许,请勿转载。