org.apache.poi.util.POILogger Java Examples
The following examples show how to use
org.apache.poi.util.POILogger.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VariantSupport.java From lams with GNU General Public License v2.0 | 7 votes |
/** * Writes a warning to {@code System.err} that a variant type is * unsupported by HPSF. Such a warning is written only once for each variant * type. Log messages can be turned on or off by * * @param ex The exception to log */ protected static void writeUnsupportedTypeMessage (final UnsupportedVariantTypeException ex) { if (isLogUnsupportedTypes()) { if (unsupportedMessage == null) { unsupportedMessage = new LinkedList<Long>(); } Long vt = Long.valueOf(ex.getVariantType()); if (!unsupportedMessage.contains(vt)) { logger.log( POILogger.ERROR, ex.getMessage()); unsupportedMessage.add(vt); } } }
Example #2
Source File: ChunkedCipherOutputStream.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void close() throws IOException { if (isClosed) { LOG.log(POILogger.DEBUG, "ChunkedCipherOutputStream was already closed - ignoring"); return; } isClosed = true; try { writeChunk(false); super.close(); if (fileOut != null) { int oleStreamSize = (int)(fileOut.length()+LittleEndianConsts.LONG_SIZE); calculateChecksum(fileOut, (int)pos); dir.createDocument(DEFAULT_POIFS_ENTRY, oleStreamSize, new EncryptedPackageWriter()); createEncryptionInfoEntry(dir, fileOut); } } catch (GeneralSecurityException e) { throw new IOException(e); } }
Example #3
Source File: CFRecordsAggregate.java From lams with GNU General Public License v2.0 | 6 votes |
private CFRecordsAggregate(CFHeaderBase pHeader, CFRuleBase[] pRules) { if(pHeader == null) { throw new IllegalArgumentException("header must not be null"); } if(pRules == null) { throw new IllegalArgumentException("rules must not be null"); } if(pRules.length > MAX_97_2003_CONDTIONAL_FORMAT_RULES) { logger.log(POILogger.WARN, "Excel versions before 2007 require that " + "No more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES + " rules may be specified, " + pRules.length + " were found," + " this file will cause problems with old Excel versions"); } if (pRules.length != pHeader.getNumberOfConditionalFormats()) { throw new RecordFormatException("Mismatch number of rules"); } header = pHeader; rules = new ArrayList<CFRuleBase>(pRules.length); for (CFRuleBase pRule : pRules) { checkRuleType(pRule); rules.add(pRule); } }
Example #4
Source File: OldLabelRecord.java From lams with GNU General Public License v2.0 | 6 votes |
/** * @param in the RecordInputstream to read the record from */ public OldLabelRecord(RecordInputStream in) { super(in, in.getSid() == biff2_sid); if (isBiff2()) { field_4_string_len = (short)in.readUByte(); } else { field_4_string_len = in.readShort(); } // Can only decode properly later when you know the codepage field_5_bytes = new byte[field_4_string_len]; in.read(field_5_bytes, 0, field_4_string_len); if (in.remaining() > 0) { logger.log(POILogger.INFO, "LabelRecord data remains: " + in.remaining() + " : " + HexDump.toHex(in.readRemainder()) ); } }
Example #5
Source File: LabelRecord.java From lams with GNU General Public License v2.0 | 6 votes |
/** * @param in the RecordInputstream to read the record from */ public LabelRecord(RecordInputStream in) { field_1_row = in.readUShort(); field_2_column = in.readShort(); field_3_xf_index = in.readShort(); field_4_string_len = in.readShort(); field_5_unicode_flag = in.readByte(); if (field_4_string_len > 0) { if (isUnCompressedUnicode()) { field_6_value = in.readUnicodeLEString(field_4_string_len); } else { field_6_value = in.readCompressedUnicode(field_4_string_len); } } else { field_6_value = ""; } if (in.remaining() > 0) { logger.log(POILogger.INFO, "LabelRecord data remains: " + in.remaining() + " : " + HexDump.toHex(in.readRemainder()) ); } }
Example #6
Source File: CellUtil.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Copies the entries in src to dest, using the preferential data type * so that maps can be compared for equality * * @param src the property map to copy from (read-only) * @param dest the property map to copy into * @since POI 3.15 beta 3 */ private static void putAll(final Map<String, Object> src, Map<String, Object> dest) { for (final String key : src.keySet()) { if (shortValues.contains(key)) { dest.put(key, getShort(src, key)); } else if (booleanValues.contains(key)) { dest.put(key, getBoolean(src, key)); } else if (borderTypeValues.contains(key)) { dest.put(key, getBorderStyle(src, key)); } else if (ALIGNMENT.equals(key)) { dest.put(key, getHorizontalAlignment(src, key)); } else if (VERTICAL_ALIGNMENT.equals(key)) { dest.put(key, getVerticalAlignment(src, key)); } else if (FILL_PATTERN.equals(key)) { dest.put(key, getFillPattern(src, key)); } else { if (log.check(POILogger.INFO)) { log.log(POILogger.INFO, "Ignoring unrecognized CellUtil format properties key: " + key); } } } }
Example #7
Source File: POIDocument.java From lams with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") private <T> T readPropertySet(Class<T> clazz, String name) { String localName = clazz.getName().substring(clazz.getName().lastIndexOf('.')+1); try { PropertySet ps = getPropertySet(name); if (clazz.isInstance(ps)) { return (T)ps; } else if (ps != null) { logger.log(POILogger.WARN, localName+" property set came back with wrong class - "+ps.getClass().getName()); } else { logger.log(POILogger.WARN, localName+" property set came back as null"); } } catch (IOException e) { logger.log(POILogger.ERROR, "can't retrieve property set", e); } return null; }
Example #8
Source File: InternalSheet.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Adds a value record to the sheet's contained binary records * (i.e. LabelSSTRecord or NumberRecord). * <P> * This method is "loc" sensitive. Meaning you need to set LOC to where you * want it to start searching. If you don't know do this: setLoc(getDimsLoc). * When adding several rows you can just start at the last one by leaving loc * at what this sets it to. * * @param row the row to add the cell value to * @param col the cell value record itself. */ public void addValueRecord(int row, CellValueRecordInterface col) { if(log.check(POILogger.DEBUG)) { log.log(POILogger.DEBUG, "add value record row" + row); } DimensionsRecord d = _dimensions; if (col.getColumn() >= d.getLastCol()) { d.setLastCol(( short ) (col.getColumn() + 1)); } if (col.getColumn() < d.getFirstCol()) { d.setFirstCol(col.getColumn()); } _rowsAggregate.insertCell(col); }
Example #9
Source File: FileBackedDataSource.java From lams with GNU General Public License v2.0 | 6 votes |
private static void unmap(final ByteBuffer buffer) { // not necessary for HeapByteBuffer, avoid lots of log-output on this class if(buffer.getClass().getName().endsWith("HeapByteBuffer")) { return; } AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override @SuppressForbidden("Java 9 Jigsaw whitelists access to sun.misc.Cleaner, so setAccessible works") public Void run() { try { final Method getCleanerMethod = buffer.getClass().getMethod("cleaner"); getCleanerMethod.setAccessible(true); final Object cleaner = getCleanerMethod.invoke(buffer); if (cleaner != null) { cleaner.getClass().getMethod("clean").invoke(cleaner); } } catch (Exception e) { logger.log(POILogger.WARN, "Unable to unmap memory mapped ByteBuffer.", e); } return null; // Void } }); }
Example #10
Source File: StandardEncryptor.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void processPOIFSWriterEvent(POIFSWriterEvent event) { try { LittleEndianOutputStream leos = new LittleEndianOutputStream(event.getStream()); // StreamSize (8 bytes): An unsigned integer that specifies the number of bytes used by data // encrypted within the EncryptedData field, not including the size of the StreamSize field. // Note that the actual size of the \EncryptedPackage stream (1) can be larger than this // value, depending on the block size of the chosen encryption algorithm leos.writeLong(countBytes); FileInputStream fis = new FileInputStream(fileOut); try { IOUtils.copy(fis, leos); } finally { fis.close(); } if (!fileOut.delete()) { logger.log(POILogger.ERROR, "Can't delete temporary encryption file: "+fileOut); } leos.close(); } catch (IOException e) { throw new EncryptedDocumentException(e); } }
Example #11
Source File: EscherMetafileBlip.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Decompresses the provided data, returning the inflated result. * * @param data the deflated picture data. * @return the inflated picture data. */ private static byte[] inflatePictureData(byte[] data) { try { InflaterInputStream in = new InflaterInputStream( new ByteArrayInputStream( data ) ); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; int readBytes; while ((readBytes = in.read(buf)) > 0) { out.write(buf, 0, readBytes); } return out.toByteArray(); } catch (IOException e) { log.log(POILogger.WARN, "Possibly corrupt compression or non-compressed data", e); return data; } }
Example #12
Source File: EscherGraphics2d.java From lams with GNU General Public License v2.0 | 6 votes |
public void draw(Shape shape) { if (shape instanceof Line2D) { Line2D shape2d = (Line2D) shape; int width = 0; if (_stroke != null && _stroke instanceof BasicStroke) { width = (int) ((BasicStroke)_stroke).getLineWidth() * 12700; } drawLine((int)shape2d.getX1(), (int)shape2d.getY1(), (int)shape2d.getX2(), (int)shape2d.getY2(), width); } else { if (logger.check(POILogger.WARN)) logger.log(POILogger.WARN, "draw not fully supported"); } }
Example #13
Source File: CustomProperties.java From lams with GNU General Public License v2.0 | 6 votes |
private void checkCodePage(String value) { int cp = getCodepage(); if (cp == -1) { cp = Property.DEFAULT_CODEPAGE; } if (cp == CodePageUtil.CP_UNICODE) { return; } String cps = ""; try { cps = CodePageUtil.codepageToEncoding(cp, false); } catch (UnsupportedEncodingException e) { LOG.log(POILogger.ERROR, "Codepage '"+cp+"' can't be found."); } if (!cps.isEmpty() && Charset.forName(cps).newEncoder().canEncode(value)) { return; } LOG.log(POILogger.DEBUG, "Charset '"+cps+"' can't encode '"+value+"' - switching to unicode."); setCodepage(CodePageUtil.CP_UNICODE); }
Example #14
Source File: DrawPictureShape.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void drawContent(Graphics2D graphics) { PictureData data = getShape().getPictureData(); if(data == null) return; Rectangle2D anchor = getAnchor(graphics, getShape()); Insets insets = getShape().getClipping(); try { ImageRenderer renderer = getImageRenderer(graphics, data.getContentType()); renderer.loadImage(data.getData(), data.getContentType()); renderer.drawImage(graphics, anchor, insets); } catch (IOException e) { LOG.log(POILogger.ERROR, "image can't be loaded/rendered.", e); } }
Example #15
Source File: OPOIFSFileSystem.java From lams with GNU General Public License v2.0 | 6 votes |
/** * @param stream the stream to be closed * @param success <code>false</code> if an exception is currently being thrown in the calling method */ protected void closeInputStream(InputStream stream, boolean success) { if(stream.markSupported() && !(stream instanceof ByteArrayInputStream)) { String msg = "POIFS is closing the supplied input stream of type (" + stream.getClass().getName() + ") which supports mark/reset. " + "This will be a problem for the caller if the stream will still be used. " + "If that is the case the caller should wrap the input stream to avoid this close logic. " + "This warning is only temporary and will not be present in future versions of POI."; _logger.log(POILogger.WARN, msg); } try { stream.close(); } catch (IOException e) { if(success) { throw new RuntimeException(e); } // else not success? Try block did not complete normally // just print stack trace and leave original ex to be thrown _logger.log(POILogger.ERROR, "can't close input stream", e); } }
Example #16
Source File: EscherGraphics.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @NotImplemented public void translate(int x, int y) { if (logger.check( POILogger.WARN )) logger.log(POILogger.WARN,"translate not supported"); }
Example #17
Source File: CFRecordsAggregate.java From lams with GNU General Public License v2.0 | 5 votes |
public void addRule(CFRuleBase r) { if (r == null) { throw new IllegalArgumentException("r must not be null"); } if(rules.size() >= MAX_97_2003_CONDTIONAL_FORMAT_RULES) { logger.log(POILogger.WARN, "Excel versions before 2007 cannot cope with" + " any more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES + " - this file will cause problems with old Excel versions"); } checkRuleType(r); rules.add(r); header.setNumberOfConditionalFormats(rules.size()); }
Example #18
Source File: EscherGraphics.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void drawString(AttributedCharacterIterator iterator, int x, int y) { if (logger.check( POILogger.WARN )) logger.log(POILogger.WARN,"drawString not supported"); }
Example #19
Source File: EscherGraphics.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (logger.check( POILogger.WARN )) logger.log(POILogger.WARN,"fillRoundRect not supported"); }
Example #20
Source File: EscherGraphics.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @NotImplemented public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (logger.check( POILogger.WARN )) logger.log(POILogger.WARN,"drawRoundRect not supported"); }
Example #21
Source File: EscherGraphics.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @NotImplemented public void setXORMode(Color color) { if (logger.check( POILogger.WARN )) logger.log(POILogger.WARN,"setXORMode not supported"); }
Example #22
Source File: EscherGraphics.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @NotImplemented public void setPaintMode() { if (logger.check( POILogger.WARN )) logger.log(POILogger.WARN,"setPaintMode not supported"); }
Example #23
Source File: ImageHeaderWMF.java From lams with GNU General Public License v2.0 | 5 votes |
public ImageHeaderWMF(byte[] data, final int off) { int offset = off; int key = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; //header key if (key != APMHEADER_KEY) { LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing"); handle = 0; left = 0; top = 0; right = 200; bottom = 200; inch = Units.POINT_DPI; //default resolution is 72 dpi reserved = 0; return; } handle = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; left = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; top = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; right = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; bottom = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; inch = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; reserved = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; checksum = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; if (checksum != getChecksum()){ LOG.log(POILogger.WARN, "WMF checksum does not match the header data"); } }
Example #24
Source File: DataFormatter.java From lams with GNU General Public License v2.0 | 5 votes |
private Format createNumberFormat(String formatStr, double cellValue) { String format = cleanFormatForNumber(formatStr); DecimalFormatSymbols symbols = decimalSymbols; // Do we need to change the grouping character? // eg for a format like #'##0 which wants 12'345 not 12,345 Matcher agm = alternateGrouping.matcher(format); if (agm.find()) { char grouping = agm.group(2).charAt(0); // Only replace the grouping character if it is not the default // grouping character for the US locale (',') in order to enable // correct grouping for non-US locales. if (grouping!=',') { symbols = DecimalFormatSymbols.getInstance(locale); symbols.setGroupingSeparator(grouping); String oldPart = agm.group(1); String newPart = oldPart.replace(grouping, ','); format = format.replace(oldPart, newPart); } } try { return new InternalDecimalFormatWithScale(format, symbols); } catch(IllegalArgumentException iae) { logger.log(POILogger.DEBUG, "Formatting failed for format " + formatStr + ", falling back", iae); // the pattern could not be parsed correctly, // so fall back to the default number format return getDefaultFormat(cellValue); } }
Example #25
Source File: RawDataBlock.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Constructor RawDataBlock * * @param stream the InputStream from which the data will be read * @param blockSize the size of the POIFS blocks, normally 512 bytes * {@link org.apache.poi.poifs.common.POIFSConstants#SMALLER_BIG_BLOCK_SIZE} * * @exception IOException on I/O errors, and if an insufficient * amount of data is read (the InputStream must * be an exact multiple of the block size) */ public RawDataBlock(final InputStream stream, int blockSize) throws IOException { _data = new byte[ blockSize ]; int count = IOUtils.readFully(stream, _data); _hasData = (count > 0); if (count == -1) { _eof = true; } else if (count != blockSize) { // IOUtils.readFully will always read the // requested number of bytes, unless it hits // an EOF _eof = true; String type = " byte" + ((count == 1) ? ("") : ("s")); log.log(POILogger.ERROR, "Unable to read entire block; " + count + type + " read before EOF; expected " + blockSize + " bytes. Your document " + "was either written by software that " + "ignores the spec, or has been truncated!" ); } else { _eof = false; } }
Example #26
Source File: DimensionsRecord.java From lams with GNU General Public License v2.0 | 5 votes |
public DimensionsRecord(RecordInputStream in) { field_1_first_row = in.readInt(); field_2_last_row = in.readInt(); field_3_first_col = in.readShort(); field_4_last_col = in.readShort(); field_5_zero = in.readShort(); //POI-61045 -- in practice, there can be an extra 2 bytes if (in.available() == 2) { logger.log(POILogger.INFO, "DimensionsRecord has extra 2 bytes."); in.readShort(); } }
Example #27
Source File: NPropertyTable.java From lams with GNU General Public License v2.0 | 5 votes |
private static List<Property> buildProperties(final Iterator<ByteBuffer> dataSource, final POIFSBigBlockSize bigBlockSize) throws IOException { List<Property> properties = new ArrayList<Property>(); while(dataSource.hasNext()) { ByteBuffer bb = dataSource.next(); // Turn it into an array byte[] data; if(bb.hasArray() && bb.arrayOffset() == 0 && bb.array().length == bigBlockSize.getBigBlockSize()) { data = bb.array(); } else { data = new byte[bigBlockSize.getBigBlockSize()]; int toRead = data.length; if (bb.remaining() < bigBlockSize.getBigBlockSize()) { // Looks to be a truncated block // This isn't allowed, but some third party created files // sometimes do this, and we can normally read anyway _logger.log(POILogger.WARN, "Short Property Block, ", bb.remaining(), " bytes instead of the expected " + bigBlockSize.getBigBlockSize()); toRead = bb.remaining(); } bb.get(data, 0, toRead); } PropertyFactory.convertToProperties(data, properties); } return properties; }
Example #28
Source File: NPOIFSFileSystem.java From lams with GNU General Public License v2.0 | 5 votes |
/** * @param stream the stream to be closed * @param success <code>false</code> if an exception is currently being thrown in the calling method */ private void closeInputStream(InputStream stream, boolean success) { try { stream.close(); } catch (IOException e) { if(success) { throw new RuntimeException(e); } // else not success? Try block did not complete normally // just print stack trace and leave original ex to be thrown LOG.log(POILogger.ERROR, "can't close input stream", e); } }
Example #29
Source File: POIFSDocumentPath.java From lams with GNU General Public License v2.0 | 5 votes |
/** * constructor that adds additional subdirectories to an existing * path * * @param path the existing path * @param components the additional subdirectory names to be added * * @exception IllegalArgumentException if any of the Strings in * components is null or zero * length */ public POIFSDocumentPath(final POIFSDocumentPath path, final String [] components) throws IllegalArgumentException { if (components == null) { this.components = new String[ path.components.length ]; } else { this.components = new String[ path.components.length + components.length ]; } for (int j = 0; j < path.components.length; j++) { this.components[ j ] = path.components[ j ]; } if (components != null) { for (int j = 0; j < components.length; j++) { if (components[ j ] == null) { throw new IllegalArgumentException( "components cannot contain null"); } if (components[ j ].length() == 0) { log.log(POILogger.WARN, "Directory under " + path + " has an empty name, " + "not all OLE2 readers will handle this file correctly!"); } this.components[ j + path.components.length ] = components[ j ]; } } }
Example #30
Source File: HSSFWorkbook.java From lams with GNU General Public License v2.0 | 5 votes |
/** * This is basically a kludge to deal with the now obsolete Label records. If * you have to read in a sheet that contains Label records, be aware that the rest * of the API doesn't deal with them, the low level structure only provides read-only * semi-immutable structures (the sets are there for interface conformance with NO * Implementation). In short, you need to call this function passing it a reference * to the Workbook object. All labels will be converted to LabelSST records and their * contained strings will be written to the Shared String table (SSTRecord) within * the Workbook. * * @param records a collection of sheet's records. * @param offset the offset to search at * @see org.apache.poi.hssf.record.LabelRecord * @see org.apache.poi.hssf.record.LabelSSTRecord * @see org.apache.poi.hssf.record.SSTRecord */ private void convertLabelRecords(List<Record> records, int offset) { if (log.check( POILogger.DEBUG )) { log.log(POILogger.DEBUG, "convertLabelRecords called"); } for (int k = offset; k < records.size(); k++) { Record rec = records.get(k); if (rec.getSid() == LabelRecord.sid) { LabelRecord oldrec = ( LabelRecord ) rec; records.remove(k); LabelSSTRecord newrec = new LabelSSTRecord(); int stringid = workbook.addSSTString(new UnicodeString(oldrec.getValue())); newrec.setRow(oldrec.getRow()); newrec.setColumn(oldrec.getColumn()); newrec.setXFIndex(oldrec.getXFIndex()); newrec.setSSTIndex(stringid); records.add(k, newrec); } } if (log.check( POILogger.DEBUG )) { log.log(POILogger.DEBUG, "convertLabelRecords exit"); } }