Author: kiwiwings
Date: Mon Mar 28 22:46:53 2016
New Revision: 1736932
URL: http://svn.apache.org/viewvc?rev=1736932&view=rev
Log:
sonar fixes
Modified:
poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Colorref.java
Modified:
poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java?rev=1736932&r1=1736931&r2=1736932&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java Mon
Mar 28 22:46:53 2016
@@ -44,7 +44,6 @@ import org.apache.poi.poifs.filesystem.D
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.util.IOUtils;
/**
* A text extractor for old Excel files, which are too old for
@@ -58,45 +57,41 @@ import org.apache.poi.util.IOUtils;
*/
public class OldExcelExtractor implements Closeable {
private RecordInputStream ris;
- private Closeable input;
private int biffVersion;
private int fileType;
public OldExcelExtractor(InputStream input) throws IOException {
- BufferedInputStream bstream = new BufferedInputStream(input, 8);
- if (NPOIFSFileSystem.hasPOIFSHeader(bstream)) {
- open(new NPOIFSFileSystem(bstream));
- } else {
- open(bstream);
- }
+ open(input);
}
public OldExcelExtractor(File f) throws IOException {
+ NPOIFSFileSystem poifs = null;
try {
- open(new NPOIFSFileSystem(f));
- } catch (OldExcelFormatException oe) {
- FileInputStream biffStream = new FileInputStream(f);
- try {
- open(biffStream);
- } catch (RuntimeException e2) {
- // ensure that the stream is properly closed here if an
Exception
- // is thrown while opening
- biffStream.close();
-
- throw e2;
+ poifs = new NPOIFSFileSystem(f);
+ open(poifs);
+ return;
+ } catch (OldExcelFormatException e) {
+ // will be handled by workaround below
+ if (poifs != null) {
+ poifs.close();
}
} catch (NotOLE2FileException e) {
- FileInputStream biffStream = new FileInputStream(f);
- try {
- open(biffStream);
- } catch (RuntimeException e2) {
- // ensure that the stream is properly closed here if an
Exception
- // is thrown while opening
- biffStream.close();
-
- throw e2;
+ // will be handled by workaround below
+ if (poifs != null) {
+ poifs.close();
}
}
+
+ @SuppressWarnings("resource")
+ FileInputStream biffStream = new FileInputStream(f);
+ try {
+ open(biffStream);
+ } catch (IOException e) {
+ // ensure that the stream is properly closed here if an Exception
+ // is thrown while opening
+ biffStream.close();
+ throw e;
+ }
}
public OldExcelExtractor(NPOIFSFileSystem fs) throws IOException {
@@ -107,14 +102,25 @@ public class OldExcelExtractor implement
open(directory);
}
- private void open(InputStream biffStream) {
- input = biffStream;
- ris = new RecordInputStream(biffStream);
- prepare();
+ private void open(InputStream biffStream) throws IOException {
+ BufferedInputStream bis = (biffStream instanceof BufferedInputStream)
+ ? (BufferedInputStream)biffStream
+ : new BufferedInputStream(biffStream, 8);
+
+ if (NPOIFSFileSystem.hasPOIFSHeader(bis)) {
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(bis);
+ try {
+ open(poifs);
+ } finally {
+ poifs.close();
+ }
+ } else {
+ ris = new RecordInputStream(bis);
+ prepare();
+ }
}
private void open(NPOIFSFileSystem fs) throws IOException {
- input = fs;
open(fs.getRoot());
}
@@ -273,9 +279,7 @@ public class OldExcelExtractor implement
@Override
public void close() {
- if (input != null) {
- IOUtils.closeQuietly(input);
- }
+ // not necessary any more ...
}
protected void handleNumericCell(StringBuffer text, double value) {
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Colorref.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Colorref.java?rev=1736932&r1=1736931&r2=1736932&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Colorref.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Colorref.java Mon
Mar 28 22:46:53 2016
@@ -89,7 +89,7 @@ public class Colorref implements Cloneab
@Override
public Colorref clone() throws CloneNotSupportedException
{
- return new Colorref( this.value );
+ return (Colorref)super.clone();
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]