Make SlideShow closeable as of HSLF references a NPOIFSFileSystem and hasn't closed it

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-10-31 23:10:17 +00:00
parent f42904f162
commit f91f9120c2
3 changed files with 19 additions and 3 deletions

View File

@ -18,6 +18,7 @@
package org.apache.poi.sl.usermodel;
import java.awt.Dimension;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
@ -27,7 +28,7 @@ import org.apache.poi.sl.usermodel.PictureData.PictureType;
public interface SlideShow<
S extends Shape<S,P>,
P extends TextParagraph<S,P,?>
> {
> extends Closeable {
Slide<S,P> createSlide() throws IOException;
List<? extends Slide<S,P>> getSlides();

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.usermodel;
import java.awt.Dimension;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -88,7 +89,7 @@ import org.apache.poi.util.Units;
* @author Nick Burch
* @author Yegor kozlov
*/
public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph> {
public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable {
// What we're based on
private HSLFSlideShowImpl _hslfSlideShow;
@ -1157,4 +1158,9 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
// TODO Auto-generated method stub
return null;
}
@Override
public void close() throws IOException {
_hslfSlideShow.close();
}
}

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.usermodel;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -64,7 +65,7 @@ import org.apache.poi.util.POILogger;
*
* @author Nick Burch
*/
public final class HSLFSlideShowImpl extends POIDocument {
public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
public static final int UNSET_OFFSET = -1;
// For logging
@ -795,6 +796,14 @@ public final class HSLFSlideShowImpl extends POIDocument {
return _objects;
}
@Override
public void close() throws IOException {
NPOIFSFileSystem fs = directory.getFileSystem();
if (fs != null) {
fs.close();
}
}
private static class BufAccessBAOS extends ByteArrayOutputStream {
public byte[] getBuf() {