3 Replies Latest reply on Feb 21, 2003 6:30 AM by Torsten Greiff

    transfer Word Document to session bean

    Torsten Greiff Newbie

      currently we start a reimplementation of our document management system using JBoss and EJB's
      In our old app we used directly JDBC from the client to store Documents into the Database (Oracle).
      Now we want to send the docs to the EJB (stateless session bean) to handle meta data and content persistence.
      What is the best way to send a file over to the server (streams are not serializable)

      thanks in advance
      Torsten

        • 1. Re: transfer Word Document to session bean
          Peter Doornbosch Apprentice

          > 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 Newbie

            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
              Torsten Greiff Newbie

              Thanks Hezekiel,

              the RMI version seems to be the best in our case. Word docs are max 10 meg of size (uncompressed).