mirror of https://github.com/apache/poi.git
Also fix some Eclipse warnings while hunting Bugs: Generics, unused
variables, ... git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1516312 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b7db2fceef
commit
d415bf5d06
|
@ -36,11 +36,11 @@ import org.apache.poi.ddf.EscherBitmapBlip;
|
||||||
import org.apache.poi.ddf.EscherBlipRecord;
|
import org.apache.poi.ddf.EscherBlipRecord;
|
||||||
import org.apache.poi.ddf.EscherRecord;
|
import org.apache.poi.ddf.EscherRecord;
|
||||||
import org.apache.poi.hssf.OldExcelFormatException;
|
import org.apache.poi.hssf.OldExcelFormatException;
|
||||||
|
import org.apache.poi.hssf.model.DrawingManager2;
|
||||||
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
||||||
import org.apache.poi.hssf.model.InternalSheet;
|
import org.apache.poi.hssf.model.InternalSheet;
|
||||||
import org.apache.poi.hssf.model.InternalWorkbook;
|
import org.apache.poi.hssf.model.InternalWorkbook;
|
||||||
import org.apache.poi.hssf.model.RecordStream;
|
import org.apache.poi.hssf.model.RecordStream;
|
||||||
import org.apache.poi.hssf.model.DrawingManager2;
|
|
||||||
import org.apache.poi.hssf.record.*;
|
import org.apache.poi.hssf.record.*;
|
||||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
||||||
import org.apache.poi.hssf.record.common.UnicodeString;
|
import org.apache.poi.hssf.record.common.UnicodeString;
|
||||||
|
@ -51,6 +51,7 @@ import org.apache.poi.ss.formula.FormulaShifter;
|
||||||
import org.apache.poi.ss.formula.FormulaType;
|
import org.apache.poi.ss.formula.FormulaType;
|
||||||
import org.apache.poi.ss.formula.SheetNameFormatter;
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
|
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
|
||||||
|
import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
|
||||||
import org.apache.poi.ss.formula.udf.UDFFinder;
|
import org.apache.poi.ss.formula.udf.UDFFinder;
|
||||||
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
@ -58,7 +59,6 @@ import org.apache.poi.ss.util.WorkbookUtil;
|
||||||
import org.apache.poi.util.Configurator;
|
import org.apache.poi.util.Configurator;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,7 +118,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* this holds the HSSFFont objects attached to this workbook.
|
* this holds the HSSFFont objects attached to this workbook.
|
||||||
* We only create these from the low level records as required.
|
* We only create these from the low level records as required.
|
||||||
*/
|
*/
|
||||||
private Hashtable fonts;
|
private Hashtable<Short,HSSFFont> fonts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* holds whether or not to preserve other nodes in the POIFS. Used
|
* holds whether or not to preserve other nodes in the POIFS. Used
|
||||||
|
@ -285,7 +285,6 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
workbook = InternalWorkbook.createWorkbook(records);
|
workbook = InternalWorkbook.createWorkbook(records);
|
||||||
setPropertiesFromWorkbook(workbook);
|
setPropertiesFromWorkbook(workbook);
|
||||||
int recOffset = workbook.getNumRecords();
|
int recOffset = workbook.getNumRecords();
|
||||||
int sheetNum = 0;
|
|
||||||
|
|
||||||
// convert all LabelRecord records to LabelSSTRecord
|
// convert all LabelRecord records to LabelSSTRecord
|
||||||
convertLabelRecords(records, recOffset);
|
convertLabelRecords(records, recOffset);
|
||||||
|
@ -353,13 +352,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* @see org.apache.poi.hssf.record.SSTRecord
|
* @see org.apache.poi.hssf.record.SSTRecord
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private void convertLabelRecords(List records, int offset)
|
private void convertLabelRecords(List<Record> records, int offset)
|
||||||
{
|
{
|
||||||
if (log.check( POILogger.DEBUG ))
|
if (log.check( POILogger.DEBUG ))
|
||||||
log.log(POILogger.DEBUG, "convertLabelRecords called");
|
log.log(POILogger.DEBUG, "convertLabelRecords called");
|
||||||
for (int k = offset; k < records.size(); k++)
|
for (int k = offset; k < records.size(); k++)
|
||||||
{
|
{
|
||||||
Record rec = ( Record ) records.get(k);
|
Record rec = records.get(k);
|
||||||
|
|
||||||
if (rec.getSid() == LabelRecord.sid)
|
if (rec.getSid() == LabelRecord.sid)
|
||||||
{
|
{
|
||||||
|
@ -661,9 +660,6 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
return workbook.resolveNameXText(refIndex, definedNameIndex);
|
return workbook.resolveNameXText(refIndex, definedNameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
|
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
|
||||||
* the high level representation. Use this to create new sheets.
|
* the high level representation. Use this to create new sheets.
|
||||||
|
@ -1034,7 +1030,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
|
|
||||||
public HSSFFont createFont()
|
public HSSFFont createFont()
|
||||||
{
|
{
|
||||||
FontRecord font = workbook.createNewFont();
|
/*FontRecord font =*/ workbook.createNewFont();
|
||||||
short fontindex = (short) (getNumberOfFonts() - 1);
|
short fontindex = (short) (getNumberOfFonts() - 1);
|
||||||
|
|
||||||
if (fontindex > 3)
|
if (fontindex > 3)
|
||||||
|
@ -1094,14 +1090,14 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* @return HSSFFont at the index
|
* @return HSSFFont at the index
|
||||||
*/
|
*/
|
||||||
public HSSFFont getFontAt(short idx) {
|
public HSSFFont getFontAt(short idx) {
|
||||||
if(fonts == null) fonts = new Hashtable();
|
if(fonts == null) fonts = new Hashtable<Short, HSSFFont>();
|
||||||
|
|
||||||
// So we don't confuse users, give them back
|
// So we don't confuse users, give them back
|
||||||
// the same object every time, but create
|
// the same object every time, but create
|
||||||
// them lazily
|
// them lazily
|
||||||
Short sIdx = Short.valueOf(idx);
|
Short sIdx = Short.valueOf(idx);
|
||||||
if(fonts.containsKey(sIdx)) {
|
if(fonts.containsKey(sIdx)) {
|
||||||
return (HSSFFont)fonts.get(sIdx);
|
return fonts.get(sIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
FontRecord font = workbook.getFontRecordAt(idx);
|
FontRecord font = workbook.getFontRecordAt(idx);
|
||||||
|
@ -1118,7 +1114,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* and that's not something you should normally do
|
* and that's not something you should normally do
|
||||||
*/
|
*/
|
||||||
protected void resetFontCache() {
|
protected void resetFontCache() {
|
||||||
fonts = new Hashtable();
|
fonts = new Hashtable<Short, HSSFFont>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1217,12 +1213,12 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
*/
|
*/
|
||||||
private static final class SheetRecordCollector implements RecordVisitor {
|
private static final class SheetRecordCollector implements RecordVisitor {
|
||||||
|
|
||||||
private List _list;
|
private List<Record> _list;
|
||||||
private int _totalSize;
|
private int _totalSize;
|
||||||
|
|
||||||
public SheetRecordCollector() {
|
public SheetRecordCollector() {
|
||||||
_totalSize = 0;
|
_totalSize = 0;
|
||||||
_list = new ArrayList(128);
|
_list = new ArrayList<Record>(128);
|
||||||
}
|
}
|
||||||
public int getTotalSize() {
|
public int getTotalSize() {
|
||||||
return _totalSize;
|
return _totalSize;
|
||||||
|
@ -1230,12 +1226,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
public void visitRecord(Record r) {
|
public void visitRecord(Record r) {
|
||||||
_list.add(r);
|
_list.add(r);
|
||||||
_totalSize+=r.getRecordSize();
|
_totalSize+=r.getRecordSize();
|
||||||
|
|
||||||
}
|
}
|
||||||
public int serialize(int offset, byte[] data) {
|
public int serialize(int offset, byte[] data) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int nRecs = _list.size();
|
int nRecs = _list.size();
|
||||||
for(int i=0; i<nRecs; i++) {
|
for(int i=0; i<nRecs; i++) {
|
||||||
Record rec = (Record)_list.get(i);
|
Record rec = _list.get(i);
|
||||||
result += rec.serialize(offset + result, data);
|
result += rec.serialize(offset + result, data);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1556,11 +1553,11 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
{
|
{
|
||||||
DrawingGroupRecord r = (DrawingGroupRecord) workbook.findFirstRecordBySid( DrawingGroupRecord.sid );
|
DrawingGroupRecord r = (DrawingGroupRecord) workbook.findFirstRecordBySid( DrawingGroupRecord.sid );
|
||||||
r.decode();
|
r.decode();
|
||||||
List escherRecords = r.getEscherRecords();
|
List<EscherRecord> escherRecords = r.getEscherRecords();
|
||||||
PrintWriter w = new PrintWriter(System.out);
|
PrintWriter w = new PrintWriter(System.out);
|
||||||
for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
|
for ( Iterator<EscherRecord> iterator = escherRecords.iterator(); iterator.hasNext(); )
|
||||||
{
|
{
|
||||||
EscherRecord escherRecord = (EscherRecord) iterator.next();
|
EscherRecord escherRecord = iterator.next();
|
||||||
if (fat)
|
if (fat)
|
||||||
System.out.println(escherRecord.toString());
|
System.out.println(escherRecord.toString());
|
||||||
else
|
else
|
||||||
|
|
|
@ -19,7 +19,13 @@
|
||||||
|
|
||||||
package org.apache.poi.xssf.streaming;
|
package org.apache.poi.xssf.streaming;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
@ -35,6 +41,7 @@ public class GZIPSheetDataWriter extends SheetDataWriter {
|
||||||
/**
|
/**
|
||||||
* @return temp file to write sheet data
|
* @return temp file to write sheet data
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public File createTempFile()throws IOException {
|
public File createTempFile()throws IOException {
|
||||||
File fd = File.createTempFile("poi-sxssf-sheet-xml", ".gz");
|
File fd = File.createTempFile("poi-sxssf-sheet-xml", ".gz");
|
||||||
return fd;
|
return fd;
|
||||||
|
@ -43,6 +50,7 @@ public class GZIPSheetDataWriter extends SheetDataWriter {
|
||||||
/**
|
/**
|
||||||
* @return a wrapped instance of GZIPOutputStream
|
* @return a wrapped instance of GZIPOutputStream
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Writer createWriter(File fd)throws IOException {
|
public Writer createWriter(File fd)throws IOException {
|
||||||
return new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(fd)));
|
return new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(fd)));
|
||||||
}
|
}
|
||||||
|
@ -51,6 +59,7 @@ public class GZIPSheetDataWriter extends SheetDataWriter {
|
||||||
/**
|
/**
|
||||||
* @return a GZIPInputStream stream to read the compressed temp file
|
* @return a GZIPInputStream stream to read the compressed temp file
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public InputStream getWorksheetXMLInputStream() throws IOException {
|
public InputStream getWorksheetXMLInputStream() throws IOException {
|
||||||
File fd = getTempFile();
|
File fd = getTempFile();
|
||||||
return new GZIPInputStream(new FileInputStream(fd));
|
return new GZIPInputStream(new FileInputStream(fd));
|
||||||
|
|
Loading…
Reference in New Issue