Archived
0

модернизания NetStream (extends Input/Output stream)

cherry-pick: d783317b5d
This commit is contained in:
2018-12-24 11:30:46 +03:00
parent fa5ef8c97c
commit 0feefc83e4
7 changed files with 72 additions and 38 deletions

View File

@@ -1,7 +1,3 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2018-06-10
*/
package mc.core.network.proto_1_12_2;
import java.io.ByteArrayOutputStream;
@@ -25,8 +21,8 @@ public class ByteArrayOutputNetStream extends NetOutputStream_p340 {
}
@Override
public void writeBytes(byte[] buffer) {
baos.write(buffer, 0, buffer.length);
public void writeBytes(byte[] buffer, int offset, int lengtn) {
baos.write(buffer, offset, lengtn);
}
@Override

View File

@@ -1,7 +1,3 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2018-07-25
*/
package mc.core.network.proto_1_12_2;
import lombok.extern.slf4j.Slf4j;
@@ -22,8 +18,6 @@ public abstract class NetOutputStream_p340 extends NetOutputStream {
writeByte(value);
}
@Override
public void writeString(String value) {
if (value.length() > Short.MAX_VALUE) {

View File

@@ -1,9 +1,12 @@
package mc.core.network.proto_1_12_2.packets;
import lombok.extern.slf4j.Slf4j;
import mc.core.network.proto_1_12_2.NetInputStream_p340;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@Slf4j
public class ByteArrayInputNetStream extends NetInputStream_p340 {
private ByteArrayInputStream bais;
@@ -22,7 +25,17 @@ public class ByteArrayInputNetStream extends NetInputStream_p340 {
}
@Override
public void readBytes(byte[] buffer) {
public int readBytes(byte[] buffer, int offset, int length) {
try {
int read = bais.read(buffer, offset, length);
if (read < length) {
throw new IOException("not enough data");
}
return read;
} catch (IOException e) {
log.error("", e);
return -1;
}
}
@Override
@@ -47,7 +60,7 @@ public class ByteArrayInputNetStream extends NetInputStream_p340 {
int ch3 = bais.read();
int ch4 = bais.read();
if ((ch1 | ch2 | ch3 | ch4) < 0) return 0;
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4));
}
@Override