OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

XInputStream2InputStream (java)

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
sallad
General User
General User


Joined: 19 Feb 2008
Posts: 8

PostPosted: Thu Feb 28, 2008 2:36 pm    Post subject: XInputStream2InputStream (java) Reply with quote

Below is a small function I used to transfer data from a com.sun.star.io.XInputStream to a java.io.InputStream.

Code:

   static final int BLOCK = 1024;
   public static InputStream XInputStream2InputStream(XInputStream xin)
   {
      InputStream in = null;
      try
      {
         byte[] buf = new byte[0];
         byte[][] b = new byte[1][BLOCK];
         int size = 0;
         int res = 0;
         while ((res = xin.readSomeBytes(b, BLOCK)) == BLOCK)
         {
            // we have just read a full block, allocate another one
            byte[] b2=new byte[size+res];
            System.arraycopy(buf,0,b2,0,size);
            System.arraycopy(b[0],0,b2,size, res);
            buf = b2;
            size += res;
         }
         byte[] b2=new byte[size+res];
         System.arraycopy(buf,0,b2,0,size);
         System.arraycopy(b[0],0,b2,size, res);
         buf = b2;

         in = new ByteArrayInputStream(buf);
      }
      catch (com.sun.star.io.IOException e)
      { System.out.println("DOH!"); }
      return in;
   }


I have some legacy parsers that I'd like to use with OOo's XExtendedFilterDetection and import/export XFilter services. My old parsers, naturally, take the java default InputStream rather than OOo. I'm a novice OOo programmer, but this code seems to work. Is it a good idea to do this? Are there any downsides to this dirty hack?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group