Dim out As JavaObject
out.InitializeNewInstance($"${Application.PackageName}.main$MyOutputStream"$, Array(Me))
#If Java
import java.io.*;
import anywheresoftware.b4a.B4AClass;
public static class MyOutputStream extends OutputStream {
B4AClass cls;
private boolean closed;
public MyOutputStream (B4AClass cls) {
this.cls = cls;
}
public void write(int b) throws IOException {
if (closed)
throw new IOException("closed");
cls.getBA().raiseEventFromDifferentThread (null, null, 0, "data_available", true, new Object[] {new byte[] {(byte)b}});
}
public void write(byte b[], int off, int len) throws IOException {
if (closed)
throw new IOException("closed");
byte[] bb = new byte[len];
System.arraycopy(b, off, bb, 0, len);
cls.getBA().raiseEventFromDifferentThread (null, null, 0, "data_available", true, new Object[] {bb});
}
public void close() {
closed = true;
}
}
#End if