🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: how to download an image file?

#19104
From: Conrad Hoesle-Kienzlen
Date: Sat, 14 Mar 1998 00:00
104 lines
4038 bytes
Michael,
you may want to look at my thread "How to handle images" in
<borland.public.jbuilder.applet-issues> it _may_ have what you need...
...Conrad

Michael Hunter wrote:

> 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!
> '************************************************************
>
>   Michael Hunter <Humbug_Reality@csi.com>
>
>   Michael Hunter
>     <Humbug_Reality@csi.com>
>   Additional Information:
>   Version   2.1
>   Last Name Hunter
>   First NameMichael
>   Revision  19980314T180344Z
Technical Details
Message-ID: <350AF3BB.A6D00A16@csi.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6eeg79$ijq4@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,342544a5c279f600
X-Google-Attributes: gidf74b3,public
From: Conrad Hoesle-Kienzlen <Conrad_Hoesle@csi.com>
Subject: Re: how to download an image file?
Date: 1998/03/14
Message-ID: <350AF3BB.A6D00A16@csi.com>
X-Deja-AN: 334085519
Content-Transfer-Encoding: 7bit
References: <6eeg79$ijq4@forums.borland.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Organization: CHK IT-Consulting
Newsgroups: borland.public.jbuilder.java.language