Skip to content

Commit 360bc1a

Browse files
committed
Fixed BufferUnderflowException.
1 parent ece739e commit 360bc1a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/de/javasocketapi/core/ReadingByteBuffer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.javasocketapi.core;
22

33
import java.nio.ByteBuffer;
4+
import java.util.Arrays;
45
import java.util.UUID;
56

67
public class ReadingByteBuffer {
@@ -52,9 +53,9 @@ public char readChar() {
5253

5354
public String readString() {
5455
//read string
55-
int lenght = this.readInt();
56-
byte[] bytes = new byte[lenght];
57-
for (int i = 0; i < lenght; i++) {
56+
int length = this.readInt();
57+
byte[] bytes = new byte[length];
58+
for (int i = 0; i < length; i++) {
5859
bytes[i] = this.readByte();
5960
}
6061
return new String(bytes);

src/de/javasocketapi/core/WritingByteBuffer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public void writeString(final String value) {
5555
//check value
5656
checkInput(value);
5757
//writing string
58-
int length = value.length();
59-
this.writeInt(length);
60-
for (byte b : value.getBytes()) {
58+
byte[] bytes = value.getBytes();
59+
this.writeInt(bytes.length);
60+
for (byte b : bytes) {
6161
this.writeByte(b);
6262
}
6363
}

0 commit comments

Comments
 (0)