Downloading a binary file

Following is a short program that attempts to copy a binary file from a remote site to a local file. I tested the program with a text file and it basically works. The problem is that the read() function does not throw an EOFException. So I have the following questions:
1. Is there some method that accomplishes what my copyFile(...) method does?
2. Is there a marker that signals the end of a file? Is this marker the same for text files and for binary files?
3. Is there a better way to copy a binary file?
Your help will be much appreciated.
Miguel
import java.util.*;
import java.io.*;
import java.awt.*;
import java.net.*;
public class filecopy {
public static void main(String[] args) { 
copyFile("http://localhost/super/input.txt","output.txt");
static void copyFile(String mapURL,String mapName) {
BufferedReader bin = null;
DataOutputStream bout = null;
try {
URL url = new URL(mapURL);
URLConnection connection = url.openConnection();
bin = new BufferedReader(new InputStreamReader(connection.getInputStream()));
bout = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(mapName)));
while(true) {
bout.write(bin.read());
} catch (EOFException eofexc) {
try {
bin.close();
bout.flush();
bout.close();
} catch (IOException ioexc) {
System.out.println("copyFile: IOException: " + ioexc);
} catch (IOException ioexc) {
System.out.println("copyFile: IOException: " + ioexc);
}

I would highly recomend getting the file size of the remote file, and collecting data until you have a file as big as the one you want. I would do this for both binary and text files. Not all textfiles have an EOF marker, and there is no universal "EOF" marker for a binary file.
~Kullgen

Similar Messages

  • Using utl_http to download a binary file to the server disk

    Hi,
    I need to download a binary file from the web into the hard disk of the server.
    I am using utl_http to do that. My program works on URLs that have text, but not on binary files. Does anyone have an idea how to do that?
    Thanks
    Rani
    Here is the program I am using:
    DECLARE
    req utl_http.req;
    resp utl_http.resp;
    value VARCHAR2(32767);
    fname utl_file.file_type;
    BEGIN
    utl_http.set_proxy('wwwproxy.myorg.com:8080');
    req := utl_http.begin_request('http://www.somelocation.com/abc.zip');
    resp := utl_http.get_response(req);
    fname := utl_file.fopen('DBTEMP','testfile.zip','w');
    LOOP
    utl_http.read_line(resp, value, TRUE);
    utl_file.put_line(fname,value);
    END LOOP;
    utl_http.end_response(resp);
    utl_file.fclose(fname);
    EXCEPTION
    WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
    utl_file.fclose(fname);
    END;

    Try to use UTL_HTTP.READ_RAW.

  • Firefox crashed when I try to download a binary file

    In this instance it is IE8 which I am trying to download (for business purposes I need Activex controls). When I currently open IE it runs as a process rather than an application. I have tried to download IE8 and google's Chrome but Firefox crashes as soon as I try to save the Binary files.

    Sorry you are having problems. Can you give an example preferably of some small publicly available file and the site you are trying to download it from ?
    As a simple example of a download (ok it is a .png image file not not a .exe file) but can you try to download a copy of your avtar/icon, as used on these forums. In Windows one method is that you right click & should get an option save. <br/> Mine alongside uses the link
    * https://support.mozilla.com/media/uploads/avatars/avatar-257447.png
    Are you able to download such an image, then see it in your download manager, and find it on your computer.
    Once you have got Firefox to save your binary file you can use it. In the case of the .exe file you are trying to download that should be usable as intended with your Windows Operating System, the avatar also should be easily opened and viewed.
    P.S.
    You could try installing the add-on https://addons.mozilla.org/en-US/firefox/addon/opendownload-10902/ if you wished to adapt Firefox to run .exe files instead of just save them.

  • Downloading a binary file using sockets without length known

    Hi all,
    I'm trying to download a binary(.exe) file using socket, where the length of the file is not known. Please take a look at the code I'm using:
          var readBin = socketBin.read();
         <-- Here comes the code that checks for http Content-length header field
         ; If content-length field is available, then I'll use it to download file, else proceed with following code -->
        pBar.reset("Downloading plugin..",null);pBar.hit(readBin.length);       
                while (1)
                    binFil.write(readBin);     //'binFil' is the file, into which downloaded file is written.
                    readBin = socketBin.read();
                    pBar.hit(readBin.length);
                    if( socketBin.eof || readBin.length<=0){
                        break;}          
                binFil.write(readBin);
                binFil.close();
                socketBin.close();
    Problem is: I'm able to download file within 10 seconds when content-length is known. But when content-length is not known, its taking about 1 and half minute to download, also the progress bar gets struck for much of time.
    FYI: socket is opened in binary mode, file is getting downloaded correctly(even though it takes abt a minute). BTW Im using CS5.5 extendscript
    I'm not able to figure out where the bug is.

    Hi, Srikanth:
    Sevaral points.
    #1 When posting code, please use the web interface and the >> icon and choose Syntax Highlighting >> Java. Otherwise your code is just too hard to read and gets misformatted.
    #2 Apropos of #1, your script as written does not work, because this line:
    url=url.replace(/([a-z]*):\/\/([-\._a-z0-9A-Z]*)(:[0-9]*)?\/?(.*)/,"$ 1/$2/$3/$4");
    has an extra space in the $1 and should be this:
    url=url.replace(/([a-z]*):\/\/([-\._a-z0-9A-Z]*)(:[0-9]*)?\/?(.*)/,"$1/$2/$3/$4");
    Please take an extra moment to make sure that when you asking for help, you do so in a way that makes sense. Otherwise it takes too much effort to help you, and that is frustrating.
    #3 If we instrument your script by adding a line to the while() loop:
                while (1)
                    binFil.write(readBin);
                    readBin = socketBin.read();
                    $.writeln(Date()+" Read "+readBin.length+" chars, eof is "+socketBin.eof);
                    if(  readBin.length<=0){         break;}              
    We get output like this:
    Mon Jul 11 2011 12:06:56 GMT-0400 Read 1024 chars, eof is false
    Mon Jul 11 2011 12:06:56 GMT-0400 Read 1024 chars, eof is false
    Mon Jul 11 2011 12:06:56 GMT-0400 Read 1024 chars, eof is false
    Mon Jul 11 2011 12:06:56 GMT-0400 Read 631 chars, eof is false
    Mon Jul 11 2011 12:07:06 GMT-0400 Read 0 chars, eof is false
    Result: undefined
    Therefore, we can reasonably conclude that the last read at the end of the data stream returns a short read when the other side blocks.
    Unfortunately, that's clearly insufficient since you can get short reads all the time.
    I'm not sure why you say the length of the file is not known, HTTP provides it to you in the Content-Length field of the response.
    But the easy answer is to get the server to close it for you. This is easy, enough, with Connection: close. Why were you specifying
    Connection: keep-alive, anyhow?:
                var requestBin =
                "GET /" + parsedURLBin.path + " HTTP/1.1\n" +
                "Host: " + parsedURLBin.address + "\n" +
                "User-Agent: InDesign ExtendScript\n" +
                "Accept: */*\n" +
                //"Connection: keep-alive\n\n";
                "Connection: close\n"+
                "\n";
    This yields a nice tidy:
    Mon Jul 11 2011 12:26:19 GMT-0400 Read 1024 chars, eof is false
    Mon Jul 11 2011 12:26:19 GMT-0400 Read 1024 chars, eof is false
    Mon Jul 11 2011 12:26:19 GMT-0400 Read 1024 chars, eof is false
    Mon Jul 11 2011 12:26:19 GMT-0400 Read 735 chars, eof is true
    Mon Jul 11 2011 12:26:19 GMT-0400 Read 0 chars, eof is true
    I suspect you're also better off using something like socketBin.read(64*1024) for a 64k buffer size, but it doesn't seem to effect the on-the-wire protocol, so perhaps its not so important.
    If you don't want to reply on the server

  • Itunes won't download, binary file won't save to computer.

    Every time I click on the "Download Now" button, I am able to select what folder I want to download the binary file to.
    Once I click save, nothing else happens. I am taken to the "Thank you for downloading itunes" screen, but there is no record of my download anywhere, and the file is simply not saving.

    So weird...I don't know why so many folks have this problem. Why won't the silly file download from Apple? When I click "save file" absolutely nothing happens. A dialogue box should pop up asking me where to save it.
    My solution was to finally download it from one of the many file servers. I used one called "filehorse" and it downloaded right away.
    How can one use their nifty iOS device if they can't install itunes on their computer?!
    I tried the recommended "fixes", one of which included deleting the "temp" folder (which was not so easy to delete, required booting to safe mode command prompt) but made no difference. This was all using Firefox. IE is the only other browser on my computer, which seems to be permanently broken (most sites do not show properly even after using IE's "reset" feature).
    I refuse to install Chrome, I tried it once and it sucked. Hopefully Apple will fix this silly issue so that next time I need to download iTunes, I can do it. Thank you!

  • How do i install powersearch toolbar properly, it only instal a binary file

    i try downloading powersearch toolbar but it only downloads a binary file and then it says it cant download because it has no update information how do i get it the toolbar on my browser?
    == This happened ==
    Every time Firefox opened
    == i installed it the first time

    What you need is a correct path to the directory
    inside of the jar. This can be accomplished by adding
    a line to your main program like this:
    URL
    url=myProgram.class.getResource("images/New16.gif");
    Dummy = new JButton(new ImageIcon(URL));
    where myProgram.class is the name of the class
    file that contain the main method.
    Hope this helps....
    ;o)
    PS: I don't want your dukes...I got them coming out of
    my ears!
    O.K, that works thank you.
    I put something like:
    for all the 'buttons' in the toolbar
    URL url = null;
    Class ThisClass = this.getClass();
    url=ThisClass.getResource("images/New16.gif");
    Dummy = new JButton(new ImageIcon(url));
    Dummy.setActionCommand("New");
    Dummy.addActionListener(this);
    Dummy.setToolTipText("New Database");
    bar.add( Dummy );
    etc for all the rest of the 'buttons'
    After Reading the API docs on URL's etc I'm still not sure as to why it works, but it does....
    I am able now to place the class files in a jar along with the images and it all works fine
    although now I don't quite follow all my code....................
    I assume that
    url=ThisClass.getResource("images/New16.gif");
    returns some sort of 'relative url ' ???
    Thanks for the help though.

  • How do i disable to pop up asking me if i want to save or cancel the binary file i am trying to download?

    everytime i download a show or movie from the internet a pop up asks me:
    "you have chosen to open xxxxxx which is a: Binary File from: httpxxxxx would you like to save this file - SAVE or CANCEL"
    this never used to happen on the older versions of firefox. it is so annoying - is there any way to turn it off?
    i am running mac os 10.5.8 and no, there is no option to click a 'don't ask me again' feature in the pop-up dialog.

    I'd first try downloading an installer from the Apple website using a different web browser:
    http://www.apple.com/quicktime/download/
    If you use Firefox instead of IE for the download (or vice versa), do you get a working installer?

  • Issue in downloading Binary File on Safari 5 (MAC OS)

    Hi,
    We are working on an application, which download binary file when clicks the button, when i am using Safari 6 the below code snippet download file successfully.
    Image:
    Safari 6: on clicking Export file downloaded:
    code:
    String userAgent = request.getHeader("user-agent");
                if (userAgent.toLowerCase().indexOf("mac") >= 0) {
                    response.setContentType("application/octet-stream");
                } else {
                    response.setContentType(TEXT_CSV);
                // These Lines were added to make it work on the secure https
                // connection
                response.setHeader("Pragma", "public");
                response.setHeader("Cache-Control", "max-age=0");
                response.setHeader("Content-Disposition", "filename=contacts.csv");
    but when we use safari 5 on MAC its not downloading the file, it simply display the content on browser it self
    Image:
    and file is not downloaded in this case, can some one tell what should be the contentType(""); should be set to download the file in Safari 5, so that the file can be downloaded in case of Safari 5.
    Thanks in advance:)

    You can set content type to:
    response.setContentType("application/vnd.ms-excel");
    file will download on safari 6

  • GUI_DOWNLOAD binary file download as XLS

    All,
    Using the following code i am generating a binary file and downloading as XLS using GUI_DOWNLOAD. But Everything working fine. But the problem is in the excel I am getting blank row and Blank column in the sheet.
    ie First row and First column in the are coming as blank. I like to avoid this blank column and row
    Any Info ?
    data : lv_heading(50)     type c.
      data:  lv_index(5)        type c.
      data:  lv_string          type string.
      data:  lv_string1         type string.
      data:  lv_xstring         type xstring.
      data:  lt_textab          type truxs_t_text_data.
      data:  ls_textab          like line of lt_textab.
      constants:
      c_tab  type c value cl_abap_char_utilities=>horizontal_tab,
      c_cret type c value cl_abap_char_utilities=>cr_lf.
      " Create Heading
      do.
        write sy-index to lv_index no-zero.
        concatenate 'CTXT_' lv_index into lv_heading.
        condense lv_heading no-gaps.
        concatenate lv_string lv_heading c_tab into lv_string.
        concatenate 'CVAL_' lv_index into lv_heading.
        condense lv_heading no-gaps.
        concatenate lv_string lv_heading c_tab into lv_string.
        if sy-index eq gv_no_col.
          concatenate c_cret c_tab lv_string into lv_string.
          exit.
        endif.
      enddo.
      call function 'SAP_CONVERT_TO_TEX_FORMAT'
        exporting
          i_field_seperator    = c_tab
        tables
          i_tab_sap_data       = <fs_table>
        changing
          i_tab_converted_data = lt_textab
        exceptions
          conversion_failed    = 1
          others               = 2.
    " Records for XLS
      loop at lt_textab into ls_textab.
        wa_out-text = ls_textab.
        lv_string1 = wa_out-text.
        concatenate lv_string c_cret c_tab lv_string1 into lv_string.
      endloop.
      clear: lv_xstring .
      call function 'SCMS_STRING_TO_XSTRING'
        exporting
          text   = lv_string
        importing
          buffer = lv_xstring.
      refresh it_binary_content .
      call function 'SCMS_XSTRING_TO_BINARY'
        exporting
          buffer     = lv_xstring
        tables
          binary_tab = it_binary_content.
    endform.                    " F_generate_output_data.

    Resolved..
    Issue is in the code
      do.
        write sy-index to lv_index no-zero.
        concatenate 'CTXT_' lv_index into lv_heading.
        condense lv_heading no-gaps.
        concatenate lv_string lv_heading c_tab into lv_string.
        concatenate 'CVAL_' lv_index into lv_heading.
        condense lv_heading no-gaps.
        concatenate lv_string lv_heading c_tab into lv_string.
        if sy-index eq gv_no_col.
          " concatenate c_cret c_tab lv_string into lv_string. "<< to be commented
          exit.
        endif.
      enddo.
    and
      loop at lt_textab into ls_textab.
        wa_out-text = ls_textab.
        lv_string1 = wa_out-text.
        concatenate lv_string c_cret lv_string1 into lv_string. " This line tab is removed
      endloop.

  • When trying to download it says binary file download and it starts but doesnt finish

    as i try to download the little box pops up and says binary file save or cancel . So i save and it starts downloading the little line starts across and it gets to the end and disappears and leaves a empty box and nothing else happens

    Which player? Do you mean Flash, or maybe the Windows Media Player plugin?
    * http://www.adobe.com/products/flashplayer/distribution3.html
    * https://support.mozilla.org/en-US/kb/play-windows-media-files-in-firefox
    You have to run the installers with Firefox closed.

  • When I try to download a software up date for another program in Binary File (eg CCleaner or a Microsoft file) in FireFox they all just come up in the download window as 'Cancelled'? When I go to the destination folder the download file icon is there wit

    When I try to download a software up date for another program in Binary File (eg. C Cleaner or a Microsoft file) in Firefox they all just come up in the download window as 'Canceled'? When I go to the destination folder the download file icon is there with 0 Kb's for size...Then when I click 'RETRY' the download it appears to download fully, but when I go into the destination folder the downloaded file is not there? I need to know if there is something in the Firefox options to resolve this problem or much more!!

    If all .exe files are blocked, antivirus software is most likely configured to block them. See if you can download these with your antivirus and/or security software disabled.

  • When I try to download a .exe file extension, Firefox designates it as a binary file which is useless to me.

    using Windows 7 with i3 processor all the latest updates. Firefox is the ONLY browser that gives me this problem. I should not have to turn off my antivirus or go into my config files, write code or anything to have this simple task to work. If I buy a download for a program and get one shot at the download which is an executable file, I should not have it come up as a Binary file and can not use it to load the program that I just ordered.

    Sorry you are having problems. Can you give an example preferably of some small publicly available file and the site you are trying to download it from ?
    As a simple example of a download (ok it is a .png image file not not a .exe file) but can you try to download a copy of your avtar/icon, as used on these forums. In Windows one method is that you right click & should get an option save. <br/> Mine alongside uses the link
    * https://support.mozilla.com/media/uploads/avatars/avatar-257447.png
    Are you able to download such an image, then see it in your download manager, and find it on your computer.
    Once you have got Firefox to save your binary file you can use it. In the case of the .exe file you are trying to download that should be usable as intended with your Windows Operating System, the avatar also should be easily opened and viewed.
    P.S.
    You could try installing the add-on https://addons.mozilla.org/en-US/firefox/addon/opendownload-10902/ if you wished to adapt Firefox to run .exe files instead of just save them.

  • Binary file corrupted when downloading

    Hi. I'm trying to download binary files using a JSP. This is my code:
    <%
         response.setContentType(report.getContent_type());
         response.setHeader ("Content-Disposition", "attachment;filename=\""+report.getNombre()+"\"");
         byte[] file = report.getFile();
         ServletOutputStream sos = response.getOutputStream();                         
         sos.write(file);
         sos.close();
    %>
    It seems to work, but when i'm going to open the downloaded file, it's corrupted, and when I compare it with the original one, all bytes that follow the first '\0' character have been replaced by '\0'. The file size is the same, but not the content.
    I'm using Websphere as application server. Maybe this problem is related with the server, or maybe I'm doing something wrong. Any ideas?
    Thanks.

    I'm surprised that you didn't event get a IllegalStateException. Rather move all your logic to a servlet, jsps usually add whitespace where scriplets were and could corrupt your content.

  • Read binary files that are wraped in the downloaded executable signed jar

    Hello, there:
    I have created a Swing application and created a signed jar file and uploaded it to my site. The signed jar includes class packages, and a folder of binary files which are the datasource for my application.
    jws downloads this signed executable jar, it'll automatically run it, but it has problems reading the binary folders wrapped in itself (the app is supposed to read the folder's structure and use the info to create a JTree object, and read the file's content as well). Is it the file path conversion problem? Do we need to use URL instead? I tried it after reading some threads on this forum but didn't make it.
    As an alternatives, I want JWS to unjar the jar file and expand it to exploded files. I manually unjar it and run the app from command line, it works fine.
    Plus, the app is supposed to manipulate the binary files when it's in process, like saving new content back to the files, zip the files and upload them to the remote sql server. therefore, I think it's easy to have it run when it's expanded.
    So here is the question: JWS by default is running the executable jar, is there a way to tell JWS to unzip the jar and find the main class in the exploded files and run it?
    Thanks a lot for your suggestions,
    Sway

    You can get to any resource in a jar file in your classpath. The code below will return InputStream for resource.bin nested two packages down.
    InputStream in = YourClass.class.getResourceAsStream("/com/mypackage/resouce.bin");  //use '/' instead of '.'You can open a FileOutputStream to write that file.
    OutputStream out = new FileOutputStream("myTempResource.bin");
    IOUtil.streamAndClose(in,out);If the resouce is a nested zip or nested jar then you can use the Java Zip utilities to unwrap the stream.

  • "Binary File" all the time when ever i try to download something.

    I tried downloading some few things lately but FF can't and won't even let me download normally. It says "Binary File" file all the time.
    Like what the heck is going on?
    Someone please help me.
    Thanks!
    == URL of affected sites ==
    http://

    Try "Reset Download Actions": http://kb.mozillazine.org/File_types_and_download_actions

Maybe you are looking for

  • Memoryze barcode for vendor invoices

    Hi all We want to save, after have posted a vendor invoice with barcode, the link between the document and the barcode. Now the link is present in the BDS_BAR_IN table but when the corresponding record in BDS_BAR_EX appear, both the two are deleted.

  • What would happen if I wanted to replace my iPhone 3G 16GB?

    My model of the iPhone (iPhone 3G 16GB Black) has now been discontinued since the 3GS was released. Previously, when my iPhone broke I just took it to the apple store and they replaced it. However, they cannot do that anymore as they will not have my

  • HP Color Laserjet 5550dtn Printer problem

    The printer keeps printing out the same two color copies on 11x17 paper then follows with page after page of code that will not stop.  Any idea of how to stop this would be helpful...

  • Need help in configuring Client to Site IPSec VPN with Hairpinning on Cisco ASA5510 8.2(1)

    Need urgent help in configuring Client to Site IPSec VPN with Hairpinning on Cisco ASA5510 - 8.2(1). The following is the Layout: There are two Leased Lines for Internet access - 1.1.1.1 & 2.2.2.2, the latter being the Standard Default route, the for

  • Pie chart doesn't show the label of the last slice

    Post Author: saschaherrle CA Forum: Charts and Graphs Hi there... I have this problem with displaying the label of the last pie slice of my report. It is working perfectly fine in my testing environment, but it just doesn't want to show in the client