本文整理了Java中okio.BufferedSource.readDecimalLong()
方法的一些代码示例,展示了BufferedSource.readDecimalLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedSource.readDecimalLong()
方法的具体详情如下:
包路径:okio.BufferedSource
类名称:BufferedSource
方法名:readDecimalLong
[英]Reads a long from this source in signed decimal form (i.e., as a string in base 10 with optional leading '-'). This will iterate until a non-digit character is found.
[中]以有符号十进制形式从该源中读取长字符串(即,以10为基数,带可选前导“-”的字符串)。这将迭代,直到找到非数字字符。
代码示例来源:origin: square/okhttp
static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: apollographql/apollo-android
private static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: square/okio
@Test public void longDecimalStringTooLongThrows() throws IOException {
try {
sink.writeUtf8("12345678901234567890"); // Too many digits.
sink.emit();
source.readDecimalLong();
fail();
} catch (NumberFormatException e) {
assertEquals("Number too large: 12345678901234567890", e.getMessage());
}
}
代码示例来源:origin: square/okio
@Test public void longDecimalStringTooShortThrows() throws IOException {
try {
sink.writeUtf8(" ");
sink.emit();
source.readDecimalLong();
fail();
} catch (NumberFormatException e) {
assertEquals("Expected leading [0-9] or '-' character but was 0x20", e.getMessage());
}
}
代码示例来源:origin: square/okio
@Test public void longDecimalStringTooHighThrows() throws IOException {
try {
sink.writeUtf8("9223372036854775808"); // Right size but cannot fit.
sink.emit();
source.readDecimalLong();
fail();
} catch (NumberFormatException e) {
assertEquals("Number too large: 9223372036854775808", e.getMessage());
}
}
代码示例来源:origin: square/okio
@Test public void longDecimalStringTooLowThrows() throws IOException {
try {
sink.writeUtf8("-9223372036854775809"); // Right size but cannot fit.
sink.emit();
source.readDecimalLong();
fail();
} catch (NumberFormatException e) {
assertEquals("Number too large: -9223372036854775809", e.getMessage());
}
}
代码示例来源:origin: square/okio
@Test public void longDecimalEmptyThrows() throws IOException {
try {
sink.writeUtf8("");
sink.emit();
source.readDecimalLong();
fail();
} catch (EOFException expected) {
}
}
代码示例来源:origin: square/okio
private void assertLongDecimalString(String s, long expected) throws IOException {
sink.writeUtf8(s);
sink.writeUtf8("zzz");
sink.emit();
long actual = source.readDecimalLong();
assertEquals(s + " --> " + expected, expected, actual);
assertEquals("zzz", source.readUtf8());
}
代码示例来源:origin: square/okio
@Test public void longDecimalStringAcrossSegment() throws IOException {
sink.writeUtf8(repeat('a', SEGMENT_SIZE - 8)).writeUtf8("1234567890123456");
sink.writeUtf8("zzz");
sink.emit();
source.skip(SEGMENT_SIZE - 8);
assertEquals(1234567890123456L, source.readDecimalLong());
assertEquals("zzz", source.readUtf8());
}
代码示例来源:origin: com.github.ljun20160606/okhttp
static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: huxq17/tractor
private static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: huxq17/SwipeCardsView
private static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: duzechao/OKHttpUtils
private static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: apache/servicemix-bundles
static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
内容来源于网络,如有侵权,请联系作者删除!