🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19102

how to download an image file?

#19102
From: Michael Hunter
Date: Sat, 14 Mar 1998 00:00
101 lines
3669 bytes
I need to download a bunch of images off my intranet, and it seems like Java
should do this very easily.  After some digging through my Java manual, I
came up with the following:

     In my button Click even handler:
            try
               {
               statusBar.setText("Opening /junk/ptmap.gif....");
               URL theUrl = new URL("http", "findev.fnb.fcnbd.com",
     "/junk/ptmap.gif");

               try
                  {
                  InputStream rawIn = theUrl.openStream();
                  ImageGet helper = new ImageGet(rawIn);
                  helper.WriteImage("c:\\temp\\jtest.gif", statusBar);
                  rawIn.close();
                  }
               catch (IOException ioe)
                  {
                  System.out.println(ioe);
                  }
               }
            catch (MalformedURLException mue)
                 {
                 System.out.println(mue);
                 }



     Here's the ImageGet class the button handler uses:

     package JAutoGet;
     import java.io.*;
     import borland.jbcl.control.*;

     public class ImageGet extends FilterInputStream {

       public ImageGet(InputStream in) {
              super(in);
       }

       public void WriteImage(String outFile, StatusBar statusBar) throws
     IOException
              {
              FileOutputStream fileOut = new
     FileOutputStream("c:\\temp\\jtest.gif");

              byte[] data = new byte[1048576];
              int curPos = 0;
              int numRead = super.read(data);
              while (-1 < numRead)
                  {
                  fileOut.write(data, curPos, numRead);
                  curPos += numRead;
                  statusBar.setText("Read " + curPos + " total bytes.");
                  numRead = super.read(data);
                  statusBar.setText(statusBar.getText() + "-- last read was
     " + numRead + ".");
                  }

              fileOut.close();
              super.close();
              }
     }


     This all compiles and runs, but I'm running into two problems:

     First, if I use a smaller size for the byte array, such as 1024 or
2048, it does the first loop, but then never completes.  Why is this?

     Second, the above code downloads the correct number of bytes, but the
resultant GIF is not correct -- some portion of it will just be blank. Why
is this?

Any help will be greatly appreciated!
--
Michael Hunter
Humbug_Reality@csi.com

"But what can we do?  We can't do anything to show what we could do if only
we had the power we haven't got."
-- Ladies Clarice and Cora of Gormenghast

'************************************************************
Visit the ActiveCAD Pages at
http://ourworld.compuserve.com/homepages/Humbug_Reality/ActiveCAD/index.htm!
'************************************************************



begin 666 Michael Hunter.vcf
M0D5'24XZ5D-!4D0-"E9%4E-)3TXZ,BXQ#0I..DAU;G1E<CM-:6-H865L#0I&
M3CI-:6-H865L($AU;G1E<@T*14U!24P[4%)%1CM)3E1%4DY%5#I(=6UB=6=?
M4F5A;&ET>4!C<VDN8V]M#0I2158Z,3DY.# S,314,3@P,S0T6@T*14Y$.E9#
%05)$#0H`
`
end
end
Technical Details
Message-ID: <6eeg79$ijq4@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,342544a5c279f600,start
X-Google-Attributes: gidf74b3,public
From: "Michael Hunter" <Humbug_Reality@compuserve.com>
Subject: how to download an image file?
Date: 1998/03/14
Message-ID: <6eeg79$ijq4@forums.borland.com>
X-Deja-AN: 334047752
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language