예제 #1
0
  /**
   * Create an array of records from an input stream
   *
   * @param in the InputStream from which the records will be obtained
   * @return an array of Records created from the InputStream
   * @exception RecordFormatException on error processing the InputStream
   */
  public static List<Record> createRecords(InputStream in) throws RecordFormatException {

    List<Record> records = new ArrayList<>(NUM_RECORDS);

    RecordFactoryInputStream recStream = new RecordFactoryInputStream(in, true);

    Record record;
    while ((record = recStream.nextRecord()) != null) {
      records.add(record);
    }

    return records;
  }
  /**
   * Processes a DocumentInputStream into essentially Record events.
   *
   * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String)
   * @param req an Instance of HSSFRequest which has your registered listeners
   * @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object
   * @return numeric user-specified result code.
   */
  private short genericProcessEvents(HSSFRequest req, InputStream in) throws HSSFUserException {
    short userCode = 0;

    // Create a new RecordStream and use that
    RecordFactoryInputStream recordStream = new RecordFactoryInputStream(in, false);

    // Process each record as they come in
    while (true) {
      Record r = recordStream.nextRecord();
      if (r == null) {
        break;
      }
      userCode = req.processRecord(r);
      if (userCode != 0) {
        break;
      }
    }

    // All done, return our last code
    return userCode;
  }