本文整理汇总了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;
}
}
示例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;
}
示例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();
}