Convert SkipOutputStream to Kotlin

This commit also changes the skipBytes logic slightly to avoid the need
to modify the off/len arguments, which is not possible in Kotlin.
pull/48/head
Graham 4 years ago
parent caaa53095d
commit 429867e3af
  1. 37
      util/src/main/java/dev/openrs2/util/io/SkipOutputStream.java
  2. 23
      util/src/main/java/dev/openrs2/util/io/SkipOutputStream.kt

@ -1,37 +0,0 @@
package dev.openrs2.util.io;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public final class SkipOutputStream extends FilterOutputStream {
private long skipBytes;
public SkipOutputStream(OutputStream out, long skipBytes) {
super(out);
this.skipBytes = skipBytes;
}
@Override
public void write(int b) throws IOException {
if (skipBytes == 0) {
super.write(b);
} else {
skipBytes--;
}
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (len >= skipBytes) {
off += skipBytes;
len -= skipBytes;
skipBytes = 0;
} else {
skipBytes -= len;
return;
}
super.write(b, off, len);
}
}

@ -0,0 +1,23 @@
package dev.openrs2.util.io
import java.io.FilterOutputStream
import java.io.OutputStream
class SkipOutputStream(out: OutputStream, private var skipBytes: Long) : FilterOutputStream(out) {
override fun write(b: Int) {
if (skipBytes == 0L) {
super.write(b)
} else {
skipBytes--
}
}
override fun write(b: ByteArray, off: Int, len: Int) {
if (len >= skipBytes) {
super.write(b, off + skipBytes.toInt(), len - skipBytes.toInt())
skipBytes = 0
} else {
skipBytes -= len
}
}
}
Loading…
Cancel
Save