public int read(byte[] b,int off,int len) throws IOException {
        avail = buf.length - pos;
        if (avail > 0) {
            if (len < avail)
                avail = len;
            
            if(avail==3){
                temp = pos;
                temp2 = off;
                b[temp2++] = buf[temp++];
                b[temp2++] = buf[temp++];
                b[temp2] = buf[temp];
            } else{ //equals 1
                b[off]= buf[pos];
            }
            
            pos += avail;
            off += avail;
            len -= avail;
        }
        
        if (len > 0) {
            if ((len = in.read(b,off,len)) == -1)
                return avail == 0 ? -1 : avail;
            
            return avail + len;
        }
        
        return avail;
    }