diff --git a/platform/util-rt/src/com/intellij/openapi/util/io/DataInputOutputUtilRt.java b/platform/util-rt/src/com/intellij/openapi/util/io/DataInputOutputUtilRt.java index a12c6af9f462..1d8fd4ca8609 100644 --- a/platform/util-rt/src/com/intellij/openapi/util/io/DataInputOutputUtilRt.java +++ b/platform/util-rt/src/com/intellij/openapi/util/io/DataInputOutputUtilRt.java @@ -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} diff --git a/platform/util/src/com/intellij/util/io/DataInputOutputUtil.java b/platform/util/src/com/intellij/util/io/DataInputOutputUtil.java index 199da87ffa9a..0408d6508475 100644 --- a/platform/util/src/com/intellij/util/io/DataInputOutputUtil.java +++ b/platform/util/src/com/intellij/util/io/DataInputOutputUtil.java @@ -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 {