sonar fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1736932 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-03-28 22:46:53 +00:00
parent 155323ee56
commit 033580e1b3
2 changed files with 41 additions and 37 deletions

View File

@ -44,7 +44,6 @@ import org.apache.poi.poifs.filesystem.DocumentNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.NotOLE2FileException; import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.ss.usermodel.Cell; 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 * 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 { public class OldExcelExtractor implements Closeable {
private RecordInputStream ris; private RecordInputStream ris;
private Closeable input;
private int biffVersion; private int biffVersion;
private int fileType; private int fileType;
public OldExcelExtractor(InputStream input) throws IOException { public OldExcelExtractor(InputStream input) throws IOException {
BufferedInputStream bstream = new BufferedInputStream(input, 8); open(input);
if (NPOIFSFileSystem.hasPOIFSHeader(bstream)) {
open(new NPOIFSFileSystem(bstream));
} else {
open(bstream);
}
} }
public OldExcelExtractor(File f) throws IOException { public OldExcelExtractor(File f) throws IOException {
NPOIFSFileSystem poifs = null;
try { try {
open(new NPOIFSFileSystem(f)); poifs = new NPOIFSFileSystem(f);
} catch (OldExcelFormatException oe) { open(poifs);
FileInputStream biffStream = new FileInputStream(f); return;
try { } catch (OldExcelFormatException e) {
open(biffStream); // will be handled by workaround below
} catch (RuntimeException e2) { if (poifs != null) {
// ensure that the stream is properly closed here if an Exception poifs.close();
// is thrown while opening
biffStream.close();
throw e2;
} }
} catch (NotOLE2FileException e) { } catch (NotOLE2FileException e) {
FileInputStream biffStream = new FileInputStream(f); // will be handled by workaround below
try { if (poifs != null) {
open(biffStream); poifs.close();
} catch (RuntimeException e2) {
// ensure that the stream is properly closed here if an Exception
// is thrown while opening
biffStream.close();
throw e2;
} }
} }
@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 { public OldExcelExtractor(NPOIFSFileSystem fs) throws IOException {
@ -107,14 +102,25 @@ public class OldExcelExtractor implements Closeable {
open(directory); open(directory);
} }
private void open(InputStream biffStream) { private void open(InputStream biffStream) throws IOException {
input = biffStream; BufferedInputStream bis = (biffStream instanceof BufferedInputStream)
ris = new RecordInputStream(biffStream); ? (BufferedInputStream)biffStream
prepare(); : 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 { private void open(NPOIFSFileSystem fs) throws IOException {
input = fs;
open(fs.getRoot()); open(fs.getRoot());
} }
@ -273,9 +279,7 @@ public class OldExcelExtractor implements Closeable {
@Override @Override
public void close() { public void close() {
if (input != null) { // not necessary any more ...
IOUtils.closeQuietly(input);
}
} }
protected void handleNumericCell(StringBuffer text, double value) { protected void handleNumericCell(StringBuffer text, double value) {

View File

@ -89,7 +89,7 @@ public class Colorref implements Cloneable
@Override @Override
public Colorref clone() throws CloneNotSupportedException public Colorref clone() throws CloneNotSupportedException
{ {
return new Colorref( this.value ); return (Colorref)super.clone();
} }
@Override @Override