SonarQube fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777526 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0aa24b3b60
commit
d7da7a0ff4
@ -16,11 +16,10 @@
|
||||
==================================================================== */
|
||||
package org.apache.poi.hssf.usermodel.examples;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||
import org.apache.poi.hssf.usermodel.HSSFObjectData;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.hwpf.HWPFDocument;
|
||||
@ -39,26 +38,19 @@ public class EmbeddedObjects {
|
||||
for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
|
||||
//the OLE2 Class Name of the object
|
||||
String oleName = obj.getOLE2ClassName();
|
||||
DirectoryNode dn = (obj.hasDirectoryEntry()) ? (DirectoryNode) obj.getDirectory() : null;
|
||||
Closeable document = null;
|
||||
if (oleName.equals("Worksheet")) {
|
||||
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
|
||||
HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, fs, false);
|
||||
//System.out.println(entry.getName() + ": " + embeddedWorkbook.getNumberOfSheets());
|
||||
embeddedWorkbook.close();
|
||||
document = new HSSFWorkbook(dn, fs, false);
|
||||
} else if (oleName.equals("Document")) {
|
||||
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
|
||||
HWPFDocument embeddedWordDocument = new HWPFDocument(dn);
|
||||
//System.out.println(entry.getName() + ": " + embeddedWordDocument.getRange().text());
|
||||
document = new HWPFDocument(dn);
|
||||
} else if (oleName.equals("Presentation")) {
|
||||
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
|
||||
HSLFSlideShow embeddedPowerPointDocument = new HSLFSlideShow(new HSLFSlideShowImpl(dn));
|
||||
//System.out.println(entry.getName() + ": " + embeddedPowerPointDocument.getSlides().length);
|
||||
document = new HSLFSlideShow(dn);
|
||||
} else {
|
||||
if(obj.hasDirectoryEntry()){
|
||||
if(dn != null){
|
||||
// The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is
|
||||
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
|
||||
for (Iterator<Entry> entries = dn.getEntries(); entries.hasNext();) {
|
||||
Entry entry = entries.next();
|
||||
//System.out.println(oleName + "." + entry.getName());
|
||||
for (Entry entry : dn) {
|
||||
String name = entry.getName();
|
||||
}
|
||||
} else {
|
||||
// There is no DirectoryEntry
|
||||
@ -66,6 +58,9 @@ public class EmbeddedObjects {
|
||||
byte[] objectData = obj.getObjectData();
|
||||
}
|
||||
}
|
||||
if (document != null) {
|
||||
document.close();
|
||||
}
|
||||
}
|
||||
workbook.close();
|
||||
}
|
||||
|
@ -159,7 +159,6 @@ public class CryptoAPIDecryptor extends Decryptor implements Cloneable {
|
||||
*/
|
||||
public POIFSFileSystem getSummaryEntries(DirectoryNode root, String encryptedStream)
|
||||
throws IOException, GeneralSecurityException {
|
||||
POIFSFileSystem fsOut = new POIFSFileSystem();
|
||||
// HSLF: encryptedStream
|
||||
// HSSF: encryption
|
||||
DocumentNode es = (DocumentNode) root.getEntry(encryptedStream);
|
||||
@ -169,6 +168,7 @@ public class CryptoAPIDecryptor extends Decryptor implements Cloneable {
|
||||
dis.close();
|
||||
CryptoAPIDocumentInputStream sbis = new CryptoAPIDocumentInputStream(this, bos.toByteArray());
|
||||
LittleEndianInputStream leis = new LittleEndianInputStream(sbis);
|
||||
POIFSFileSystem fsOut = null;
|
||||
try {
|
||||
int streamDescriptorArrayOffset = (int) leis.readUInt();
|
||||
/* int streamDescriptorArraySize = (int) */ leis.readUInt();
|
||||
@ -194,6 +194,7 @@ public class CryptoAPIDecryptor extends Decryptor implements Cloneable {
|
||||
assert(entry.streamName.length() == nameSize);
|
||||
}
|
||||
|
||||
fsOut = new POIFSFileSystem();
|
||||
for (StreamDescriptorEntry entry : entries) {
|
||||
sbis.seek(entry.streamOffset);
|
||||
sbis.setBlock(entry.block);
|
||||
@ -201,11 +202,19 @@ public class CryptoAPIDecryptor extends Decryptor implements Cloneable {
|
||||
fsOut.createDocument(is, entry.streamName);
|
||||
is.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
IOUtils.closeQuietly(fsOut);
|
||||
if (e instanceof GeneralSecurityException) {
|
||||
throw (GeneralSecurityException)e;
|
||||
} else if (e instanceof IOException) {
|
||||
throw (IOException)e;
|
||||
} else {
|
||||
throw new IOException("summary entries can't be read", e);
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeQuietly(leis);
|
||||
IOUtils.closeQuietly(sbis);
|
||||
}
|
||||
sbis = null;
|
||||
return fsOut;
|
||||
}
|
||||
|
||||
@ -220,6 +229,7 @@ public class CryptoAPIDecryptor extends Decryptor implements Cloneable {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunkSize(int chunkSize) {
|
||||
this.chunkSize = chunkSize;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public final class ZipPackage extends OPCPackage {
|
||||
|
||||
ZipEntrySource ze;
|
||||
try {
|
||||
final ZipFile zipFile = ZipHelper.openZipFile(file);
|
||||
final ZipFile zipFile = ZipHelper.openZipFile(file); // NOSONAR
|
||||
ze = new ZipFileZipEntrySource(zipFile);
|
||||
} catch (IOException e) {
|
||||
// probably not happening with write access - not sure how to handle the default read-write access ...
|
||||
@ -149,7 +149,7 @@ public final class ZipPackage extends OPCPackage {
|
||||
// Acquire a resource that is needed to read the next level of openZipEntrySourceStream
|
||||
try {
|
||||
// open the file input stream
|
||||
fis = new FileInputStream(file);
|
||||
fis = new FileInputStream(file); // NOSONAR
|
||||
} catch (final FileNotFoundException e) {
|
||||
// If the source cannot be acquired, abort (no resources to free at this level)
|
||||
throw new InvalidOperationException("Can't open the specified file input stream from file: '" + file + "'", e);
|
||||
@ -175,7 +175,7 @@ public final class ZipPackage extends OPCPackage {
|
||||
// Acquire a resource that is needed to read the next level of openZipEntrySourceStream
|
||||
try {
|
||||
// open the zip input stream
|
||||
zis = ZipHelper.openZipStream(fis);
|
||||
zis = ZipHelper.openZipStream(fis); // NOSONAR
|
||||
} catch (final IOException e) {
|
||||
// If the source cannot be acquired, abort (no resources to free at this level)
|
||||
throw new InvalidOperationException("Could not open the file input stream", e);
|
||||
|
Loading…
Reference in New Issue
Block a user