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;
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
}
- 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));
}
}
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;
}
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;
}
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;
}
/**
* Gets the slide text, but not the notes text
*/
- public String getText() {
+ @Override
+ public String getText() {
return getText(slidesByDefault, notesByDefault);
}
// 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
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;
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.
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);