Skip to content

Commit 62e9fb3

Browse files
mint-runsmint-runs
authored andcommitted
update WritingByteBuffer.java
1 parent babea07 commit 62e9fb3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/main/java/de/javasocketapi/core/WritingByteBuffer.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,31 @@ public void writeChar(final char value) {
5454

5555
public void writeString(final String value) {
5656
//check value
57-
WritingByteBuffer.checkInput(value);
58-
//writing string
59-
final byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
60-
this.writeInt(bytes.length);
61-
for (final byte b : bytes) {
62-
this.writeByte(b);
57+
if (!WritingByteBuffer.isValueNull(value)){
58+
final byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
59+
this.writeInt(bytes.length);
60+
for (byte b : bytes) {
61+
this.writeByte(b);
62+
}
6363
}
64+
//writing string
6465
}
6566

6667
public void writeUUID(final UUID value) {
6768
//check value
68-
WritingByteBuffer.checkInput(value);
69+
if (!WritingByteBuffer.isValueNull(value)){
70+
this.writeString(value.toString());
71+
}
6972
//writing uuid
70-
this.writeString(value.toString());
7173
}
7274

7375
public byte[] toBytes() {
7476
//convert to byte array
7577
return this.byteBuf.toBytes();
7678
}
7779

78-
private static void checkInput(final Object o) {
79-
//check o to not be null
80-
if (o == null) {
81-
throw new IllegalStateException("The object to be sent may not be null.");
82-
}
80+
private static boolean isValueNull(final Object input) {
81+
//check input to not be null
82+
return input == null;
8383
}
8484
}

0 commit comments

Comments
 (0)