From 6fdefd3895226056087cd03129237fcb3d298b94 Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Mon, 15 Jan 2024 15:03:12 +0100 Subject: [PATCH] Use inputStream::readNBytes instead of inputStream::read Signed-off-by: Florian Dupuy --- .../main/java/com/powsybl/commons/binary/BinReader.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/commons/src/main/java/com/powsybl/commons/binary/BinReader.java b/commons/src/main/java/com/powsybl/commons/binary/BinReader.java index e744e00e3a6..5c037eadbf2 100644 --- a/commons/src/main/java/com/powsybl/commons/binary/BinReader.java +++ b/commons/src/main/java/com/powsybl/commons/binary/BinReader.java @@ -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) {