android URL stream cannot get whole data

128 views Asked by At

I'm trying to get youtube download link by using this

String data = getURL("http://www.youtube.com/get_video_info?video_id=" + id);

but It always return a part of data. The end of data is like "..." for example,

expire%253D1391242316%2526ms%253Dau%2526fexp%253D900356%25252C902546%25252C936910%252...

I used this code

public String getURL(String s){
    InputStream is = null;  

    try{

        URL r = new URL(s);
        URLConnection rc = r.openConnection();

        DataInputStream dis = new DataInputStream(rc.getInputStream());

        List<Byte> l = new ArrayList<Byte>();

        while(true){
            try{
                l.add(dis.readByte());
            }catch(Exception e){
                break;
            }
        }

        byte[] b = new byte[l.size()];
        for(int i = 0; i < l.size(); i++){
            b[i] = l.get(i);
        }

        return new String(b,"UTF-8");


    }catch(Exception e){

        e.printStackTrace();
        return null;

    }
}

Is there anyone why this can't get whole data? It can be downloaded if I just use chrome by this url

http://www.youtube.com/get_video_info?video_id=itGNQbJwRSk

It downloads whole file. but streaming can't.

1

There are 1 answers

0
Lion.k On BEST ANSWER

I was stupid!. It was just debug window value.

I logged string length and found it was same with total file length.