• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in wrtitng JAR File

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jar file called test.jar on my server and i am sending that file on my client.the client-server communication is through socket.the file gets created on the client howerver when i unjar the file it extracts only some files and then gives me the error

"java.io.eofexception:unexpected end of ZLIB input steram".
plz tell me how to solve this problem.can somebody plz send me the code for this.

thanx
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code for reading and writing files is very simple and well-covered in the IO chapter in the Java Tutorial. How about you show us some SMALL samples of relevant code and we can see if you've got a bug?
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A little more info please:
How do you unjar the jar file?
Can you unjar the jar file that is on the server without an error?
Have you compared the two files to see if they are different and if so, what is the difference?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What classes are you using to read/write the jar file?
Since jar files can contain binary (non-char) values, you need to read/write bytes not chars.
 
Parth Mankad
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my server code
import java.net.*;
import java.io.*;
import java.util.*;
import java.lang.*;



class Server1
{

Socket soc;
ServerSocket sersoc;
InputStream inStream,iStream;
DataInputStream inDataStream,iDataStream;
ObjectInputStream inObjStream;
OutputStream outStream;
DataOutputStream outDataStream;
ObjectOutputStream outObjStream;
int j;
public void runServer()
{
try
{
sersoc=new ServerSocket(2000);
System.out.println("Server Started");
while(true)
{
soc=sersoc.accept();
System.out.println("Waiting to Accept Data");
getFile();

}
}
catch(Exception e)
{
System.out.println("This is error generated by function runServer()");
e.printStackTrace(System.out);
}

//soc.close();
}
public byte[] ConvertFile(String filelocation) throws Exception
{
try
{
File f = new File(filelocation);
System.out.println("file length"+ f.length());
byte[] b = new byte[(int)(f.length())];
FileInputStream in = new FileInputStream(filelocation);
in.read(b);
return b;
}
catch(Exception e)
{
System.out.println("This is error generated by function ConvertFile()");
e.printStackTrace(System.out);
return null;
}
}

public void getFile()
{
System.out.println("get file called");
try
{

DataOutputStream fout = new DataOutputStream(soc.getOutputStream());
System.out.println(ConvertFile("c:\\test.jar"));
byte[] filebits = ConvertFile("c:\\test.jar");
fout.writeInt(filebits.length);
fout.write(filebits);
fout.flush();

}
catch(Exception e)
{
System.out.println("This is error generated by function getFile()");
e.printStackTrace(System.out);
}
}



public static void main(String[] args)
{
Server1 ms=new Server1();
ms.runServer();
System.out.println("call runserver");
}
}

and this is my client code

import java.net.*;
import java.io.*;
import java.util.*;
class Client1
{
Socket connection;
InputStream inStream;
DataInputStream inDataStream;
ObjectInputStream inObjStream;
OutputStream outStream,oStream;
DataOutputStream outDataStream,oDataStream;
public void ConvertFileBack(byte[] in, String outfile) throws Exception
{
System.out.println("***outfile***"+outfile);
FileOutputStream fos = new FileOutputStream(outfile);
fos.write(in);
fos.close();

}


public void connectServer()
{
try
{
connection = new Socket ( "10.0.0.56",2000 );
DataInputStream dis = new DataInputStream(connection.getInputStream());
byte[] fileenc = new byte[dis.readInt()];
dis.read(fileenc);
ConvertFileBack(fileenc, "C:\\test\\test.jar");
}
catch(ConnectException ce){
System.out.println( "Server is Closed\n" );
System.exit ( 1 );
}
catch ( IOException except) {
System.out.println( "Error connecting to server\n" );
except.printStackTrace ();
System.exit ( 1 );
}
catch ( Exception e) {
System.out.println( "Error " );
System.exit ( 1 );
}


}
public static void main(String[] args)
{
Client1 cs=new Client1();
cs.connectServer();
}
}
plz see if u can find any bug in the above code
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>Have you compared the two files to see if they are different and if so, what is the difference?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a problem:


Have a gander at the Java API Documentation for InputStream and you'll see that read(byte[]) is a pass-through to the method read(byte[] b, int off, int len), and the documentation for that method states:

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

 
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic