Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf356d8b

Browse files
committed
fix: do not crash DataChannelRereaders when empty file is encountered
1 parent433eaf3 commitf356d8b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

‎src/main/java/ev3dev/utils/DataChannelRereader2.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,18 @@ public String readString() {
9090
// try to do the read
9191
// only one try, as:
9292
// - value >0 indicates success
93-
// - value =0does not tell us much, as there's a possibility of reading anempty attribute
94-
// - value <0 indicatesfailure
93+
// - value =0indicatesempty attribute (???)
94+
// - value <0 indicatesempty attribute
9595
intn =channel.read(buffer,0);
96-
if (n == -1) {
97-
thrownewIOException("Premature end of file " +path);
96+
// minus one reliably occurs on empty file, zero should be similar
97+
if (n <=0) {
98+
return"";
9899
}
99100

100101
// strip trailing newline & return data as a string
101102
// rationale: ev3dev sysfs often appends \n, but this breaks parseFloat/parseInt/...
102103
byte[]bytes =buffer.array();
103-
if (n >0 &&bytes[n -1] =='\n') {
104+
if (bytes[n -1] =='\n') {
104105
returnnewString(bytes,0,n -1,StandardCharsets.UTF_8);
105106
}else {
106107
returnnewString(bytes,0,n,StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp