private void fillImageContent() { byte[] rawContent = getRawContent(); // HACK: Detect compressed images. In reality there should be some way to determine // this from the first 32 bytes, but I can't see any similarity between all the // samples I have obtained, nor any similarity in the data block contents. if (matchSignature(rawContent, COMPRESSED1, 32) || matchSignature(rawContent, COMPRESSED2, 32)) { try { InflaterInputStream in = new InflaterInputStream( new ByteArrayInputStream(rawContent, 33, rawContent.length - 33)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; int readBytes; while ((readBytes = in.read(buf)) > 0) { out.write(buf, 0, readBytes); } content = out.toByteArray(); } catch (IOException e) { // Problems reading from the actual ByteArrayInputStream should never happen // so this will only ever be a ZipException. log.log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e); } } else { // Raw data is not compressed. content = rawContent; } }
private static String decodeFileName(String encodedUrl) { /* see "MICROSOFT OFFICE EXCEL 97-2007 BINARY FILE FORMAT SPECIFICATION" */ StringBuilder sb = new StringBuilder(); for (int i = 1; i < encodedUrl.length(); i++) { char c = encodedUrl.charAt(i); switch (c) { case CH_VOLUME: char driveLetter = encodedUrl.charAt(++i); if (driveLetter == '@') { sb.append("\\\\"); } else { // Windows notation for drive letters sb.append(driveLetter).append(":"); } break; case CH_SAME_VOLUME: sb.append(PATH_SEPERATOR); break; case CH_DOWN_DIR: sb.append(PATH_SEPERATOR); break; case CH_UP_DIR: sb.append("..").append(PATH_SEPERATOR); break; case CH_LONG_VOLUME: // Don't known to handle... logger.log(POILogger.WARN, "Found unexpected key: ChLongVolume - IGNORING"); break; case CH_STARTUP_DIR: case CH_ALT_STARTUP_DIR: case CH_LIB_DIR: logger.log(POILogger.WARN, "EXCEL.EXE path unkown - using this directoy instead: ."); sb.append(".").append(PATH_SEPERATOR); break; default: sb.append(c); } } return sb.toString(); }