39 lines
908 B
Plaintext
39 lines
908 B
Plaintext
|
package slangc.streams;
|
||
|
|
||
|
import slang.streams.SyncOutput;
|
||
|
|
||
|
public class ArrayOutput implements SyncOutput<byte> {
|
||
|
byte[] buffer;
|
||
|
//int top;
|
||
|
|
||
|
public ArrayOutput() {
|
||
|
buffer = new byte[0];
|
||
|
}
|
||
|
|
||
|
public void innerResize(int newsz) {
|
||
|
byte[] nbuf = new byte[newsz];
|
||
|
for (int i = 0; i < nbuf.length && i < buffer.length; i++) {
|
||
|
nbuf[i] = buffer[i];
|
||
|
}
|
||
|
buffer = nbuf;
|
||
|
}
|
||
|
|
||
|
public int writeBuffer(byte[] b, int from, int max) {
|
||
|
if (from >= b.length) {
|
||
|
return 0;
|
||
|
}
|
||
|
if (from + max > b.length) {
|
||
|
max = b.length - from;
|
||
|
}
|
||
|
int base = buffer.length;
|
||
|
innerResize(buffer.length + max);
|
||
|
for (int i = 0; i < max; i++) {
|
||
|
buffer[base + i] = b[from + i];
|
||
|
}
|
||
|
return max;
|
||
|
}
|
||
|
|
||
|
public void close() {
|
||
|
|
||
|
}
|
||
|
}
|