本文整理匯總了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();
}
}