Java Help file download

MihiCherub

Well-known member
  • Sep 14, 2009
    18,867
    1
    9,637
    113
    Gampaha

    ඕක buffer එකේ අවුලක් නෙවෙයි. උබ stream එක රීඩ් කරන්නෙ බයිට් එකෙන් බයිට් එක නැතුව බ්ලොක් ලෙවල් එකෙන් නෙවෙයි. එක්කො inputstream එක BufferedInputStream එකක wrap කරල රීඩ් කර ගනින් නැත්තම් read(byte[], int, int) එක යූස් කරපං
    කරන හැටි දාන්න බැරිද? :baffled:
     

    DJvodka

    Well-known member
  • Mar 31, 2009
    3,375
    292
    83
    A land like no other
    කරන හැටි දාන්න බැරිද? :baffled:


    PHP:
    try (FileOutputStream fos = new FileOutputStream(file)) {
                                    byte[] buf = new byte[1024*4096];
                                    int bytesRead;
                                    while ((bytesRead = is.read(buf, 0, buf.length)) != -1) {
                                        fos.write(buf, 0, bytesRead);
                                    }
                                }

    or wrap it like this:

    bis = new BufferedInputStream(is);

    and then:

    bis.read();
     

    Radioactive

    Member
    Jul 22, 2014
    10,047
    732
    0
    පට්ට මේක තමා මට ඕන උන උත්තරෙ. 10+ :cool: නියෙමෙට තියෙනව.. හැබැයි වැඩේ තියෙන්නෙ මගේ 8mbps එකෙන් 3mb file එකක් dowload වෙන්න මේ ක්‍රමෙන් 2min කටත් වඩා යනවනෙ..

    BUILD SUCCESSFUL (total time: 1 minute 52 seconds) :baffled:

    නිකන් browser එකෙන් මේක download කලොත් තත් 10ක් වත් යන්නෙ නෑ.
    කොහොමද ඒක හදා ගන්නෙ.

    මම හිතන්නේ ඒකට හේතුව multiple lines නැති වීමයි. අපි file එකක් download කරනකොට, හිතන්න 10MB file එකක් කියලා, ඊට පස්සේ මේක තනි line එකෙන් download කරොත් traffic නිසා slow වෙනවා, මේකට විසදුමක් විදියට අපි server එකට multiple connection හදනවා ඊට පස්සේ file එක download කරනවා කොටස් වශයෙන්, ඊට පස්සේ client end එකේදි ඒවා එකතු කරලා original state එකට ගේනවා.
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,867
    1
    9,637
    113
    Gampaha
    PHP:
    try (FileOutputStream fos = new FileOutputStream(file)) {
                                    byte[] buf = new byte[1024*4096];
                                    int bytesRead;
                                    while ((bytesRead = is.read(buf, 0, buf.length)) != -1) {
                                        fos.write(buf, 0, bytesRead);
                                    }
                                }
    or wrap it like this:

    bis = new BufferedInputStream(is);

    and then:

    bis.read();
    1. is.read(byte[],int,int) 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 40 seconds)

    2.wrap bis.read() 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 54 seconds)

    3.wrap bis.read(byte,int,int) 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 29 seconds)

    still no luck.. මම මේක email attachment එකකින් ගන්නෙ. මුල් ටිකට තත් 3ක් වගේ යන්නෙ. download වෙන ටිකට තමා ඉතුරු ඔක්කොම ටික යන්නෙ..
     

    Radioactive

    Member
    Jul 22, 2014
    10,047
    732
    0
    1. is.read(byte[],int,int) 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 40 seconds)

    2.wrap bis.read() 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 54 seconds)

    3.wrap bis.read(byte,int,int) 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 29 seconds)

    still no luck.. මම මේක email attachment එකකින් ගන්නෙ. මුල් ටිකට තත් 3ක් වගේ යන්නෙ. download වෙන ටිකට තමා ඉතුරු ඔක්කොම ටික යන්නෙ..

    මම නම් දන්න විදියට ඕක ඔහොම කරන්න බෑ. ඕකට threading දාන්න ඕනේ, file එක split වෙන්න download වෙන්න ඕනේ එතකොට speed වෙන්නේ.
     

    DJvodka

    Well-known member
  • Mar 31, 2009
    3,375
    292
    83
    A land like no other
    1. is.read(byte[],int,int) 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 40 seconds)

    2.wrap bis.read() 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 54 seconds)

    3.wrap bis.read(byte,int,int) 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 29 seconds)

    still no luck.. මම මේක email attachment එකකින් ගන්නෙ. මුල් ටිකට තත් 3ක් වගේ යන්නෙ. download වෙන ටිකට තමා ඉතුරු ඔක්කොම ටික යන්නෙ..

    apache commons io lib එක use කරල බලන්න. ඒකත් slow නම් වෙන අවුලක්

    org.apache.commons.io.FileUtils.copyURLToFile(URL, File)
     

    AloneGuy90

    Member
    Sep 3, 2014
    1,791
    243
    0
    මම නම් දන්න විදියට ඕක ඔහොම කරන්න බෑ. ඕකට threading දාන්න ඕනේ, file එක split වෙන්න download වෙන්න ඕනේ එතකොට speed වෙන්නේ.

    he dont care dude! :(
    ok then

    now he will reply :rofl:
     

    DjSpK

    Well-known member
  • Nov 4, 2008
    5,298
    1,005
    113
    I'm Looking for Me !
    1. is.read(byte[],int,int) 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 40 seconds)

    2.wrap bis.read() 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 54 seconds)

    3.wrap bis.read(byte,int,int) 1024*4096
    BUILD SUCCESSFUL (total time: 1 minute 29 seconds)

    still no luck.. මම මේක email attachment එකකින් ගන්නෙ. මුල් ටිකට තත් 3ක් වගේ යන්නෙ. download වෙන ටිකට තමා ඉතුරු ඔක්කොම ටික යන්නෙ..
    vena link ekak try karala baluwada...
    request headers monada yawwe ? c# valadi nam "ServicePointManager.UseNagleAlgorithm = False" propery eka venas karala bytes receive vena count eka vadi karaganna puluwan but java valin NagleAlgorithm venas karanna puluwanda kiyala idea ekak na... multiple connection yanna puluwan nam hodai ehema unoth nam eka vade 1000 venava... headers send venne one ""Accept-Ranges" ":" acceptable-ranges" current reading position & join files.
    no idea friend .. sorry !
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,867
    1
    9,637
    113
    Gampaha
    apache commons io lib එක use කරල බලන්න. ඒකත් slow නම් වෙන අවුලක්

    org.apache.commons.io.FileUtils.copyURLToFile(URL, File)
    url එකක් නෑනෙ...
    PHP:
    Multipart multipart = (Multipart) message.getContent();
    BodyPart bodyPart = multipart.getBodyPart(0);
    InputStream is = bodyPart.getInputStream();
    File file = new File(bodyPart.getFileName());
    
    try (FileOutputStream fos = new FileOutputStream(file)) {
        byte[] buf = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buf, 0, buf.length)) != -1) {
           fos.write(buf, 0, bytesRead);
       }
    }
     

    DJvodka

    Well-known member
  • Mar 31, 2009
    3,375
    292
    83
    A land like no other
    url එකක් නෑනෙ...
    PHP:
    Multipart multipart = (Multipart) message.getContent();
    BodyPart bodyPart = multipart.getBodyPart(0);
    InputStream is = bodyPart.getInputStream();
    File file = new File(bodyPart.getFileName());
    
    try (FileOutputStream fos = new FileOutputStream(file)) {
        byte[] buf = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buf, 0, buf.length)) != -1) {
           fos.write(buf, 0, bytesRead);
       }
    }

    උබට සරලව file එකක් download කර ගන්න නේ ඕනෙ?

    org.apache.commons.io.FileUtils.copyURLToFile(URL, File)

    URL url = new URL("www.pp.com/456.exe");

    file එකට දීපන් output file එක. එච්චරයි
     

    DJvodka

    Well-known member
  • Mar 31, 2009
    3,375
    292
    83
    A land like no other
    Last edited: