Browse Source

Use interfaces for variables and reformat source-code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911436 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_4
Dominik Stadler 9 months ago
parent
commit
acf61f325f
1 changed files with 78 additions and 145 deletions
  1. 78
    145
      poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java

+ 78
- 145
poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java View File

@@ -24,6 +24,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.HashMap;
@@ -141,7 +143,8 @@ public class SXSSFWorkbook implements Workbook {
/**
* Construct a new workbook with default row window size
*/
public SXSSFWorkbook(){
public SXSSFWorkbook()
{
this(null /*workbook*/);
}

@@ -180,7 +183,7 @@ public class SXSSFWorkbook implements Workbook {
*
* @param workbook the template workbook
*/
public SXSSFWorkbook(XSSFWorkbook workbook){
public SXSSFWorkbook(XSSFWorkbook workbook) {
this(workbook, DEFAULT_WINDOW_SIZE);
}

@@ -205,7 +208,7 @@ public class SXSSFWorkbook implements Workbook {
*
* @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
*/
public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize){
public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize) {
this(workbook, rowAccessWindowSize, false);
}

@@ -292,7 +295,7 @@ public class SXSSFWorkbook implements Workbook {
*
* @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
*/
public SXSSFWorkbook(int rowAccessWindowSize){
public SXSSFWorkbook(int rowAccessWindowSize) {
this(null /*workbook*/, rowAccessWindowSize);
}

@@ -384,24 +387,20 @@ public class SXSSFWorkbook implements Workbook {
return new SheetDataWriter(_sharedStringSource);
}

XSSFSheet getXSSFSheet(SXSSFSheet sheet)
{
XSSFSheet getXSSFSheet(SXSSFSheet sheet) {
return _sxFromXHash.get(sheet);
}

SXSSFSheet getSXSSFSheet(XSSFSheet sheet)
{
SXSSFSheet getSXSSFSheet(XSSFSheet sheet) {
return _xFromSxHash.get(sheet);
}

void registerSheetMapping(SXSSFSheet sxSheet,XSSFSheet xSheet)
{
void registerSheetMapping(SXSSFSheet sxSheet,XSSFSheet xSheet) {
_sxFromXHash.put(sxSheet,xSheet);
_xFromSxHash.put(xSheet,sxSheet);
}

void deregisterSheetMapping(XSSFSheet xSheet)
{
void deregisterSheetMapping(XSSFSheet xSheet) {
SXSSFSheet sxSheet = getSXSSFSheet(xSheet);
if (sxSheet != null) {
// ensure that the writer is closed in all cases to not have lingering writers
@@ -411,10 +410,8 @@ public class SXSSFWorkbook implements Workbook {
}
}

protected XSSFSheet getSheetFromZipEntryName(String sheetRef)
{
for(XSSFSheet sheet : _sxFromXHash.values())
{
protected XSSFSheet getSheetFromZipEntryName(String sheetRef) {
for(XSSFSheet sheet : _sxFromXHash.values()) {
if(sheetRef.equals(sheet.getPackagePart().getPartName().getName().substring(1))) {
return sheet;
}
@@ -477,31 +474,25 @@ public class SXSSFWorkbook implements Workbook {

// private static void copyStreamAndInjectWorksheet(InputStream in, OutputStream out, InputStream worksheetData) throws IOException {
private static void copyStreamAndInjectWorksheet(InputStream in, OutputStream out, ISheetInjector sheetInjector) throws IOException {
InputStreamReader inReader = new InputStreamReader(in, StandardCharsets.UTF_8);
OutputStreamWriter outWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);
Reader inReader = new InputStreamReader(in, StandardCharsets.UTF_8);
Writer outWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);
boolean needsStartTag = true;
int c;
int pos=0;
String s="<sheetData";
int n=s.length();
//Copy from "in" to "out" up to the string "<sheetData/>" or "</sheetData>" (excluding).
while(((c=inReader.read())!=-1))
{
if(c==s.charAt(pos))
{
while(((c=inReader.read())!=-1)) {
if(c==s.charAt(pos)) {
pos++;
if(pos==n)
{
if ("<sheetData".equals(s))
{
if(pos==n) {
if ("<sheetData".equals(s)) {
c = inReader.read();
if (c == -1)
{
if (c == -1) {
outWriter.write(s);
break;
}
if (c == '>')
{
if (c == '>') {
// Found <sheetData>
outWriter.write(s);
outWriter.write(c);
@@ -511,17 +502,14 @@ public class SXSSFWorkbook implements Workbook {
needsStartTag = false;
continue;
}
if (c == '/')
{
if (c == '/') {
// Found <sheetData/
c = inReader.read();
if (c == -1)
{
if (c == -1) {
outWriter.write(s);
break;
}
if (c == '>')
{
if (c == '>') {
// Found <sheetData/>
break;
}
@@ -538,33 +526,25 @@ public class SXSSFWorkbook implements Workbook {
outWriter.write(c);
pos = 0;
continue;
}
else
{
} else {
// Found </sheetData>
break;
}
}
}
else
{
} else {
if(pos>0) {
outWriter.write(s,0,pos);
}
if(c==s.charAt(0))
{
if(c==s.charAt(0)) {
pos=1;
}
else
{
} else {
outWriter.write(c);
pos=0;
}
}
}
outWriter.flush();
if (needsStartTag)
{
if (needsStartTag) {
outWriter.write("<sheetData>\n");
outWriter.flush();
}
@@ -578,8 +558,7 @@ public class SXSSFWorkbook implements Workbook {
outWriter.flush();
}

public XSSFWorkbook getXSSFWorkbook()
{
public XSSFWorkbook getXSSFWorkbook() {
return _wb;
}

@@ -593,8 +572,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the index of the active sheet (0-based)
*/
@Override
public int getActiveSheetIndex()
{
public int getActiveSheetIndex() {
return _wb.getActiveSheetIndex();
}

@@ -606,8 +584,7 @@ public class SXSSFWorkbook implements Workbook {
* @param sheetIndex index of the active sheet (0-based)
*/
@Override
public void setActiveSheet(int sheetIndex)
{
public void setActiveSheet(int sheetIndex) {
_wb.setActiveSheet(sheetIndex);
}

@@ -617,8 +594,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the first tab that to display in the list of tabs (0-based).
*/
@Override
public int getFirstVisibleTab()
{
public int getFirstVisibleTab() {
return _wb.getFirstVisibleTab();
}

@@ -628,8 +604,7 @@ public class SXSSFWorkbook implements Workbook {
* @param sheetIndex the first tab that to display in the list of tabs (0-based)
*/
@Override
public void setFirstVisibleTab(int sheetIndex)
{
public void setFirstVisibleTab(int sheetIndex) {
_wb.setFirstVisibleTab(sheetIndex);
}

@@ -640,8 +615,7 @@ public class SXSSFWorkbook implements Workbook {
* @param pos the position that we want to insert the sheet into (0 based)
*/
@Override
public void setSheetOrder(String sheetname, int pos)
{
public void setSheetOrder(String sheetname, int pos) {
_wb.setSheetOrder(sheetname,pos);
}

@@ -655,8 +629,7 @@ public class SXSSFWorkbook implements Workbook {
* @param index the index of the sheet to select (0 based)
*/
@Override
public void setSelectedTab(int index)
{
public void setSelectedTab(int index) {
_wb.setSelectedTab(index);
}

@@ -667,8 +640,7 @@ public class SXSSFWorkbook implements Workbook {
* @throws IllegalArgumentException if the name is greater than 31 chars or contains <code>/\?*[]</code>
*/
@Override
public void setSheetName(int sheet, String name)
{
public void setSheetName(int sheet, String name) {
_wb.setSheetName(sheet,name);
}

@@ -679,8 +651,7 @@ public class SXSSFWorkbook implements Workbook {
* @return Sheet name
*/
@Override
public String getSheetName(int sheet)
{
public String getSheetName(int sheet) {
return _wb.getSheetName(sheet);
}

@@ -691,8 +662,7 @@ public class SXSSFWorkbook implements Workbook {
* @return index of the sheet (0 based)
*/
@Override
public int getSheetIndex(String name)
{
public int getSheetIndex(String name) {
return _wb.getSheetIndex(name);
}

@@ -703,8 +673,7 @@ public class SXSSFWorkbook implements Workbook {
* @return index of the sheet (0 based)
*/
@Override
public int getSheetIndex(Sheet sheet)
{
public int getSheetIndex(Sheet sheet) {
return _wb.getSheetIndex(getXSSFSheet((SXSSFSheet)sheet));
}

@@ -715,8 +684,7 @@ public class SXSSFWorkbook implements Workbook {
* @return Sheet representing the new sheet.
*/
@Override
public SXSSFSheet createSheet()
{
public SXSSFSheet createSheet() {
return createAndRegisterSXSSFSheet(_wb.createSheet());
}

@@ -740,8 +708,7 @@ public class SXSSFWorkbook implements Workbook {
* @throws IllegalArgumentException if the name is greater than 31 chars or contains <code>/\?*[]</code>
*/
@Override
public SXSSFSheet createSheet(String sheetname)
{
public SXSSFSheet createSheet(String sheetname) {
return createAndRegisterSXSSFSheet(_wb.createSheet(sheetname));
}

@@ -765,8 +732,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the number of sheets
*/
@Override
public int getNumberOfSheets()
{
public int getNumberOfSheets() {
return _wb.getNumberOfSheets();
}

@@ -829,8 +795,7 @@ public class SXSSFWorkbook implements Workbook {
* @return Sheet at the provided index
*/
@Override
public SXSSFSheet getSheetAt(int index)
{
public SXSSFSheet getSheetAt(int index) {
return getSXSSFSheet(_wb.getSheetAt(index));
}

@@ -841,8 +806,7 @@ public class SXSSFWorkbook implements Workbook {
* @return Sheet with the name provided or <code>null</code> if it does not exist
*/
@Override
public SXSSFSheet getSheet(String name)
{
public SXSSFSheet getSheet(String name) {
return getSXSSFSheet(_wb.getSheet(name));
}

@@ -852,8 +816,7 @@ public class SXSSFWorkbook implements Workbook {
* @param index of the sheet to remove (0-based)
*/
@Override
public void removeSheetAt(int index)
{
public void removeSheetAt(int index) {
// Get the sheet to be removed
XSSFSheet xSheet = _wb.getSheetAt(index);
SXSSFSheet sxSheet = getSXSSFSheet(xSheet);
@@ -876,8 +839,7 @@ public class SXSSFWorkbook implements Workbook {
* @return new font object
*/
@Override
public Font createFont()
{
public Font createFont() {
return _wb.createFont();
}

@@ -887,8 +849,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the font with the matched attributes or <code>null</code>
*/
@Override
public Font findFont(boolean bold, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
{
public Font findFont(boolean bold, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
return _wb.findFont(bold, color, fontHeight, name, italic, strikeout, typeOffset, underline);
}

@@ -900,14 +861,12 @@ public class SXSSFWorkbook implements Workbook {
@Override
@Deprecated
@Removal(version = "6.0.0")
public int getNumberOfFontsAsInt()
{
public int getNumberOfFontsAsInt() {
return getNumberOfFonts();
}

@Override
public Font getFontAt(int idx)
{
public Font getFontAt(int idx) {
return _wb.getFontAt(idx);
}

@@ -917,8 +876,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the new Cell Style object
*/
@Override
public CellStyle createCellStyle()
{
public CellStyle createCellStyle() {
return _wb.createCellStyle();
}

@@ -928,8 +886,7 @@ public class SXSSFWorkbook implements Workbook {
* @return count of cell styles
*/
@Override
public int getNumCellStyles()
{
public int getNumCellStyles() {
return _wb.getNumCellStyles();
}

@@ -940,8 +897,7 @@ public class SXSSFWorkbook implements Workbook {
* @return CellStyle object at the index
*/
@Override
public CellStyle getCellStyleAt(int idx)
{
public CellStyle getCellStyleAt(int idx) {
return _wb.getCellStyleAt(idx);
}

@@ -956,8 +912,7 @@ public class SXSSFWorkbook implements Workbook {
@Override
public void close() throws IOException {
// ensure that any lingering writer is closed
for (SXSSFSheet sheet : _xFromSxHash.values())
{
for (SXSSFSheet sheet : _xFromSxHash.values()) {
try {
SheetDataWriter _writer = sheet.getSheetDataWriter();
if (_writer != null) _writer.close();
@@ -1046,11 +1001,9 @@ public class SXSSFWorkbook implements Workbook {
* Calling this method will render the workbook unusable.
* @return true if all temporary files were deleted successfully.
*/
public boolean dispose()
{
public boolean dispose() {
boolean success = true;
for (SXSSFSheet sheet : _sxFromXHash.keySet())
{
for (SXSSFSheet sheet : _sxFromXHash.keySet()) {
try {
success = sheet.dispose() && success;
} catch (IOException e) {
@@ -1065,8 +1018,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the total number of defined names in this workbook
*/
@Override
public int getNumberOfNames()
{
public int getNumberOfNames() {
return _wb.getNumberOfNames();
}

@@ -1075,8 +1027,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the defined name with the specified name. <code>null</code> if not found.
*/
@Override
public Name getName(String name)
{
public Name getName(String name) {
return _wb.getName(name);
}

@@ -1097,8 +1048,7 @@ public class SXSSFWorkbook implements Workbook {
* @return all defined names
*/
@Override
public List<? extends Name> getAllNames()
{
public List<? extends Name> getAllNames() {
return _wb.getAllNames();
}

@@ -1108,8 +1058,7 @@ public class SXSSFWorkbook implements Workbook {
* @return new defined name object
*/
@Override
public Name createName()
{
public Name createName() {
return _wb.createName();
}

@@ -1119,8 +1068,7 @@ public class SXSSFWorkbook implements Workbook {
* @param name the name to remove
*/
@Override
public void removeName(Name name)
{
public void removeName(Name name) {
_wb.removeName(name);
}

@@ -1132,8 +1080,7 @@ public class SXSSFWorkbook implements Workbook {
* @param reference Valid name Reference for the Print Area
*/
@Override
public void setPrintArea(int sheetIndex, String reference)
{
public void setPrintArea(int sheetIndex, String reference) {
_wb.setPrintArea(sheetIndex,reference);
}

@@ -1147,8 +1094,7 @@ public class SXSSFWorkbook implements Workbook {
* @param endRow Row to end the printarea
*/
@Override
public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
{
public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
_wb.setPrintArea(sheetIndex, startColumn, endColumn, startRow, endRow);
}

@@ -1160,8 +1106,7 @@ public class SXSSFWorkbook implements Workbook {
* @return String Null if no print area has been defined
*/
@Override
public String getPrintArea(int sheetIndex)
{
public String getPrintArea(int sheetIndex) {
return _wb.getPrintArea(sheetIndex);
}

@@ -1171,8 +1116,7 @@ public class SXSSFWorkbook implements Workbook {
* @param sheetIndex Zero-based sheet index (0 = First Sheet)
*/
@Override
public void removePrintArea(int sheetIndex)
{
public void removePrintArea(int sheetIndex) {
_wb.removePrintArea(sheetIndex);
}

@@ -1185,8 +1129,7 @@ public class SXSSFWorkbook implements Workbook {
* </p>
*/
@Override
public MissingCellPolicy getMissingCellPolicy()
{
public MissingCellPolicy getMissingCellPolicy() {
return _wb.getMissingCellPolicy();
}

@@ -1199,8 +1142,7 @@ public class SXSSFWorkbook implements Workbook {
* {@link MissingCellPolicy}
*/
@Override
public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy)
{
public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
_wb.setMissingCellPolicy(missingCellPolicy);
}

@@ -1210,8 +1152,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the DataFormat object
*/
@Override
public DataFormat createDataFormat()
{
public DataFormat createDataFormat() {
return _wb.createDataFormat();
}

@@ -1230,8 +1171,7 @@ public class SXSSFWorkbook implements Workbook {
* @see #PICTURE_TYPE_DIB
*/
@Override
public int addPicture(byte[] pictureData, int format)
{
public int addPicture(byte[] pictureData, int format) {
return _wb.addPicture(pictureData,format);
}

@@ -1241,8 +1181,7 @@ public class SXSSFWorkbook implements Workbook {
* @return the list of pictures (a list of {@link PictureData} objects.)
*/
@Override
public List<? extends PictureData> getAllPictures()
{
public List<? extends PictureData> getAllPictures() {
return _wb.getAllPictures();
}

@@ -1262,27 +1201,23 @@ public class SXSSFWorkbook implements Workbook {

@Override
@NotImplemented("XSSFWorkbook#isHidden is not implemented")
public boolean isHidden()
{
public boolean isHidden() {
return _wb.isHidden();
}

@Override
@NotImplemented("XSSFWorkbook#setHidden is not implemented")
public void setHidden(boolean hiddenFlag)
{
public void setHidden(boolean hiddenFlag) {
_wb.setHidden(hiddenFlag);
}

@Override
public boolean isSheetHidden(int sheetIx)
{
public boolean isSheetHidden(int sheetIx) {
return _wb.isSheetHidden(sheetIx);
}

@Override
public boolean isSheetVeryHidden(int sheetIx)
{
public boolean isSheetVeryHidden(int sheetIx) {
return _wb.isSheetVeryHidden(sheetIx);
}

@@ -1292,8 +1227,7 @@ public class SXSSFWorkbook implements Workbook {
}

@Override
public void setSheetHidden(int sheetIx, boolean hidden)
{
public void setSheetHidden(int sheetIx, boolean hidden) {
_wb.setSheetHidden(sheetIx,hidden);
}

@@ -1329,8 +1263,7 @@ public class SXSSFWorkbook implements Workbook {
* @param toolpack the toolpack to register
*/
@Override
public void addToolPack(UDFFinder toolpack)
{
public void addToolPack(UDFFinder toolpack) {
_wb.addToolPack(toolpack);
}

@@ -1347,7 +1280,7 @@ public class SXSSFWorkbook implements Workbook {
* @since 3.8
*/
@Override
public void setForceFormulaRecalculation(boolean value){
public void setForceFormulaRecalculation(boolean value) {
_wb.setForceFormulaRecalculation(value);
}

@@ -1355,7 +1288,7 @@ public class SXSSFWorkbook implements Workbook {
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
*/
@Override
public boolean getForceFormulaRecalculation(){
public boolean getForceFormulaRecalculation() {
return _wb.getForceFormulaRecalculation();
}


Loading…
Cancel
Save