Skip to content

Commit

Permalink
Use inputStream::readNBytes instead of inputStream::read
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup committed Jan 15, 2024
1 parent d1f6cce commit 6fdefd3
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ private String readString() {
if (stringNbBytes == 0) {
return null;
}
byte[] stringBytes = new byte[stringNbBytes];
int nbBytesRead = dis.read(stringBytes, 0, stringNbBytes);
if (nbBytesRead != stringNbBytes) {
throw new PowsyblException("Cannot read the full string, bytes missing: " + (stringNbBytes - nbBytesRead));
byte[] stringBytes = dis.readNBytes(stringNbBytes);
if (stringBytes.length != stringNbBytes) {
throw new PowsyblException("Cannot read the full string, bytes missing: " + (stringNbBytes - stringBytes.length));
}
return new String(stringBytes, StandardCharsets.UTF_8);
} catch (IOException e) {
Expand Down

0 comments on commit 6fdefd3

Please sign in to comment.