Skip to content

Commit 23878d3

Browse files
author
mInTRuns
committed
update InputStreamThread.java
with Atomic Reference Bytes
1 parent 9ad06c2 commit 23878d3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/de/javasocketapi/core/InputStreamThread.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Timer;
88
import java.util.TimerTask;
99
import java.util.UUID;
10+
import java.util.concurrent.atomic.AtomicReference;
1011

1112
class InputStreamThread {
1213

@@ -31,7 +32,7 @@ public void run() {
3132
} catch (final IOException e) {
3233
e.printStackTrace();
3334
}
34-
final byte[][] bytes = new byte[1][1];
35+
final AtomicReference<byte[]> bytes = new AtomicReference<>(null);
3536
//start reading byte arrays
3637
final InputStream finalInputStream = inputStream;
3738
this.timer.scheduleAtFixedRate(new TimerTask() {
@@ -48,12 +49,13 @@ public void run() {
4849
if (finalInputStream.available() > 0) {
4950
final int b = finalInputStream.read();
5051
if (b != -1) {
51-
bytes[0] = new byte[b];
52+
bytes.set(new byte[b]);
5253
//receive bytes
53-
finalInputStream.read(bytes[0], 0, b);
54-
final ReadingByteBuffer readingByteBuffer = new ReadingByteBuffer(bytes[0]);
54+
finalInputStream.read(bytes.get(), 0, b);
55+
final ReadingByteBuffer readingByteBuffer = new ReadingByteBuffer(bytes.get());
5556
//read packetId
5657
final int packetId = readingByteBuffer.readInt();
58+
5759
//check if packet is UpdateUUIDPacket
5860
if (packetId == -2) {
5961
//read connectionUUID

src/de/javasocketapi/core/ReadingByteBuffer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.javasocketapi.core;
22

3+
34
import java.nio.ByteBuffer;
45
import java.nio.charset.StandardCharsets;
56
import java.util.UUID;

0 commit comments

Comments
 (0)