🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Problem :Receiving an empty file with ObjectOutputStream

#8352
From: Laurent Souriau
Date: Mon, 26 Mar 2001 09:18
97 lines
4495 bytes
            Hi,



I encounter a problem whose solution can be simple (I hope) :

I have a Java Server and a Java client .
I want to send a file (a result of a SQL query) from the server to the
client.
My problem is that I receive an empty File (length 0) on the Client size.
I am using the methods writeObject() and readObject() of ObjectOutputStream
and
of ObjectInputStream. Do I do something wrong ?


I am using the following code on the server side :

****************************************************************************
********************
        try
        {

         ObjectOutputStream out = new ObjectOutputStream(
this.getClientSocket      ().getOutputStream() );
         outputobj = out;


                    try
                    {
                        FileReader tempo = new FileReader("D:\\1stSQL.txt");
                        // Et on l'envoie au client Web
                        System.out.println("Fichier requete trouve");
                        File reponse = new File("D:\\1stSQL.txt");
                        System.out.println("Size of query file:" +
reponse.length());
                        out.writeObject(reponse);
                    }
                    catch (Exception callbackexc)
                    {
                        System.out.println(callbackexc);
                        System.out.println("Error cannot load Callback
File");
                    }
         } catch( Exception e )
         {
             System.out.println("Exception ClientThread : " + e);
         }

   ***********************************************************************
and the following code on the client side :

**************************************************************************
 ServerToClient = new ObjectInputStream(clientSocket.getInputStream());

............................
public void run()
{
      Object data = null;
      File callback,tempo;
      String nomfic;

     try
     {
         while (!stopRequested)
         {
             sleep(10);
             data = ServerToClient.readObject();
             if ((data!=null) && (data instanceof Message))
{receptMessage((Message)data);}

   if ((data!=null) && (data instanceof java.io.File))
                        {
                            callback = (File)data;
                            System.out.println("callback : " +
callback.getName());
                            System.out.println("longueur" +
callback.length());       <------ Here the length is 0 !!!
                            nomfic = "D:\\";
                            tempo = new File(nomfic, callback.getName());
                            boolean z = callback.renameTo(tempo);
                            System.out.println("result rename :" + z);
                        }
  }
 }
 catch(Exception e )
 {
            System.err.println("Execption sur sur la communication avec le
serveur : ");
            e.printStackTrace();
            try
            {
                clientSocket.close();
            }
            catch (IOException r) {}
 }
 return;
}
Technical Details
Message-ID: <99n1an$6n1$1@s1.read.news.oleane.net>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!freenix!teaser.fr!oleane.net!oleane!nnrp.oleane.net!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f631b,c5c03ccb4c917ff2,start
X-Google-Attributes: gidf631b,public
X-Google-Thread: f74b3,c5c03ccb4c917ff2,start
X-Google-Attributes: gidf74b3,public
X-Google-Thread: 10a146,c5c03ccb4c917ff2,start
X-Google-Attributes: gid10a146,public
X-Google-Thread: 10d386,c5c03ccb4c917ff2,start
X-Google-Attributes: gid10d386,public
X-Google-ArrivalTime: 2001-03-26 01:20:11 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!freenix!teaser.fr!oleane.net!oleane!nnrp.oleane.net!not-for-mail
From: "Laurent Souriau" <lsouriau@club-internet.fr>
Newsgroups: borland.public.jbuilder.java.language,comp.compilers.tools.javacc,comp.lang.java.programmer,fr.comp.lang.java
Subject: Problem :Receiving an empty file with ObjectOutputStream
Date: Mon, 26 Mar 2001 11:18:51 +0200
Organization: Guest of France Telecom Oleane's newsreading service
Lines: 99
Message-ID: <99n1an$6n1$1@s1.read.news.oleane.net>
NNTP-Posting-Host: 194.250.203.22
X-Trace: s1.read.news.oleane.net 985598107 6881 194.250.203.22 (26 Mar 2001 09:15:07 GMT)
X-Complaints-To: abuse@oleane.net
NNTP-Posting-Date: Mon, 26 Mar 2001 09:15:07 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400