🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1009

Re: OutOfMemoryError

#1009
From: Alan Shiers
Date: Wed, 03 Jul 2002 17:56
92 lines
4709 bytes
Hi there,

I do use a function that takes a Win32 string, parses it and replaces
single backslash characters with double backslashes. So that's not the
problem.

I've somewhat solved this "Bad file descriptor" temporarily at least.
On the client-side app, you see, I was splitting the procedure in two. I
would create the File object and the FileInputStream object in a
procedure called uploadFile() in one class, and within it, call a worker
thread that finished the job where in its run() method would execute the
while loop.  The worker thread gets a reference to the FileInputStream
object and the
DataOutputStream object.

For some reason, when I split things up this way it generates this "Bad
file descriptor" error.  I still don't know why that is.

Anyway, for the sake of expediency, I've cut out the use of the worker
thread for now and have placed all the code in the uploadFile() method.
Now, I don't get the "Bad file descriptor" error.

However, now I'm faced with a new dilemma. The while loop hangs on the
server-side app!

The client-side app definitely completes and exits the while loop, but
not on the server-side app. 

When I place a System.out.print(n + ", "); statement inside the loop on
the server-side app, I get:

128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,

Then it just hangs there waiting to read in more. When I terminate the
server-side app the line continues to add a four on the end:

128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 4,

The next printlin statement tells me it finally closed the stream. But
only after I shut down the entire app.

I know the client-side app finished and exited the loop at its end with
a -1, so why doesn't the server-side app read in the remaining data and
exit?

When I go into Windows Explorer, after I've shut down the app, I find
that the entire contents of the file is being transferred. The while
loop simply isn't exiting when it should!

Any suggestions?

Alan 

Owen Green wrote:
> 
> "Alan Shiers" <ashiers@hfx.eastlink.ca> wrote in message
> news:3D226288.1C7C905@hfx.eastlink.ca...
> > Hi guys,
> >
> > I've been busy trying to implement the new code and I'm having a problem
> > with the conditional statement of the while loop.
> >
> > myFile = new File("C:\somepath\somefile");
> > if(myFile.exists())System.out.println("file exists");
> > FileIn = new FileInputStream(myFile);
> >
> > byte[] buffer = new byte[128];
> > int n;
> > while((n = FileIn.read(buffer)) >= 0)  << Problem line
> > {
> >     rq.output.write(buffer);
> > }
> >
> > The FileIn object is a FileInputStream object and everytime at runtime I
> > get an IOException stating that it has a "Bad file descriptor".  I don't
> > understand what it is telling me or how to fix it.
> >
> > Earlier, I had created a File object using an absolute file path and
> > file name. Even tested it with the File.exists() method, which returned
> > true, and used the File object as an arguement for the FileInputStream
> > object, like so: FileIn = new FileInputStream(myFile);
> 
> Isn't that exactly what you've shown above?
> 
> > What is causing this "Bad file descriptor" thing?
> 
> I'm not sure :) It could be
> a) That it doesn't understand what you're asking it; are you really writing
> win32 paths as "c:\blah\blah" as oppossed to "c:\\blah\\blah" or
> "c:/blah/blah"?
> b) There are a limited number of FD's available, afaik, do you have lots
> open at any one time? (this includes sockets, btw).
Technical Details
Message-ID: <3d23c9df_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!newsfeed.gamma.ru!Gamma.RU!opentransit.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnews
References: <3D20CC5D.B70473C9@hfx.eastlink.ca> <MPG.178acb912dba8f7998b79d@newsgroups.borland.com> <3D21C1CA.F2D953E2@hfx.eastlink.ca> <3d21bb44_1@dnews> <3D21EC78.228A5CD3@hfx.eastlink.ca> <3d21e07b_2@dnews> <3D226288.1C7C905@hfx.eastlink.ca> <3d22ec28_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,28eab50e784856ac
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-07-03 21:10:41 PST
Date: Wed, 03 Jul 2002 13:56:45 -0400
From: Alan Shiers <ashiers@hfx.eastlink.ca>
Organization: Mustard Seed Software
X-Mailer: Mozilla 4.78 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api
Subject: Re: OutOfMemoryError
References: <3D20CC5D.B70473C9@hfx.eastlink.ca> <MPG.178acb912dba8f7998b79d@newsgroups.borland.com> <3D21C1CA.F2D953E2@hfx.eastlink.ca> <3d21bb44_1@dnews> <3D21EC78.228A5CD3@hfx.eastlink.ca> <3d21e07b_2@dnews> <3D226288.1C7C905@hfx.eastlink.ca> <3d22ec28_1@dnews>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 93
NNTP-Posting-Host: 130.78.143.1
Message-ID: <3d23c9df_2@dnews>
X-Trace: dnews 1025755615 130.78.143.1 (3 Jul 2002 21:06:55 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!newsfeed.gamma.ru!Gamma.RU!opentransit.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnews