You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Carmen Pancerella <ca...@ca.sandia.gov> on 2006/03/30 20:33:00 UTC

ArrayIndexOutOfBoundsException when reading custom properties ...

Hello.
 
I'm trying to write code that reads an Excel spreadsheet and reads
a custom property called "Mime type".  I'm using a jar file from
the February 7 nightly build.
 
I'm getting a Java ArrayIndexOutOfBounds exception from the POI
library, and I don't know why.  This code sometimes works fine
but other times I get the exception.  The code is straightforward,
taken from the examples given on Jakarta POI site.

Can anybody help?

Thanks.
Carmen


package apps.mimetypedetermination.excel;

import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Map;

import org.apache.poi.hpsf.*;
import org.apache.poi.poifs.eventfilesystem.*;

/**
 * Determines the Mime type of an Excel spreadsheet 
 */
public class ExcelMimeType
{

   /**
    * Determine Mime type of an Excel spreadsheet to XML using POI 
    * @param data the input data file 
    * @param options 
    */
    public static final String DEFAULT_EXCEL_MIME_TYPE =
        "application/vnd.ms-excel";
    
    private static String mime = "";

    public InputStream GetMimeType(InputStream inputStream, String options) {
     
      mime = "";
      POIFSReader POIFr = new POIFSReader();
      
      try {
         POIFr.registerListener(new MyPOIFSReaderListener());
         POIFr.read(inputStream);
      } catch (IOException ex)
      {
          return null;     
      }
     
      String mimetypeString;
      if (mime == "") 
	 mimetypeString = DEFAULT_EXCEL_MIME_TYPE;
      else 
	 mimetypeString = mime;  
      
      return new ByteArrayInputStream(mimetypeString.getBytes());
   }
   
   static class MyPOIFSReaderListener implements POIFSReaderListener
    {
        public void processPOIFSReaderEvent(POIFSReaderEvent event)
        {
            PropertySet ps = null;
            try
            {
                ps = PropertySetFactory.create(event.getStream());
            }
            catch (NoPropertySetStreamException ex)
            {
               return;
            }
            catch (Exception ex)
            {
                throw new RuntimeException
                    ("Property set stream \"" +
                     event.getPath() + event.getName() + "\": " + ex);
            }

            if (ps.isDocumentSummaryInformation()) 
            {
	       try
	       {
                  DocumentSummaryInformation docsi = new
DocumentSummaryInformation(ps);
	          Map propmap = docsi.getCustomProperties();
	          if (propmap != null)
	          { 
		    String mimeString = (String) propmap.get("Mime type");
		    if (mimeString != null) mime = mimeString;
                  }
               }
	       catch (UnexpectedPropertySetTypeException ex)
	       {
		  throw new RuntimeException
		  ("Unexpected property set type \"" +
                     event.getPath() + event.getName() + "\": " + ex);
	       }
            }
	}
    }
    

}


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/


Re: ArrayIndexOutOfBoundsException when reading custom properties

Posted by Birendar Singh Waldiya <bw...@cisco.com>.
Hi , 

Probably you are gettign this error because the xls you are trying to read is
exceedign the array size you are providing this happens when you just cupy and
deled some cell without removing hten form xls 


just copy same data you are trying to read in a clean new xls dont write
anything else  anywhere except the data you want to read. 
you will know  the cause of problem 

Birenadar S Waldiya


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/


Re: ArrayIndexOutOfBoundsException when reading custom properties ...

Posted by Rainer Klute <kl...@rainer-klute.de>.
Am Donnerstag, den 30.03.2006, 10:33 -0800 schrieb Carmen Pancerella:
> I'm getting a Java ArrayIndexOutOfBounds exception from the POI
> library, and I don't know why.

You didn't provide the exception's stacktrace, and I don't know why. :-)

Best regards
Rainer Klute

                           Rainer Klute IT-Consulting GmbH
  Dipl.-Inform.
  Rainer Klute             E-Mail:  klute@rainer-klute.de
  Körner Grund 24          Telefon: +49 172 2324824
D-44143 Dortmund           Telefax: +49 231 5349423

Public key fingerprint: E4E4386515EE0BED5C162FBB5343461584B5A42E