本文整理汇总了Java中java.io.InputStreamReader.skip方法的典型用法代码示例。如果您正苦于以下问题:Java InputStreamReader.skip方法的具体用法?Java InputStreamReader.skip怎么用?Java InputStreamReader.skip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.InputStreamReader
的用法示例。
在下文中一共展示了InputStreamReader.skip方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextFromURLStream
import java.io.InputStreamReader; //导入方法依赖的package包/类
private static String getTextFromURLStream(JavadocHelper.TextStream page, int[] offsets, String charset) throws IOException {
if (page == null)
return null;
InputStream fis = null;
InputStreamReader fisreader = null;
try {
fis = page.openStream();
fisreader = charset == null ? new InputStreamReader(fis) : new InputStreamReader(fis, charset);
StringBuilder sb = new StringBuilder();
int offset = 0;
for (int i = 0; i < offsets.length - 1; i+=2) {
int startOffset = offsets[i];
int endOffset = offsets[i + 1];
if (startOffset < 0 || endOffset < 0)
continue;
if (startOffset > endOffset) {
LOG.log(Level.WARNING,
"Was not able to correctly parse javadoc: {0}, startOffset={1}, endOffset={2}.",
new Object[] {page.getLocation(), startOffset, endOffset});
return null;
}
int len = endOffset - startOffset;
char buffer[] = new char[len];
int bytesToSkip = startOffset - offset;
long bytesSkipped = 0;
do {
bytesSkipped = fisreader.skip(bytesToSkip);
bytesToSkip -= bytesSkipped;
} while ((bytesToSkip > 0) && (bytesSkipped > 0));
int bytesAlreadyRead = 0;
do {
int count = fisreader.read(buffer, bytesAlreadyRead, len - bytesAlreadyRead);
if (count < 0){
break;
}
bytesAlreadyRead += count;
} while (bytesAlreadyRead < len);
sb.append(buffer);
offset = endOffset;
}
return sb.toString();
} finally {
if (fisreader != null)
fisreader.close();
}
}