
com.jsoniter.output.AsciiOutputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsoniter Show documentation
Show all versions of jsoniter Show documentation
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
package com.jsoniter.output;
import java.io.IOException;
import java.io.OutputStream;
class AsciiOutputStream extends OutputStream {
private char[] buf = new char[4096];
private int count = 0;
@Override
public void write(byte[] b, int off, int len) throws IOException {
int i = off;
for (; ; ) {
for (; i < off + len && count < buf.length; i++) {
buf[count++] = (char) b[i];
}
if (count == buf.length) {
char[] newBuf = new char[buf.length * 2];
System.arraycopy(buf, 0, newBuf, 0, buf.length);
buf = newBuf;
} else {
break;
}
}
}
@Override
public void write(int b) throws IOException {
if (count == buf.length) {
char[] newBuf = new char[buf.length * 2];
System.arraycopy(buf, 0, newBuf, 0, buf.length);
buf = newBuf;
}
buf[count++] = (char) b;
}
@Override
public String toString() {
return new String(buf, 0, count);
}
public void reset() {
count = 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy