This commit is contained in:
Him188moe 2019-08-18 18:51:11 +08:00
parent 1eae0932af
commit e9b64c83f4

View File

@ -96,8 +96,28 @@ fun ByteArray.dataInputStream(): DataInputStream = DataInputStream(this.inputStr
/**
* Reset and skip(position)
*/
fun <N : Number> DataInputStream.goto(position: N): DataInputStream {
infix fun <N : Number> DataInputStream.goto(position: N): DataInputStream {
this.reset()
this.skip(position.toLong());
return this
}
fun <N : Number> DataInputStream.readNBytes(position: N, length: Int): ByteArray {
this.goto(position)
return this.readNBytes(length)
}
fun <N : Number> DataInputStream.readInt(position: N): Int {
this.goto(position)
return this.readInt();
}
fun <N : Number> DataInputStream.readByte(position: N): Byte {
this.goto(position)
return this.readByte();
}
fun <N : Number> DataInputStream.readShort(position: N): Short {
this.goto(position)
return this.readShort();
}