Reads from the original Excel document the string table and puts it into a
compressed and encrypted file.

@param is
@throws java.io.IOException
966374
@Override
	public void readFrom(InputStream is) throws IOException {
		this.currentItem = 0;
		// read from source and write into tempfile
		// open temp file depending on options compressed/encrypted
		OutputStream tempOS = null;
		if ((this.ca != null) || (this.compressTempFile)) {
			tempOS = new FileOutputStream(this.tempFile);
			if (this.ca != null) { // encrypt file if configured
				tempOS = new CipherOutputStream(tempOS, this.ciEncrypt);
			}
			if (this.compressTempFile) { // compress file if configured
				tempOS = new GZIPOutputStream(tempOS, EncryptedCachedDiskStringsTable.compressBufferSize);
			}
		} else { // not encrypted and not compressed: configure a random access file for
					// writing/reading = highest performance
			this.tempRAF = new RandomAccessFile(this.tempFile, "rw");
		}
		// read from source
		// use Stax event reader
		XMLEventReader xer = null;
		try {
			xer = StaxHelper.newXMLInputFactory().createXMLEventReader(this.originalIS);
			while (xer.hasNext()) {
				XMLEvent xe = xer.nextEvent();
				// check if it is a string item (entry in string table)
				if (xe.isStartElement() && xe.asStartElement().getName().getLocalPart().equalsIgnoreCase("si")) {
					String siText = this.parseSIText(xer);
					// add string to temp file
					this.addString(siText, tempOS);
					this.count++;
				}
			}
			// close tempfile
			// make tempFile available as a reader
		} catch (XMLStreamException e) {
			LOG.error("Cannot read original SharedStringTable from document. Exception " + e);
			throw new IOException(e);
		} catch (FormatNotUnderstoodException e) {
			LOG.error("Cannot read properly SharedStringTable from document. Exception " + e);
			throw new IOException(e);
		} finally {
			// close temporary Stream (tempfile should be deleted using the close method of
			// this class and not here)
			if (tempOS != null) {
				tempOS.close();
			}
		}
		// open the input stream towards the temp file
		this.accessTempFile(0L);

	}
26372
public static void compress(InputStream is, OutputStream os) throws Exception {
		GZIPOutputStream gos = new GZIPOutputStream(os);
		int count;
		byte data[] = new byte[BUFFER];
		while ((count = is.read(data, 0, BUFFER)) != -1) {
			gos.write(data, 0, count);
		}
		gos.finish();
		gos.flush();
		gos.close();
	}
697389
public void initializeStringTable() {
        
        stringTable = new byte[4096][];
        
        for (int i=0; i<256; i++) {
            stringTable[i] = new byte[1];
            stringTable[i][0] = (byte)i;
        }
        
        tableIndex = 258;
        bitsToGet = 9;
    }
404303
public void loadDocuments(String docsFile) throws IOException {
        ZipFile zipFile = new ZipFile(docsFile);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();

        int numDocs = 0;
        int numDesigns = 0;

        while (entries.hasMoreElements()) {
            ZipEntry ent = entries.nextElement();
            String fName = ent.getName();
            InputStream is = zipFile.getInputStream(ent);
            String contents = ReaderUtils.fromStream(is);

            Matcher mIsDoc = ptnDOCUMENT.matcher(fName);

            if (mIsDoc.matches()) {
                String docId = mIsDoc.group(1);
                handleDocument(docId, contents);
                numDocs++;
                continue;
            }

            Matcher mIsDesign = ptnDESIGN.matcher(fName);
            if (mIsDesign.matches()) {
                String designName = mIsDesign.group(1);
                handleDesign(designName, contents);
                numDesigns++;
            }
        }
        System.err.printf("Loaded %d documents. %d design documents%n", numDocs, numDesigns);
    }
921248
public static String streamToString(final InputStream is) throws IOException {
        final StringBuffer sb = new StringBuffer();
        final BufferedReader in = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = in.readLine()) != null) {
            sb.append(line);
            sb.append(LS);
        }
        return sb.toString();
    }
145418
static String readString(final InputStream is) {
        try (final Scanner s = new Scanner(is, "UTF-8")) {
            s.useDelimiter("\\A");
            if (s.hasNext()) {
                return s.next();
            } else {
                return "";
            }
        }
    }
1193392
private void readTableIndex(TableEntry10 table)
    throws IOException
  {
    for (Segment10 segment : tableSegments(table)) {
      try (ReadStream is = openRead(segment.address(), segment.length())) {
        readSegmentIndex(is, segment);
      }
    }
  }
1205433
public <T> List<T> readCSV2Objects(InputStream is, Class<T> clazz) {

        try {
            return readCSVByMapHandler(is, clazz);
        } catch (Excel4JException | IOException e) {
            throw new Excel4jReadException("read CSV Error: ", e);
        }
    }
133575
public boolean readMessage(InputStream is)
    throws IOException
  { 
    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();
    
    try (OutboxAmp outbox = OutboxAmp.currentOrCreate(getManager())) {
      return readMessage(is, outbox);
    } catch (Throwable e) {
      log.log(Level.WARNING, e.toString(), e);
      
      throw e;
    } finally {
      thread.setContextClassLoader(loader);
    }
  }
1305750
public List<List<String>> readExcel2List(InputStream is, int offsetLine)
            throws IOException, InvalidFormatException {

        try (Workbook workbook = WorkbookFactory.create(is)) {
            return readExcel2ObjectsHandler(workbook, offsetLine, Integer.MAX_VALUE, 0);
        }
    }
460716
private void readObject(java.io.ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException
    {
        s.defaultReadObject();
        if (encryptedContent != null)
            encryptedContent = encryptedContent.clone();
        if (encodedParams != null)
            encodedParams = encodedParams.clone();
    }
310881
public static byte[] getBytes(InputStream is) throws IOException {
        ByteArrayOutputStream answer = new ByteArrayOutputStream();
        // reading the content of the file within a byte buffer
        byte[] byteBuffer = new byte[8192];
        int nbByteRead /* = 0*/;
        try {
            while ((nbByteRead = is.read(byteBuffer)) != -1) {
                // appends buffer
                answer.write(byteBuffer, 0, nbByteRead);
            }
        } finally {
            closeWithWarning(is);
        }
        return answer.toByteArray();
    }
1372632
private static byte[] readAllBytes(InputStream is) throws IOException {
        byte[] buffer = new byte[8192];
        ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
        int n;
        while ((n = is.read(buffer)) != -1) {
            baos.write(buffer, 0, n);
        }
        return baos.toByteArray();
    }
656705
public void decode(InputStream is, OutputStream os) throws IOException {
	   int read, idx=0;
	   int prev=0, index;
	   	while((read = is.read())>=0) {
	   		index = convert.convert(read);
	   		if(index>=0) {
	    		switch(++idx) { // 1 based cases, slightly faster ++
	    			case 1: // index goes into first 6 bits of prev
	    				prev = index<<2; 
	    				break;
	    			case 2: // write second 2 bits of into prev, write byte, last 4 bits go into prev
	    				os.write((byte)(prev|(index>>4)));
	    				prev = index<<4;
	    				break;
	    			case 3: // first 4 bits of index goes into prev, write byte, last 2 bits go into prev
	    				os.write((byte)(prev|(index>>2)));
	    				prev = index<<6;
	    				break;
	    			default: // (3+) | prev and last six of index
	    				os.write((byte)(prev|(index&0x3F)));
	    				idx = prev = 0;
	    		}
	   		}
	   	};
	   	os.flush();
   }
968382
public static void extract(InputStream is, File outputFolder) throws IOException {
        ZipInputStream zis = new ZipInputStream(is);
        ZipEntry entry;
        byte[] buffer = new byte[1024];

        while ((entry = zis.getNextEntry()) != null) {
            File outputFile = new File(outputFolder.getCanonicalPath() + File.separatorChar + entry.getName());
            File outputParent = new File(outputFile.getParent());
            outputParent.mkdirs();

            if (entry.isDirectory()) {
                if (!outputFile.exists()) {
                    outputFile.mkdir();
                }
            } else {
                try (FileOutputStream fos = new FileOutputStream(outputFile)) {
                    int len;
                    while ((len = zis.read(buffer)) > 0) {
                        fos.write(buffer, 0, len);
                    }
                }
            }
        }
    }
1200871
public void simpleSheet2Excel(List<SimpleSheetWrapper> sheets, boolean isXSSF, OutputStream os)
            throws IOException {

        try (Workbook workbook = exportExcelBySimpleHandler(sheets, isXSSF)) {
            workbook.write(os);
        }
    }
222247
private boolean readMetaTable(ReadStream is, int crc)
    throws IOException
  {
    byte []key = new byte[TABLE_KEY_SIZE];
      
    is.read(key, 0, key.length);
    crc = Crc32Caucho.generate(crc, key);
    
    int rowLength = BitsUtil.readInt16(is);
    crc = Crc32Caucho.generateInt16(crc, rowLength);
      
    int keyOffset = BitsUtil.readInt16(is);
    crc = Crc32Caucho.generateInt16(crc, keyOffset);
      
    int keyLength = BitsUtil.readInt16(is);
    crc = Crc32Caucho.generateInt16(crc, keyLength);
    
    int dataLength = BitsUtil.readInt16(is);
    crc = Crc32Caucho.generateInt16(crc, dataLength);
    
    byte []data = new byte[dataLength];
    is.read(data);
    crc = Crc32Caucho.generate(crc, data);
    
    int crcFile = BitsUtil.readInt(is);
      
    if (crcFile != crc) {
      log.fine("meta-table crc mismatch");
      System.out.println("meta-table crc mismatch");
      return false;
    }
    
    RowUpgrade row = new RowUpgrade10(keyOffset, keyLength).read(data);
    
    TableEntry10 table = new TableEntry10(key,
                                          rowLength,
                                          keyOffset,
                                          keyLength,
                                          row);

    _tableList.add(table);

    return true;
  }