public void readLine2(char[] buf){
        int pos = 0;
        boolean eof = false;
        while(!eof){
            int size = bufferSize > 0 ? bufferSize : read4096(buffer);
            if(bufferSize == 0 && size < 4096) eof = true;
            int i;
            for(i = bufferPos; i < bufferPos + size; i++){
                if(buffer[i] == '\0' || buffer[i] == '\n') break;
            }
            if(i == bufferPos + size){
                System.arraycopy(buffer, bufferPos, buf, pos, i - bufferPos);
                pos += i -bufferPos;
                bufferPos = 0;
                bufferSize = 0;
            }else{
                System.arraycopy(buffer, bufferPos, buf, pos, i - bufferPos + 1);
                pos += i - bufferPos + 1;
                bufferPos = (i + 1) % 4096;
                bufferSize = size - (i - bufferPos + 1);
                return;
            }
        }
    }