mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
After review feedback (IDEA-CR-31906)
readINT / writeINT for ByteBuffer were moved to DataInputOutputUtilRt
This commit is contained in:
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -43,6 +44,22 @@ public class DataInputOutputUtilRt {
|
||||
}
|
||||
}
|
||||
|
||||
public static int readINT(@NotNull ByteBuffer byteBuffer) {
|
||||
final int val = byteBuffer.get() & 0xFF;
|
||||
if (val < 192) {
|
||||
return val;
|
||||
}
|
||||
|
||||
int res = val - 192;
|
||||
for (int sh = 6; ; sh += 7) {
|
||||
int next = byteBuffer.get() & 0xFF;
|
||||
res |= (next & 0x7F) << sh;
|
||||
if ((next & 0x80) == 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeINT(@NotNull DataOutput record, int val) throws IOException {
|
||||
if (0 > val || val >= 192) {
|
||||
record.writeByte(192 + (val & 0x3F));
|
||||
@@ -55,6 +72,18 @@ public class DataInputOutputUtilRt {
|
||||
record.writeByte(val);
|
||||
}
|
||||
|
||||
public static void writeINT(@NotNull ByteBuffer byteBuffer, int val) {
|
||||
if (0 > val || val >= 192) {
|
||||
byteBuffer.put( (byte)(192 + (val & 0x3F)));
|
||||
val >>>= 6;
|
||||
while (val >= 128) {
|
||||
byteBuffer.put((byte)((val & 0x7F) | 0x80));
|
||||
val >>>= 7;
|
||||
}
|
||||
}
|
||||
byteBuffer.put((byte)val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the given collection to the output using the given procedure to write each element.
|
||||
* Should be coupled with {@link #readSeq}
|
||||
|
||||
@@ -40,19 +40,7 @@ public class DataInputOutputUtil extends DataInputOutputUtilRt {
|
||||
}
|
||||
|
||||
public static int readINT(@NotNull ByteBuffer byteBuffer) {
|
||||
final int val = byteBuffer.get() & 0xFF;
|
||||
if (val < 192) {
|
||||
return val;
|
||||
}
|
||||
|
||||
int res = val - 192;
|
||||
for (int sh = 6; ; sh += 7) {
|
||||
int next = byteBuffer.get() & 0xFF;
|
||||
res |= (next & 0x7F) << sh;
|
||||
if ((next & 0x80) == 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return DataInputOutputUtilRt.readINT(byteBuffer);
|
||||
}
|
||||
|
||||
public static void writeINT(@NotNull DataOutput record, int val) throws IOException {
|
||||
@@ -60,15 +48,7 @@ public class DataInputOutputUtil extends DataInputOutputUtilRt {
|
||||
}
|
||||
|
||||
public static void writeINT(@NotNull ByteBuffer byteBuffer, int val) {
|
||||
if (0 > val || val >= 192) {
|
||||
byteBuffer.put( (byte)(192 + (val & 0x3F)));
|
||||
val >>>= 6;
|
||||
while (val >= 128) {
|
||||
byteBuffer.put((byte)((val & 0x7F) | 0x80));
|
||||
val >>>= 7;
|
||||
}
|
||||
}
|
||||
byteBuffer.put((byte)val);
|
||||
DataInputOutputUtilRt.writeINT(byteBuffer, val);
|
||||
}
|
||||
|
||||
public static long readLONG(@NotNull DataInput record) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user