-
1. Re: transfer Word Document to session bean
petertje Feb 14, 2003 9:17 AM (in response to greiff)> What is the best way to send a file over to the
> server (streams are not serializable)
Client to server you mean? Http. -
2. Re: transfer Word Document to session bean
hezekiel Feb 16, 2003 2:11 PM (in response to greiff)While I agree that HTTP or FTP is the right way to do this one could also read and compress the file to a byte array and send it as a RMI parameter. File compression and uncompression 'algorithms' provided as an example:
public byte[] compress(String fileName) throws FileNotFoundException, IOException
{
int bufferLen = 1024; //one can experiment with the buffer size
ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferLen);
DeflaterOutputStream dos = new DeflaterOutputStream(baos);
FileInputStream fis = new FileInputStream(fileName);
int i = 0;
byte[] inBuffer = new byte[bufferLen];
while (-1 != (i = fis.read(inBuffer, 0, bufferLen))) //read from the file to inBuffer until we hit the eof
{
dos.write(inBuffer, 0, i);
}
dos.close();
return baos.toByteArray();
}
public byte[] uncompress(byte[] compressedArray) throws IOException
{
int bufferLen = 1024; //one can experiment with the buffer size
ByteArrayInputStream bais = new ByteArrayInputStream(compressedArray);
InflaterInputStream dis = new InflaterInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferLen);
byte[] buffer = new byte[bufferLen];
int i = 0;
while (-1 != (i = dis.read(buffer, 0, bufferLen)))
{
baos.write(buffer, 0, i);
}
baos.close();
return baos.toByteArray();
}
This method works very well for relatively small documents (compressed sizes are within few megabytes) and word docs tend to compress very well. -
3. Re: transfer Word Document to session bean
greiff Feb 21, 2003 6:30 AM (in response to greiff)Thanks Hezekiel,
the RMI version seems to be the best in our case. Word docs are max 10 meg of size (uncompressed).