int read(byte[]b, int off, int len, InputStream in) {
		int total=0,readlen=0,toReadlen=0;
		boolean eof=false;
		while (len>0&&!eof) {
			// original buffer is empty
			if (start==end) {
				start=0;
				readlen=read4k(buffer, in);
				end+=readlen>0?readlen:0;
				if (readlen==-1) return total;
				else if (readlen<nativeLen) eof=true;
			} else {readlen=end-start;}
			toReadlen=Math.min(len, readlen);
			System.arraycopy(buffer, start, b, off, toReadlen);
			len-=toReadlen; off+=toReadlen; total+=toReadlen; start+=toReadlen;
			if (start==end) {end=0;start=0;}
		}
		return total;
	}