Skip to content

Commit

Permalink
[Minor] #388 Add braces to satisfy coding guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
eitch committed Oct 3, 2024
1 parent 8e0f46b commit 02954a3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pi4j-core/src/main/java/com/pi4j/io/i2c/I2C.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,31 @@ default int writeRead(byte[] writeBuffer, int writeSize, int writeOffset, byte[]
int readOffset) {

// Check bounds for writeBuffer
if (writeOffset < 0)
if (writeOffset < 0) {
throw new IndexOutOfBoundsException("Write offset cannot be negative!");
if (writeOffset + writeSize > writeBuffer.length)
}
if (writeOffset + writeSize > writeBuffer.length) {
throw new IndexOutOfBoundsException(
String.format("Write operation out of bounds. Write buffer length is %d. Yet write offset + size is=%d",
writeBuffer.length, writeOffset + writeSize));
}

// Check bounds for readBuffer
if (readOffset < 0)
if (readOffset < 0) {
throw new IndexOutOfBoundsException("Read offset cannot be negative!");
if (readOffset + readSize > readBuffer.length)
}
if (readOffset + readSize > readBuffer.length) {
throw new IndexOutOfBoundsException(
String.format("Read operation out of bounds. Read buffer length is %d. Yet read offset + size is=%d",
readBuffer.length, readOffset + readSize));
}

return execute(() -> {
int written = write(writeBuffer, writeOffset, writeSize);
if (written != writeSize)
if (written != writeSize) {
throw new IllegalStateException(
"Expected to write " + writeSize + " bytes but only wrote " + written + " bytes");
}
return read(readBuffer, readOffset, readSize);
});
}
Expand Down

0 comments on commit 02954a3

Please sign in to comment.