@Override
public ByteBuffer read(int length, long position) throws IOException {
if(position >= size()) {
- throw new IllegalArgumentException("Position " + position + " past the end of the file");
+ throw new IndexOutOfBoundsException("Position " + position + " past the end of the file");
}
// Do we read or map (for read/write?
// Check
if(worked == -1) {
- throw new IllegalArgumentException("Position " + position + " past the end of the file");
+ throw new IndexOutOfBoundsException("Position " + position + " past the end of the file");
}
// Ready it for reading
import java.util.Collection;
import java.util.List;
+import junit.framework.AssertionFailedError;
+
import org.apache.poi.POIDataSamples;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.hpsf.ClassID;
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;
-
/**
* Tests for {@link HSSFWorkbook}
*/
}
@Test
- @Ignore("Not currently working, bug in POIFS creating empty FS")
public void testWriteToNewFile() throws Exception {
// Open from a Stream
HSSFWorkbook wb = new HSSFWorkbook(
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Iterator;
import org.apache.poi.poifs.property.RootProperty;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.TempFile;
import org.junit.Test;
/**
original.close();
return new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
}
+ protected static NPOIFSFileSystem writeOutFileAndReadBack(NPOIFSFileSystem original) throws IOException {
+ final File file = TempFile.createTempFile("TestPOIFS", ".ole2");
+ final FileOutputStream fout = new FileOutputStream(file);
+ original.writeFilesystem(fout);
+ original.close();
+ return new NPOIFSFileSystem(file, false);
+ }
@Test
public void basicOpen() throws Exception {
assertEquals(0, fs._get_property_table().getStartBlock());
+ // Check the same but with saving to a file
+ fs = new NPOIFSFileSystem();
+ fs = writeOutFileAndReadBack(fs);
+
+ // Same, no change, SBAT remains empty
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(3));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getRoot().getProperty().getStartBlock());
+ assertEquals(0, fs._get_property_table().getStartBlock());
+
+
+
// Put everything within a new directory
DirectoryEntry testDir = fs.createDirectory("Test Directory");