git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777739 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_16_BETA2
@@ -17,9 +17,7 @@ | |||
package org.apache.poi.util; | |||
import java.io.BufferedInputStream; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
@@ -168,7 +166,9 @@ public class HexDump { | |||
public static char toAscii(int dataB) { | |||
char charB = (char)(dataB & 0xFF); | |||
if (Character.isISOControl(charB)) return '.'; | |||
if (Character.isISOControl(charB)) { | |||
return '.'; | |||
} | |||
switch (charB) { | |||
// printable, but not compilable with current compiler encoding | |||
@@ -408,12 +408,10 @@ public class HexDump { | |||
} | |||
public static void main(String[] args) throws Exception { | |||
File file = new File(args[0]); | |||
InputStream in = new BufferedInputStream(new FileInputStream(file)); | |||
byte[] b = new byte[(int)file.length()]; | |||
in.read(b); | |||
System.out.println(HexDump.dump(b, 0, 0)); | |||
public static void main(String[] args) throws IOException { | |||
InputStream in = new FileInputStream(args[0]); | |||
byte[] b = IOUtils.toByteArray(in); | |||
in.close(); | |||
System.out.println(HexDump.dump(b, 0, 0)); | |||
} | |||
} |
@@ -56,7 +56,9 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream | |||
final int size = LittleEndianConsts.INT_SIZE; | |||
checkPosition(size); | |||
int le = LittleEndian.getInt(buf, pos); | |||
super.skip(size); | |||
if (super.skip(size) < size) { | |||
throw new RuntimeException("Buffer overrun"); | |||
} | |||
return le; | |||
} | |||
@@ -65,7 +67,9 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream | |||
final int size = LittleEndianConsts.LONG_SIZE; | |||
checkPosition(size); | |||
long le = LittleEndian.getLong(buf, pos); | |||
super.skip(size); | |||
if (super.skip(size) < size) { | |||
throw new RuntimeException("Buffer overrun"); | |||
} | |||
return le; | |||
} | |||
@@ -84,7 +88,9 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream | |||
final int size = LittleEndianConsts.SHORT_SIZE; | |||
checkPosition(size); | |||
int le = LittleEndian.getUShort(buf, pos); | |||
super.skip(size); | |||
if (super.skip(size) < size) { | |||
throw new RuntimeException("Buffer overrun"); | |||
} | |||
return le; | |||
} | |||
@@ -118,7 +118,7 @@ public class CombinedIterable<T> implements Iterable<T> { | |||
} else { | |||
lastI = masterIdx; | |||
val = currentMaster.getValue(); | |||
val = (currentMaster != null) ? currentMaster.getValue() : null; | |||
currentMaster = null; | |||
} | |||
@@ -101,7 +101,8 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor { | |||
/** | |||
* Gets the slide text, but not the notes text | |||
*/ | |||
public String getText() { | |||
@Override | |||
public String getText() { | |||
return getText(slidesByDefault, notesByDefault); | |||
} | |||
@@ -162,12 +163,10 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor { | |||
// If requested, get text from the master and it's layout | |||
if(masterText) { | |||
if(layout != null) { | |||
extractText(layout, true, text); | |||
} | |||
if(master != null) { | |||
extractText(master, true, text); | |||
} | |||
assert (layout != null); | |||
extractText(layout, true, text); | |||
assert (master != null); | |||
extractText(master, true, text); | |||
} | |||
// If the slide has comments, do those too |
@@ -115,11 +115,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> { | |||
} catch (Exception e){ | |||
throw new POIXMLException(e); | |||
} finally { | |||
try { | |||
is.close(); | |||
} catch (Exception e) { | |||
throw new POIXMLException(e); | |||
} | |||
IOUtils.closeQuietly(is); | |||
} | |||
} | |||
@@ -17,6 +17,9 @@ | |||
package org.apache.poi.xssf.streaming; | |||
import java.awt.Dimension; | |||
import java.io.IOException; | |||
import org.apache.poi.openxml4j.opc.PackagePart; | |||
import org.apache.poi.ss.usermodel.Picture; | |||
import org.apache.poi.ss.usermodel.Row; | |||
@@ -26,15 +29,19 @@ import org.apache.poi.ss.util.ImageUtils; | |||
import org.apache.poi.util.Internal; | |||
import org.apache.poi.util.POILogFactory; | |||
import org.apache.poi.util.POILogger; | |||
import org.apache.poi.xssf.usermodel.*; | |||
import org.apache.poi.xssf.usermodel.XSSFAnchor; | |||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | |||
import org.apache.poi.xssf.usermodel.XSSFDrawing; | |||
import org.apache.poi.xssf.usermodel.XSSFPicture; | |||
import org.apache.poi.xssf.usermodel.XSSFPictureData; | |||
import org.apache.poi.xssf.usermodel.XSSFShape; | |||
import org.apache.poi.xssf.usermodel.XSSFSheet; | |||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |||
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D; | |||
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; | |||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; | |||
import java.awt.Dimension; | |||
import java.io.IOException; | |||
/** | |||
* Streaming version of Picture. | |||
* Most of the code is a copy of the non-streaming XSSFPicture code. | |||
@@ -140,38 +147,31 @@ public final class SXSSFPicture implements Picture { | |||
double scaledHeight = size.getHeight() * scale; | |||
float w = 0; | |||
int col2 = anchor.getCol1(); | |||
int dx2 = 0; | |||
int col2 = anchor.getCol1()-1; | |||
for (;;) { | |||
w += getColumnWidthInPixels(col2); | |||
if(w > scaledWidth) break; | |||
col2++; | |||
while (w <= scaledWidth) { | |||
w += getColumnWidthInPixels(++col2); | |||
} | |||
if(w > scaledWidth) { | |||
double cw = getColumnWidthInPixels(col2 ); | |||
double delta = w - scaledWidth; | |||
dx2 = (int)(XSSFShape.EMU_PER_PIXEL * (cw - delta)); | |||
} | |||
assert (w > scaledWidth); | |||
double cw = getColumnWidthInPixels(col2); | |||
double deltaW = w - scaledWidth; | |||
int dx2 = (int)(XSSFShape.EMU_PER_PIXEL * (cw - deltaW)); | |||
anchor.setCol2(col2); | |||
anchor.setDx2(dx2); | |||
double h = 0; | |||
int row2 = anchor.getRow1(); | |||
int dy2 = 0; | |||
int row2 = anchor.getRow1()-1; | |||
for (;;) { | |||
h += getRowHeightInPixels(row2); | |||
if(h > scaledHeight) break; | |||
row2++; | |||
while (h <= scaledHeight) { | |||
h += getRowHeightInPixels(++row2); | |||
} | |||
if(h > scaledHeight) { | |||
double ch = getRowHeightInPixels(row2); | |||
double delta = h - scaledHeight; | |||
dy2 = (int)(XSSFShape.EMU_PER_PIXEL * (ch - delta)); | |||
} | |||
assert (h > scaledHeight); | |||
double ch = getRowHeightInPixels(row2); | |||
double deltaH = h - scaledHeight; | |||
int dy2 = (int)(XSSFShape.EMU_PER_PIXEL * (ch - deltaH)); | |||
anchor.setRow2(row2); | |||
anchor.setDy2(dy2); | |||