|
-
April 27th, 2008, 04:29 PM
#1
Byte Array mpeg file
Hi All!
im developing a chat room system, where the client can retrieve a file from the server. To make it simple, i have 3 files which the user can retrieve. A Picture, sound, and movie. They are all sent to the client using a sendMedia function which i have created. The Sound and Images are sent to the client fine, but there is a problem with the movie file(.mpeg) I will post the relevant server and client code, and indacate where the problem is occuring:
Sever Code:
Code:
public void sendMedia(String message)
{
try
{
//Step 1...
ObjectOutputStream outStream =
new ObjectOutputStream(
transfer.getOutputStream());
if (message.equals("getSound"))
{
output.println("mess:**** SOUND REQUESTED ****");
sendFile("cuckoo.au", outStream);
output.println("mess:**** SOUND SENT ****");
}
else if (message.equals("getImage"))
{
output.println("mess:**** IMAGE REQUESTED ****");
sendFile("car.jpg", outStream);
output.println("mess:**** IMAGE SENT ****");
}
else if (message.equals("getMovie"))
{
output.println("mess:**** MOVIE REQUESTED ****");
sendFile("moon_walk.mpeg", outStream);
output.println("mess:**** MOVIE SENT ****");
}
//To play safe, flush the output buffer...
outStream.flush();
}
catch(IOException ioEx)
{
ioEx.printStackTrace();
}
}
private static void sendFile(String fileName,
ObjectOutputStream outStream) throws IOException
{
System.out.println("start send file");
FileInputStream fileIn = new FileInputStream(fileName);
long fileLen = (new File(fileName)).length();
int intFileLen = (int)fileLen;
byte[] byteArray = new byte[intFileLen];
fileIn.read(byteArray);
fileIn.close();
outStream.writeObject(byteArray); <-------PROGRAM CRASHES HERE
outStream.flush();
}
And now the client code:
Code:
private void getFile(ObjectInputStream inStream, String fileType)
{
try
{
byte[] byteArray = (byte[])inStream.readObject();
FileOutputStream mediaStream = null;
if (fileType.equals("SOUND")){
mediaStream =
new FileOutputStream
("TransferedSound.au");
mediaStream.write(byteArray);
playMedia frame = new playMedia(fileType);
frame.setTitle( "Transfered Sound" );
frame.setSize(100, 100);
frame.setVisible(true);
}
else if (fileType.equals("IMAGE")){
mediaStream =
new FileOutputStream
("TransferedImage.jpg");
mediaStream.write(byteArray);
DisplayImage pictureFrame = new DisplayImage();
pictureFrame.setTitle( "Trasfered Image" );
pictureFrame.setSize(420,310);
pictureFrame.setVisible(true);
}
else if(fileType.equals("MOVIE")){
mediaStream =
new FileOutputStream
("\TransferedMovie.mpeg");
System.out.println("1");
mediaStream.write(byteArray);
System.out.println("2");
playMedia frame = new playMedia(fileType);
System.out.println("3");
frame.setTitle( "Trasfered Movie" );
frame.setSize(420,310);
frame.setVisible(true);
}
}
Any Help, or suggestions would be a great help
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|