whitespace clean up before fix for BUG-60305

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1767020 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tim Allison 2016-10-28 13:25:14 +00:00
parent 51b4f2a365
commit 1c2f768b8c

View File

@ -169,7 +169,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
// when there's a dual storage entry, use it, as the outer document can't be read quite probably ...
String dualName = "PP97_DUALSTORAGE";
if (!dir.hasEntry(dualName)) return dir;
dir = (DirectoryNode)dir.getEntry(dualName);
dir = (DirectoryNode) dir.getEntry(dualName);
return dir;
}
@ -198,11 +198,10 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
*
* @throws IOException
*/
private void readPowerPointStream() throws IOException
{
private void readPowerPointStream() throws IOException {
// Get the main document stream
DocumentEntry docProps =
(DocumentEntry)directory.getEntry("PowerPoint Document");
(DocumentEntry) directory.getEntry("PowerPoint Document");
// Grab the document stream
int len = docProps.getSize();
@ -218,8 +217,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
* Builds the list of records, based on the contents
* of the PowerPoint stream
*/
private void buildRecords()
{
private void buildRecords() {
// The format of records in a powerpoint file are:
// <little endian 2 byte "info">
// <little endian 2 byte "type">
@ -253,18 +251,18 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
// its length to know where the next record will start)
//
_records = read(_docstream, (int)currentUser.getCurrentEditOffset());
_records = read(_docstream, (int) currentUser.getCurrentEditOffset());
}
private Record[] read(byte[] docstream, int usrOffset){
private Record[] read(byte[] docstream, int usrOffset) {
//sort found records by offset.
//(it is not necessary but SlideShow.findMostRecentCoreRecords() expects them sorted)
NavigableMap<Integer,Record> records = new TreeMap<Integer,Record>(); // offset -> record
Map<Integer,Integer> persistIds = new HashMap<Integer,Integer>(); // offset -> persistId
NavigableMap<Integer, Record> records = new TreeMap<Integer, Record>(); // offset -> record
Map<Integer, Integer> persistIds = new HashMap<Integer, Integer>(); // offset -> persistId
initRecordOffsets(docstream, usrOffset, records, persistIds);
HSLFSlideShowEncrypted decryptData = new HSLFSlideShowEncrypted(docstream, records);
for (Map.Entry<Integer,Record> entry : records.entrySet()) {
for (Map.Entry<Integer, Record> entry : records.entrySet()) {
Integer offset = entry.getKey();
Record record = entry.getValue();
Integer persistId = persistIds.get(offset);
@ -277,23 +275,23 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
}
if (record instanceof PersistRecord) {
((PersistRecord)record).setPersistId(persistId);
((PersistRecord) record).setPersistId(persistId);
}
}
return records.values().toArray(new Record[records.size()]);
}
private void initRecordOffsets(byte[] docstream, int usrOffset, NavigableMap<Integer,Record> recordMap, Map<Integer,Integer> offset2id) {
while (usrOffset != 0){
private void initRecordOffsets(byte[] docstream, int usrOffset, NavigableMap<Integer, Record> recordMap, Map<Integer, Integer> offset2id) {
while (usrOffset != 0) {
UserEditAtom usr = (UserEditAtom) Record.buildRecordAtOffset(docstream, usrOffset);
recordMap.put(usrOffset, usr);
int psrOffset = usr.getPersistPointersOffset();
PersistPtrHolder ptr = (PersistPtrHolder)Record.buildRecordAtOffset(docstream, psrOffset);
PersistPtrHolder ptr = (PersistPtrHolder) Record.buildRecordAtOffset(docstream, psrOffset);
recordMap.put(psrOffset, ptr);
for(Map.Entry<Integer,Integer> entry : ptr.getSlideLocationsLookup().entrySet()) {
for (Map.Entry<Integer, Integer> entry : ptr.getSlideLocationsLookup().entrySet()) {
Integer offset = entry.getValue();
Integer id = entry.getKey();
recordMap.put(offset, null); // reserve a slot for the record
@ -306,11 +304,11 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
// if the next user edit atom offset is already known, we would go into an endless loop
if (usrOffset > 0 && recordMap.containsKey(usrOffset)) {
// a user edit atom is usually located 36 byte before the smallest known record offset
usrOffset = recordMap.firstKey()-36;
usrOffset = recordMap.firstKey() - 36;
// check that we really are located on a user edit atom
int ver_inst = LittleEndian.getUShort(docstream, usrOffset);
int type = LittleEndian.getUShort(docstream, usrOffset+2);
int len = LittleEndian.getInt(docstream, usrOffset+4);
int type = LittleEndian.getUShort(docstream, usrOffset + 2);
int len = LittleEndian.getInt(docstream, usrOffset + 4);
if (ver_inst == 0 && type == 4085 && (len == 0x1C || len == 0x20)) {
logger.log(POILogger.WARN, "Repairing invalid user edit atom");
usr.setLastUserEditAtomOffset(usrOffset);
@ -324,7 +322,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
public DocumentEncryptionAtom getDocumentEncryptionAtom() {
for (Record r : _records) {
if (r instanceof DocumentEncryptionAtom) {
return (DocumentEncryptionAtom)r;
return (DocumentEncryptionAtom) r;
}
}
return null;
@ -337,7 +335,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
private void readCurrentUserStream() {
try {
currentUser = new CurrentUserAtom(directory);
} catch(IOException ie) {
} catch (IOException ie) {
logger.log(POILogger.ERROR, "Error finding Current User Atom:\n" + ie);
currentUser = new CurrentUserAtom();
}
@ -362,14 +360,14 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
HSLFSlideShowEncrypted decryptData = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom());
DocumentEntry entry = (DocumentEntry)directory.getEntry("Pictures");
DocumentEntry entry = (DocumentEntry) directory.getEntry("Pictures");
DocumentInputStream is = directory.createDocumentInputStream(entry);
byte[] pictstream = IOUtils.toByteArray(is, entry.getSize());
is.close();
int pos = 0;
// An empty picture record (length 0) will take up 8 bytes
while (pos <= (pictstream.length-8)) {
while (pos <= (pictstream.length - 8)) {
int offset = pos;
decryptData.decryptPicture(pictstream, offset);
@ -392,7 +390,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
// The image size must be 0 or greater
// (0 is allowed, but odd, since we do wind on by the header each
// time, so we won't get stuck)
if(imgsize < 0) {
if (imgsize < 0) {
throw new CorruptPowerPointFileException("The file contains a picture, at position " + _pictures.size() + ", which has a negatively sized data length, so we can't trust any of the picture data");
}
@ -415,7 +413,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
pict.setOffset(offset);
pict.setIndex(_pictures.size());
_pictures.add(pict);
} catch(IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
logger.log(POILogger.ERROR, "Problem reading picture: " + e + "\nYou document will probably become corrupted if you save it!");
}
}
@ -448,12 +446,12 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
* May be null, if not needed.
* @throws IOException
*/
public void updateAndWriteDependantRecords(OutputStream os, Map<RecordTypes,PositionDependentRecord> interestingRecords)
public void updateAndWriteDependantRecords(OutputStream os, Map<RecordTypes, PositionDependentRecord> interestingRecords)
throws IOException {
// For position dependent records, hold where they were and now are
// As we go along, update, and hand over, to any Position Dependent
// records we happen across
Map<Integer,Integer> oldToNewPositions = new HashMap<Integer,Integer>();
Map<Integer, Integer> oldToNewPositions = new HashMap<Integer, Integer>();
// First pass - figure out where all the position dependent
// records are going to end up, in the new scheme
@ -464,29 +462,29 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
CountingOS cos = new CountingOS();
for (Record record : _records) {
// all top level records are position dependent
assert(record instanceof PositionDependentRecord);
PositionDependentRecord pdr = (PositionDependentRecord)record;
assert (record instanceof PositionDependentRecord);
PositionDependentRecord pdr = (PositionDependentRecord) record;
int oldPos = pdr.getLastOnDiskOffset();
int newPos = cos.size();
pdr.setLastOnDiskOffset(newPos);
if (oldPos != UNSET_OFFSET) {
// new records don't need a mapping, as they aren't in a relation yet
oldToNewPositions.put(oldPos,newPos);
oldToNewPositions.put(oldPos, newPos);
}
// Grab interesting records as they come past
// this will only save the very last record of each type
RecordTypes saveme = null;
int recordType = (int)record.getRecordType();
int recordType = (int) record.getRecordType();
if (recordType == RecordTypes.PersistPtrIncrementalBlock.typeID) {
saveme = RecordTypes.PersistPtrIncrementalBlock;
ptr = (PersistPtrHolder)pdr;
ptr = (PersistPtrHolder) pdr;
} else if (recordType == RecordTypes.UserEditAtom.typeID) {
saveme = RecordTypes.UserEditAtom;
usr = (UserEditAtom)pdr;
usr = (UserEditAtom) pdr;
}
if (interestingRecords != null && saveme != null) {
interestingRecords.put(saveme,pdr);
interestingRecords.put(saveme, pdr);
}
// Dummy write out, so the position winds on properly
@ -498,19 +496,19 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
throw new HSLFException("UserEditAtom or PersistPtr can't be determined.");
}
Map<Integer,Integer> persistIds = new HashMap<Integer,Integer>();
for (Map.Entry<Integer,Integer> entry : ptr.getSlideLocationsLookup().entrySet()) {
Map<Integer, Integer> persistIds = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : ptr.getSlideLocationsLookup().entrySet()) {
persistIds.put(oldToNewPositions.get(entry.getValue()), entry.getKey());
}
HSLFSlideShowEncrypted encData = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom());
for (Record record : _records) {
assert(record instanceof PositionDependentRecord);
assert (record instanceof PositionDependentRecord);
// We've already figured out their new location, and
// told them that
// Tell them of the positions of the other records though
PositionDependentRecord pdr = (PositionDependentRecord)record;
PositionDependentRecord pdr = (PositionDependentRecord) record;
Integer persistId = persistIds.get(pdr.getLastOnDiskOffset());
if (persistId == null) persistId = 0;
@ -529,7 +527,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
encData.close();
// Update and write out the Current User atom
int oldLastUserEditAtomPos = (int)currentUser.getCurrentEditOffset();
int oldLastUserEditAtomPos = (int) currentUser.getCurrentEditOffset();
Integer newLastUserEditAtomPos = oldToNewPositions.get(oldLastUserEditAtomPos);
if (newLastUserEditAtomPos == null || usr.getLastOnDiskOffset() != newLastUserEditAtomPos) {
throw new HSLFException("Couldn't find the new location of the last UserEditAtom that used to be at " + oldLastUserEditAtomPos);
@ -539,17 +537,16 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
/**
* Writes out the slideshow to the currently open file.
*
* <p>
* <p>This will fail (with an {@link IllegalStateException} if the
* slideshow was opened read-only, opened from an {@link InputStream}
* instead of a File, or if this is not the root document. For those cases,
* you must use {@link #write(OutputStream)} or {@link #write(File)} to
* write to a brand new document.
*
* @since POI 3.15 beta 3
*
* @throws IOException thrown on errors writing to the file
* @throws IllegalStateException if this isn't from a writable File
* @since POI 3.15 beta 3
*/
@Override
public void write() throws IOException {
@ -569,6 +566,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
* <p>This will write out only the common OLE2 streams. If you require all
* streams to be written out, use {@link #write(File, boolean)}
* with <code>preserveNodes</code> set to <code>true</code>.
*
* @param newFile The File to write to.
* @throws IOException If there is an unexpected IOException from writing to the File
*/
@ -577,11 +575,13 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
// Write out, but only the common streams
write(newFile, false);
}
/**
* Writes out the slideshow file the is represented by an instance
* of this class.
* If you require all streams to be written out (eg Marcos, embeded
* documents), then set <code>preserveNodes</code> set to <code>true</code>
*
* @param newFile The File to write to.
* @param preserveNodes Should all OLE2 streams be written back out, or only the common ones?
* @throws IOException If there is an unexpected IOException from writing to the File
@ -607,6 +607,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
* <p>This will write out only the common OLE2 streams. If you require all
* streams to be written out, use {@link #write(OutputStream, boolean)}
* with <code>preserveNodes</code> set to <code>true</code>.
*
* @param out The OutputStream to write to.
* @throws IOException If there is an unexpected IOException from
* the passed in OutputStream
@ -616,11 +617,13 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
// Write out, but only the common streams
write(out, false);
}
/**
* Writes out the slideshow file the is represented by an instance
* of this class.
* If you require all streams to be written out (eg Marcos, embeded
* documents), then set <code>preserveNodes</code> set to <code>true</code>
*
* @param out The OutputStream to write to.
* @param preserveNodes Should all OLE2 streams be written back out, or only the common ones?
* @throws IOException If there is an unexpected IOException from
@ -640,6 +643,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
outFS.close();
}
}
private void write(NPOIFSFileSystem outFS, boolean copyAllOtherNodes) throws IOException {
// read properties and pictures, with old encryption settings where appropriate
if (_pictures == null) {
@ -671,7 +675,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
// Write the PPT stream into the POIFS layer
ByteArrayInputStream bais = new ByteArrayInputStream(_docstream);
outFS.createOrUpdateDocument(bais,"PowerPoint Document");
outFS.createOrUpdateDocument(bais, "PowerPoint Document");
writtenEntries.add("PowerPoint Document");
currentUser.setEncrypted(encryptedSS.getDocumentEncryptionAtom() != null);
@ -715,9 +719,9 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
/**
* Writes out the standard Documment Information Properties (HPSF)
*
* @param outFS the POIFSFileSystem to write the properties into
* @param writtenEntries a list of POIFS entries to add the property names too
*
* @throws IOException if an error when writing to the
* {@link POIFSFileSystem} occurs
*/
@ -725,7 +729,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
super.writeProperties(outFS, writtenEntries);
DocumentEncryptionAtom dea = getDocumentEncryptionAtom();
if (dea != null) {
CryptoAPIEncryptor enc = (CryptoAPIEncryptor)dea.getEncryptionInfo().getEncryptor();
CryptoAPIEncryptor enc = (CryptoAPIEncryptor) dea.getEncryptionInfo().getEncryptor();
try {
enc.getSummaryEntries(outFS.getRoot()); // ignore OutputStream
} catch (IOException e) {
@ -744,15 +748,15 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
*/
public synchronized int appendRootLevelRecord(Record newRecord) {
int addedAt = -1;
Record[] r = new Record[_records.length+1];
Record[] r = new Record[_records.length + 1];
boolean added = false;
for(int i=(_records.length-1); i>=0; i--) {
if(added) {
for (int i = (_records.length - 1); i >= 0; i--) {
if (added) {
// Just copy over
r[i] = _records[i];
} else {
r[(i+1)] = _records[i];
if(_records[i] instanceof PersistPtrHolder) {
r[(i + 1)] = _records[i];
if (_records[i] instanceof PersistPtrHolder) {
r[i] = newRecord;
added = true;
addedAt = i;
@ -770,22 +774,22 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
*/
public int addPicture(HSLFPictureData img) {
// Process any existing pictures if we haven't yet
if(_pictures == null) {
if (_pictures == null) {
try {
readPictures();
} catch(IOException e) {
} catch (IOException e) {
throw new CorruptPowerPointFileException(e.getMessage());
}
}
// Add the new picture in
int offset = 0;
if(_pictures.size() > 0) {
if (_pictures.size() > 0) {
HSLFPictureData prev = _pictures.get(_pictures.size() - 1);
offset = prev.getOffset() + prev.getRawData().length + 8;
}
img.setOffset(offset);
img.setIndex(_pictures.size()+1);
img.setIndex(_pictures.size() + 1);
_pictures.add(img);
return offset;
}
@ -796,18 +800,24 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
/**
* Returns an array of all the records found in the slideshow
*/
public Record[] getRecords() { return _records; }
public Record[] getRecords() {
return _records;
}
/**
* Returns an array of the bytes of the file. Only correct after a
* call to open or write - at all other times might be wrong!
*/
public byte[] getUnderlyingBytes() { return _docstream; }
public byte[] getUnderlyingBytes() {
return _docstream;
}
/**
* Fetch the Current User Atom of the document
*/
public CurrentUserAtom getCurrentUserAtom() { return currentUser; }
public CurrentUserAtom getCurrentUserAtom() {
return currentUser;
}
/**
* Return list of pictures contained in this presentation
@ -816,10 +826,10 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
* presentation doesn't contain pictures.
*/
public List<HSLFPictureData> getPictureData() {
if(_pictures == null) {
if (_pictures == null) {
try {
readPictures();
} catch(IOException e) {
} catch (IOException e) {
throw new CorruptPowerPointFileException(e.getMessage());
}
}
@ -837,7 +847,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
List<HSLFObjectData> objects = new ArrayList<HSLFObjectData>();
for (Record r : _records) {
if (r instanceof ExOleObjStg) {
objects.add(new HSLFObjectData((ExOleObjStg)r));
objects.add(new HSLFObjectData((ExOleObjStg) r));
}
}
_objects = objects.toArray(new HSLFObjectData[objects.size()]);
@ -862,6 +872,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
private static class CountingOS extends OutputStream {
int count = 0;
public void write(int b) throws IOException {
count++;
}