Start on unit testing for HSSFWorkbook.write(File), bug in POIFS to fix first
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d84df31b50
commit
dfd3bbee21
@ -87,6 +87,23 @@ public class POIFSFileSystem
|
||||
super(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Creates a POIFSFileSystem from a <tt>File</tt>. This uses less memory than
|
||||
* creating from an <tt>InputStream</tt>.</p>
|
||||
*
|
||||
* <p>Note that with this constructor, you will need to call {@link #close()}
|
||||
* when you're done to have the underlying file closed, as the file is
|
||||
* kept open during normal operation to read the data out.</p>
|
||||
* @param readOnly whether the POIFileSystem will only be used in read-only mode
|
||||
*
|
||||
* @param file the File from which to read the data
|
||||
*
|
||||
* @exception IOException on errors reading, or on invalid data
|
||||
*/
|
||||
public POIFSFileSystem(File file, boolean readOnly) throws IOException {
|
||||
super(file, readOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Creates a POIFSFileSystem from a <tt>File</tt>. This uses less memory than
|
||||
* creating from an <tt>InputStream</tt>. The File will be opened read-only</p>
|
||||
@ -141,7 +158,7 @@ public class POIFSFileSystem
|
||||
tmp.close();
|
||||
|
||||
// Open it up again backed by the file
|
||||
return new POIFSFileSystem(file);
|
||||
return new POIFSFileSystem(file, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,6 +71,7 @@ import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
import org.apache.poi.util.RecordFormatException;
|
||||
import org.apache.poi.util.TempFile;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
@ -1277,4 +1278,22 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
|
||||
assertEquals(1, wb.getNumberOfSheets());
|
||||
assertEquals("Changed!", wb.getSheetAt(0).getRow(0).getCell(0).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Not currently working, bug in POIFS creating empty FS")
|
||||
public void testWriteToNewFile() throws Exception {
|
||||
// Open from a Stream
|
||||
HSSFWorkbook wb = new HSSFWorkbook(
|
||||
POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
|
||||
|
||||
// Save to a new temp file
|
||||
final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
|
||||
wb.write(file);
|
||||
wb.close();
|
||||
|
||||
// Read and check
|
||||
wb = new HSSFWorkbook(new NPOIFSFileSystem(file));
|
||||
assertEquals(3, wb.getNumberOfSheets());
|
||||
wb.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user