mirror of https://github.com/apache/poi.git
Remove deprecated methods from NPOIFSFileSystem/OPOIFSFileSystem
IntelliJ warnings/suggestions git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808622 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ade4aec2dd
commit
e504e87873
|
@ -23,6 +23,7 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
import org.apache.poi.POIXMLDocument;
|
||||||
import org.apache.poi.poifs.crypt.Decryptor;
|
import org.apache.poi.poifs.crypt.Decryptor;
|
||||||
|
import org.apache.poi.poifs.filesystem.FileMagic;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
|
|
||||||
public final class POIXMLDocumentHandler {
|
public final class POIXMLDocumentHandler {
|
||||||
|
@ -35,14 +36,11 @@ public final class POIXMLDocumentHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isEncrypted(InputStream stream) throws IOException {
|
protected static boolean isEncrypted(InputStream stream) throws IOException {
|
||||||
if (POIFSFileSystem.hasPOIFSHeader(stream)) {
|
if (FileMagic.valueOf(stream) == FileMagic.OLE2) {
|
||||||
POIFSFileSystem poifs = new POIFSFileSystem(stream);
|
try (POIFSFileSystem poifs = new POIFSFileSystem(stream)) {
|
||||||
try {
|
|
||||||
if (poifs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
|
if (poifs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
poifs.close();
|
|
||||||
}
|
}
|
||||||
throw new IOException("Wrong file format or file extension for OO XML file");
|
throw new IOException("Wrong file format or file extension for OO XML file");
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,10 +40,7 @@ import org.apache.poi.hssf.record.OldSheetRecord;
|
||||||
import org.apache.poi.hssf.record.OldStringRecord;
|
import org.apache.poi.hssf.record.OldStringRecord;
|
||||||
import org.apache.poi.hssf.record.RKRecord;
|
import org.apache.poi.hssf.record.RKRecord;
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.*;
|
||||||
import org.apache.poi.poifs.filesystem.DocumentNode;
|
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
|
||||||
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
|
|
||||||
import org.apache.poi.ss.usermodel.CellType;
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
|
||||||
|
@ -80,16 +77,8 @@ public class OldExcelExtractor implements Closeable {
|
||||||
open(poifs);
|
open(poifs);
|
||||||
toClose = poifs;
|
toClose = poifs;
|
||||||
return;
|
return;
|
||||||
} catch (OldExcelFormatException e) {
|
} catch (OldExcelFormatException | NotOLE2FileException e) {
|
||||||
// will be handled by workaround below
|
// will be handled by workaround below
|
||||||
} catch (NotOLE2FileException e) {
|
|
||||||
// will be handled by workaround below
|
|
||||||
} catch (IOException e) {
|
|
||||||
// ensure streams are closed correctly
|
|
||||||
throw e;
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
// ensure streams are closed correctly
|
|
||||||
throw e;
|
|
||||||
} finally {
|
} finally {
|
||||||
if (toClose == null) {
|
if (toClose == null) {
|
||||||
IOUtils.closeQuietly(poifs);
|
IOUtils.closeQuietly(poifs);
|
||||||
|
@ -100,12 +89,7 @@ public class OldExcelExtractor implements Closeable {
|
||||||
FileInputStream biffStream = new FileInputStream(f); // NOSONAR
|
FileInputStream biffStream = new FileInputStream(f); // NOSONAR
|
||||||
try {
|
try {
|
||||||
open(biffStream);
|
open(biffStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException | RuntimeException e) {
|
||||||
// ensure that the stream is properly closed here if an Exception
|
|
||||||
// is thrown while opening
|
|
||||||
biffStream.close();
|
|
||||||
throw e;
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
// ensure that the stream is properly closed here if an Exception
|
// ensure that the stream is properly closed here if an Exception
|
||||||
// is thrown while opening
|
// is thrown while opening
|
||||||
biffStream.close();
|
biffStream.close();
|
||||||
|
@ -126,12 +110,9 @@ public class OldExcelExtractor implements Closeable {
|
||||||
? (BufferedInputStream)biffStream
|
? (BufferedInputStream)biffStream
|
||||||
: new BufferedInputStream(biffStream, 8);
|
: new BufferedInputStream(biffStream, 8);
|
||||||
|
|
||||||
if (NPOIFSFileSystem.hasPOIFSHeader(bis)) {
|
if (FileMagic.valueOf(bis) == FileMagic.OLE2) {
|
||||||
NPOIFSFileSystem poifs = new NPOIFSFileSystem(bis);
|
try (NPOIFSFileSystem poifs = new NPOIFSFileSystem(bis)) {
|
||||||
try {
|
|
||||||
open(poifs);
|
open(poifs);
|
||||||
} finally {
|
|
||||||
poifs.close();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ris = new RecordInputStream(bis);
|
ris = new RecordInputStream(bis);
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class DirectoryNode
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
Property child = iter.next();
|
Property child = iter.next();
|
||||||
Entry childNode = null;
|
Entry childNode;
|
||||||
|
|
||||||
if (child.isDirectory())
|
if (child.isDirectory())
|
||||||
{
|
{
|
||||||
|
@ -586,16 +586,11 @@ public class DirectoryNode
|
||||||
* @return an Iterator; may not be null, but may have an empty
|
* @return an Iterator; may not be null, but may have an empty
|
||||||
* back end store
|
* back end store
|
||||||
*/
|
*/
|
||||||
public Iterator<Object> getViewableIterator()
|
public Iterator<Object> getViewableIterator() {
|
||||||
{
|
|
||||||
List<Object> components = new ArrayList<>();
|
List<Object> components = new ArrayList<>();
|
||||||
|
|
||||||
components.add(getProperty());
|
components.add(getProperty());
|
||||||
Iterator<Entry> iter = _entries.iterator();
|
components.addAll(_entries);
|
||||||
while (iter.hasNext())
|
|
||||||
{
|
|
||||||
components.add(iter.next());
|
|
||||||
}
|
|
||||||
return components.iterator();
|
return components.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.apache.poi.poifs.filesystem;
|
package org.apache.poi.poifs.filesystem;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -57,7 +56,6 @@ import org.apache.poi.util.IOUtils;
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.Removal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>This is the main class of the POIFS system; it manages the entire
|
* <p>This is the main class of the POIFS system; it manages the entire
|
||||||
|
@ -342,42 +340,6 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks that the supplied InputStream (which MUST
|
|
||||||
* support mark and reset) has a POIFS (OLE2) header at the start of it.
|
|
||||||
* If unsure if your InputStream does support mark / reset,
|
|
||||||
* use {@link FileMagic#prepareToCheckMagic(InputStream)} to wrap it and make
|
|
||||||
* sure to always use that, and not the original!
|
|
||||||
*
|
|
||||||
* After the method call, the InputStream is at the
|
|
||||||
* same position as of the time of entering the method.
|
|
||||||
*
|
|
||||||
* @param inp An InputStream which supports mark/reset
|
|
||||||
*
|
|
||||||
* @deprecated in 3.17-beta2, use {@link FileMagic#valueOf(InputStream)} == {@link FileMagic#OLE2} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Removal(version="4.0")
|
|
||||||
public static boolean hasPOIFSHeader(InputStream inp) throws IOException {
|
|
||||||
return FileMagic.valueOf(inp) == FileMagic.OLE2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the supplied first 8 bytes of a stream / file
|
|
||||||
* has a POIFS (OLE2) header.
|
|
||||||
*
|
|
||||||
* @deprecated in 3.17-beta2, use {@link FileMagic#valueOf(InputStream)} == {@link FileMagic#OLE2} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Removal(version="4.0")
|
|
||||||
public static boolean hasPOIFSHeader(byte[] header8Bytes) {
|
|
||||||
try {
|
|
||||||
return hasPOIFSHeader(new ByteArrayInputStream(header8Bytes));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("invalid header check", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read and process the PropertiesTable and the
|
* Read and process the PropertiesTable and the
|
||||||
* FAT / XFAT blocks, so that we're ready to
|
* FAT / XFAT blocks, so that we're ready to
|
||||||
|
@ -686,7 +648,6 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
*
|
*
|
||||||
* @exception IOException
|
* @exception IOException
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public DocumentEntry createDocument(final String name, final int size,
|
public DocumentEntry createDocument(final String name, final int size,
|
||||||
final POIFSWriterListener writer)
|
final POIFSWriterListener writer)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
@ -752,8 +713,7 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
*
|
*
|
||||||
* @exception IOException thrown on errors writing to the stream
|
* @exception IOException thrown on errors writing to the stream
|
||||||
*/
|
*/
|
||||||
public void writeFilesystem() throws IOException
|
public void writeFilesystem() throws IOException {
|
||||||
{
|
|
||||||
if(_data instanceof FileBackedDataSource) {
|
if(_data instanceof FileBackedDataSource) {
|
||||||
// Good, correct type
|
// Good, correct type
|
||||||
} else {
|
} else {
|
||||||
|
@ -779,10 +739,7 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
*
|
*
|
||||||
* @exception IOException thrown on errors writing to the stream
|
* @exception IOException thrown on errors writing to the stream
|
||||||
*/
|
*/
|
||||||
|
public void writeFilesystem(final OutputStream stream) throws IOException {
|
||||||
public void writeFilesystem(final OutputStream stream)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
// Have the datasource updated
|
// Have the datasource updated
|
||||||
syncWithDataSource();
|
syncWithDataSource();
|
||||||
|
|
||||||
|
@ -838,31 +795,19 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
*
|
*
|
||||||
* @exception IOException
|
* @exception IOException
|
||||||
*/
|
*/
|
||||||
|
public static void main(String args[]) throws IOException {
|
||||||
public static void main(String args[])
|
if (args.length != 2) {
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
if (args.length != 2)
|
|
||||||
{
|
|
||||||
System.err.println(
|
System.err.println(
|
||||||
"two arguments required: input filename and output filename");
|
"two arguments required: input filename and output filename");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
FileInputStream istream = new FileInputStream(args[ 0 ]);
|
|
||||||
try {
|
try (FileInputStream istream = new FileInputStream(args[0])) {
|
||||||
FileOutputStream ostream = new FileOutputStream(args[ 1 ]);
|
try (FileOutputStream ostream = new FileOutputStream(args[1])) {
|
||||||
try {
|
try (NPOIFSFileSystem fs = new NPOIFSFileSystem(istream)) {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(istream);
|
|
||||||
try {
|
|
||||||
fs.writeFilesystem(ostream);
|
fs.writeFilesystem(ostream);
|
||||||
} finally {
|
|
||||||
fs.close();
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
ostream.close();
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
istream.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -871,8 +816,7 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
*
|
*
|
||||||
* @return the root entry
|
* @return the root entry
|
||||||
*/
|
*/
|
||||||
public DirectoryNode getRoot()
|
public DirectoryNode getRoot() {
|
||||||
{
|
|
||||||
if (_root == null) {
|
if (_root == null) {
|
||||||
_root = new DirectoryNode(_property_table.getRoot(), this, null);
|
_root = new DirectoryNode(_property_table.getRoot(), this, null);
|
||||||
}
|
}
|
||||||
|
@ -889,11 +833,8 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
* @exception IOException if the document does not exist or the
|
* @exception IOException if the document does not exist or the
|
||||||
* name is that of a DirectoryEntry
|
* name is that of a DirectoryEntry
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public DocumentInputStream createDocumentInputStream(
|
public DocumentInputStream createDocumentInputStream(
|
||||||
final String documentName)
|
final String documentName) throws IOException {
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
return getRoot().createDocumentInputStream(documentName);
|
return getRoot().createDocumentInputStream(documentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -902,8 +843,7 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
*
|
*
|
||||||
* @param entry to be removed
|
* @param entry to be removed
|
||||||
*/
|
*/
|
||||||
void remove(EntryNode entry) throws IOException
|
void remove(EntryNode entry) throws IOException {
|
||||||
{
|
|
||||||
// If it's a document, free the blocks
|
// If it's a document, free the blocks
|
||||||
if (entry instanceof DocumentEntry) {
|
if (entry instanceof DocumentEntry) {
|
||||||
NPOIFSDocument doc = new NPOIFSDocument((DocumentProperty)entry.getProperty(), this);
|
NPOIFSDocument doc = new NPOIFSDocument((DocumentProperty)entry.getProperty(), this);
|
||||||
|
@ -922,13 +862,11 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
*
|
*
|
||||||
* @return an array of Object; may not be null, but may be empty
|
* @return an array of Object; may not be null, but may be empty
|
||||||
*/
|
*/
|
||||||
|
public Object [] getViewableArray() {
|
||||||
public Object [] getViewableArray()
|
if (preferArray()) {
|
||||||
{
|
|
||||||
if (preferArray())
|
|
||||||
{
|
|
||||||
return getRoot().getViewableArray();
|
return getRoot().getViewableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Object[ 0 ];
|
return new Object[ 0 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -940,12 +878,11 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
* back end store
|
* back end store
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Iterator<Object> getViewableIterator()
|
public Iterator<Object> getViewableIterator() {
|
||||||
{
|
if (!preferArray()) {
|
||||||
if (!preferArray())
|
|
||||||
{
|
|
||||||
return getRoot().getViewableIterator();
|
return getRoot().getViewableIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Collections.emptyList().iterator();
|
return Collections.emptyList().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -957,8 +894,7 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
* a viewer should call getViewableIterator
|
* a viewer should call getViewableIterator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public boolean preferArray()
|
public boolean preferArray() {
|
||||||
{
|
|
||||||
return getRoot().preferArray();
|
return getRoot().preferArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -969,8 +905,7 @@ public class NPOIFSFileSystem extends BlockStore
|
||||||
* @return short description
|
* @return short description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public String getShortDescription()
|
public String getShortDescription() {
|
||||||
{
|
|
||||||
return "POIFS FileSystem";
|
return "POIFS FileSystem";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,23 +170,22 @@ public class NPOIFSMiniStore extends BlockStore
|
||||||
|
|
||||||
// First up, do we have any spare ones?
|
// First up, do we have any spare ones?
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for(int i=0; i<_sbat_blocks.size(); i++) {
|
for (BATBlock sbat : _sbat_blocks) {
|
||||||
// Check this one
|
// Check this one
|
||||||
BATBlock sbat = _sbat_blocks.get(i);
|
if (sbat.hasFreeSectors()) {
|
||||||
if(sbat.hasFreeSectors()) {
|
// Claim one of them and return it
|
||||||
// Claim one of them and return it
|
for (int j = 0; j < sectorsPerSBAT; j++) {
|
||||||
for(int j=0; j<sectorsPerSBAT; j++) {
|
int sbatValue = sbat.getValueAt(j);
|
||||||
int sbatValue = sbat.getValueAt(j);
|
if (sbatValue == POIFSConstants.UNUSED_BLOCK) {
|
||||||
if(sbatValue == POIFSConstants.UNUSED_BLOCK) {
|
// Bingo
|
||||||
// Bingo
|
return offset + j;
|
||||||
return offset + j;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Move onto the next SBAT
|
// Move onto the next SBAT
|
||||||
offset += sectorsPerSBAT;
|
offset += sectorsPerSBAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here, then there aren't any
|
// If we get here, then there aren't any
|
||||||
// free sectors in any of the SBATs
|
// free sectors in any of the SBATs
|
||||||
|
|
|
@ -384,11 +384,8 @@ public final class OPOIFSDocument implements BATManaged, BlockWritable, POIFSVie
|
||||||
* @return short description
|
* @return short description
|
||||||
*/
|
*/
|
||||||
public String getShortDescription() {
|
public String getShortDescription() {
|
||||||
StringBuffer buffer = new StringBuffer();
|
return "Document: \"" + _property.getName() + "\"" +
|
||||||
|
" size = " + getSize();
|
||||||
buffer.append("Document: \"").append(_property.getName()).append("\"");
|
|
||||||
buffer.append(" size = ").append(getSize());
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********** END begin implementation of POIFSViewable ********** */
|
/* ********** END begin implementation of POIFSViewable ********** */
|
||||||
|
@ -529,8 +526,8 @@ public final class OPOIFSDocument implements BATManaged, BlockWritable, POIFSVie
|
||||||
dstream.writeFiller(countBlocks() * _bigBlockSize.getBigBlockSize(),
|
dstream.writeFiller(countBlocks() * _bigBlockSize.getBigBlockSize(),
|
||||||
DocumentBlock.getFillByte());
|
DocumentBlock.getFillByte());
|
||||||
} else {
|
} else {
|
||||||
for (int k = 0; k < bigBlocks.length; k++) {
|
for (DocumentBlock bigBlock : bigBlocks) {
|
||||||
bigBlocks[k].writeBlocks(stream);
|
bigBlock.writeBlocks(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@ import org.apache.poi.poifs.storage.SmallBlockTableWriter;
|
||||||
import org.apache.poi.util.CloseIgnoringInputStream;
|
import org.apache.poi.util.CloseIgnoringInputStream;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.Removal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>This is the main class of the POIFS system; it manages the entire
|
* <p>This is the main class of the POIFS system; it manages the entire
|
||||||
|
@ -196,38 +195,6 @@ public class OPOIFSFileSystem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks that the supplied InputStream (which MUST
|
|
||||||
* support mark and reset) has a POIFS (OLE2) header at the start of it.
|
|
||||||
* If unsure if your InputStream does support mark / reset,
|
|
||||||
* use {@link FileMagic#prepareToCheckMagic(InputStream)} to wrap it and make
|
|
||||||
* sure to always use that, and not the original!
|
|
||||||
*
|
|
||||||
* After the method call, the InputStream is at the
|
|
||||||
* same position as of the time of entering the method.
|
|
||||||
*
|
|
||||||
* @param inp An InputStream which supports either mark/reset
|
|
||||||
*
|
|
||||||
* @deprecated in 3.17-beta2, use {@link FileMagic#valueOf(InputStream)} == {@link FileMagic#OLE2} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Removal(version="4.0")
|
|
||||||
public static boolean hasPOIFSHeader(InputStream inp) throws IOException {
|
|
||||||
return NPOIFSFileSystem.hasPOIFSHeader(inp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the supplied first 8 bytes of a stream / file
|
|
||||||
* has a POIFS (OLE2) header.
|
|
||||||
*
|
|
||||||
* @deprecated in 3.17-beta2, use {@link FileMagic#valueOf(InputStream)} == {@link FileMagic#OLE2} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Removal(version="4.0")
|
|
||||||
public static boolean hasPOIFSHeader(byte[] header8Bytes) {
|
|
||||||
return NPOIFSFileSystem.hasPOIFSHeader(header8Bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new document to be added to the root directory
|
* Create a new document to be added to the root directory
|
||||||
*
|
*
|
||||||
|
@ -259,7 +226,6 @@ public class OPOIFSFileSystem
|
||||||
*
|
*
|
||||||
* @exception IOException
|
* @exception IOException
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public DocumentEntry createDocument(final String name, final int size,
|
public DocumentEntry createDocument(final String name, final int size,
|
||||||
final POIFSWriterListener writer)
|
final POIFSWriterListener writer)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
@ -325,17 +291,13 @@ public class OPOIFSFileSystem
|
||||||
BATManaged bmo = ( BATManaged ) iter.next();
|
BATManaged bmo = ( BATManaged ) iter.next();
|
||||||
int block_count = bmo.countBlocks();
|
int block_count = bmo.countBlocks();
|
||||||
|
|
||||||
if (block_count != 0)
|
if (block_count != 0) {
|
||||||
{
|
|
||||||
bmo.setStartBlock(bat.allocateSpace(block_count));
|
bmo.setStartBlock(bat.allocateSpace(block_count));
|
||||||
}
|
} /*else {
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
// Either the BATManaged object is empty or its data
|
// Either the BATManaged object is empty or its data
|
||||||
// is composed of SmallBlocks; in either case,
|
// is composed of SmallBlocks; in either case,
|
||||||
// allocating space in the BAT is inappropriate
|
// allocating space in the BAT is inappropriate
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate space for the block allocation table and take its
|
// allocate space for the block allocation table and take its
|
||||||
|
@ -370,10 +332,7 @@ public class OPOIFSFileSystem
|
||||||
writers.add(sbtw);
|
writers.add(sbtw);
|
||||||
writers.add(sbtw.getSBAT());
|
writers.add(sbtw.getSBAT());
|
||||||
writers.add(bat);
|
writers.add(bat);
|
||||||
for (int j = 0; j < xbat_blocks.length; j++)
|
Collections.addAll(writers, xbat_blocks);
|
||||||
{
|
|
||||||
writers.add(xbat_blocks[ j ]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// now, write everything out
|
// now, write everything out
|
||||||
iter = writers.iterator();
|
iter = writers.iterator();
|
||||||
|
@ -393,7 +352,6 @@ public class OPOIFSFileSystem
|
||||||
*
|
*
|
||||||
* @exception IOException
|
* @exception IOException
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static void main(String args[])
|
public static void main(String args[])
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
@ -513,7 +471,7 @@ public class OPOIFSFileSystem
|
||||||
{
|
{
|
||||||
int startBlock = property.getStartBlock();
|
int startBlock = property.getStartBlock();
|
||||||
int size = property.getSize();
|
int size = property.getSize();
|
||||||
OPOIFSDocument document = null;
|
OPOIFSDocument document;
|
||||||
|
|
||||||
if (property.shouldUseSmallBlocks())
|
if (property.shouldUseSmallBlocks())
|
||||||
{
|
{
|
||||||
|
|
|
@ -123,18 +123,11 @@ public class POIFSFileSystem
|
||||||
* @return The created and opened {@link POIFSFileSystem}
|
* @return The created and opened {@link POIFSFileSystem}
|
||||||
*/
|
*/
|
||||||
public static POIFSFileSystem create(File file) throws IOException {
|
public static POIFSFileSystem create(File file) throws IOException {
|
||||||
// TODO Make this nicer!
|
|
||||||
// Create a new empty POIFS in the file
|
// Create a new empty POIFS in the file
|
||||||
POIFSFileSystem tmp = new POIFSFileSystem();
|
try (POIFSFileSystem tmp = new POIFSFileSystem()) {
|
||||||
try {
|
try (OutputStream out = new FileOutputStream(file)) {
|
||||||
OutputStream out = new FileOutputStream(file);
|
|
||||||
try {
|
|
||||||
tmp.writeFilesystem(out);
|
tmp.writeFilesystem(out);
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
tmp.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open it up again backed by the file
|
// Open it up again backed by the file
|
||||||
|
|
|
@ -35,8 +35,8 @@ import org.apache.commons.math3.linear.MatrixUtils;
|
||||||
public abstract class MatrixFunction implements Function{
|
public abstract class MatrixFunction implements Function{
|
||||||
|
|
||||||
public static void checkValues(double[] results) throws EvaluationException {
|
public static void checkValues(double[] results) throws EvaluationException {
|
||||||
for (int idx = 0; idx < results.length; idx++) {
|
for (double result : results) {
|
||||||
if (Double.isNaN(results[idx]) || Double.isInfinite(results[idx])) {
|
if (Double.isNaN(result) || Double.isInfinite(result)) {
|
||||||
throw new EvaluationException(ErrorEval.NUM_ERROR);
|
throw new EvaluationException(ErrorEval.NUM_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,13 +57,13 @@ public abstract class MatrixFunction implements Function{
|
||||||
|
|
||||||
double[][] matrix = new double[rows][cols];
|
double[][] matrix = new double[rows][cols];
|
||||||
|
|
||||||
for (int idx = 0; idx < vector.length; idx++) {
|
for (double aVector : vector) {
|
||||||
if (j < matrix.length) {
|
if (j < matrix.length) {
|
||||||
if (i == matrix[0].length) {
|
if (i == matrix[0].length) {
|
||||||
i = 0;
|
i = 0;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
matrix[j][i++] = vector[idx];
|
matrix[j][i++] = aVector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,9 +80,9 @@ public abstract class MatrixFunction implements Function{
|
||||||
|
|
||||||
double[] vector = new double[matrix.length * matrix[0].length];
|
double[] vector = new double[matrix.length * matrix[0].length];
|
||||||
|
|
||||||
for (int j = 0; j < matrix.length; j++) {
|
for (double[] aMatrix : matrix) {
|
||||||
for (int i = 0; i < matrix[0].length; i++) {
|
for (int i = 0; i < matrix[0].length; i++) {
|
||||||
vector[idx++] = matrix[j][i];
|
vector[idx++] = aMatrix[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return vector;
|
return vector;
|
||||||
|
@ -96,8 +96,8 @@ public abstract class MatrixFunction implements Function{
|
||||||
@Override
|
@Override
|
||||||
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {
|
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {
|
||||||
if (arg0 instanceof AreaEval) {
|
if (arg0 instanceof AreaEval) {
|
||||||
double result[] = null, resultArray[][];
|
double result[], resultArray[][];
|
||||||
int width = 1, height = 1;
|
int width, height;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
double values[] = collectValues(arg0);
|
double values[] = collectValues(arg0);
|
||||||
|
@ -130,7 +130,7 @@ public abstract class MatrixFunction implements Function{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
double result[][] = null;
|
double result[][];
|
||||||
try {
|
try {
|
||||||
double value = NumericFunction.singleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
|
double value = NumericFunction.singleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
|
||||||
double temp[][] = {{value}};
|
double temp[][] = {{value}};
|
||||||
|
@ -157,7 +157,7 @@ public abstract class MatrixFunction implements Function{
|
||||||
@Override
|
@Override
|
||||||
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
|
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
|
||||||
double result[];
|
double result[];
|
||||||
int width = 1, height = 1;
|
int width, height;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
double array0[][], array1[][], resultArray[][];
|
double array0[][], array1[][], resultArray[][];
|
||||||
|
|
|
@ -31,13 +31,10 @@ public class SLCommonUtils {
|
||||||
|
|
||||||
/** a generic way to open a sample slideshow document **/
|
/** a generic way to open a sample slideshow document **/
|
||||||
public static SlideShow<?,?> openSampleSlideshow(String sampleName) throws IOException {
|
public static SlideShow<?,?> openSampleSlideshow(String sampleName) throws IOException {
|
||||||
InputStream is = _slTests.openResourceAsStream(sampleName);
|
try (InputStream is = _slTests.openResourceAsStream(sampleName)) {
|
||||||
try {
|
|
||||||
return SlideShowFactory.create(is);
|
return SlideShowFactory.create(is);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
|
||||||
is.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,8 @@ public class TestOfficeXMLException extends TestCase {
|
||||||
assertContains(e.getMessage(), "You are calling the part of POI that deals with OLE2 Office Documents");
|
assertContains(e.getMessage(), "You are calling the part of POI that deals with OLE2 Office Documents");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void test2003XMLException() throws IOException
|
|
||||||
{
|
public void test2003XMLException() throws IOException {
|
||||||
InputStream in = openSampleStream("SampleSS.xml");
|
InputStream in = openSampleStream("SampleSS.xml");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -87,18 +87,9 @@ public class TestOfficeXMLException extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void confirmIsPOIFS(String sampleFileName, boolean expectedResult) throws IOException {
|
private void confirmIsPOIFS(String sampleFileName, boolean expectedResult) throws IOException {
|
||||||
InputStream in = FileMagic.prepareToCheckMagic(openSampleStream(sampleFileName));
|
try (InputStream in = FileMagic.prepareToCheckMagic(openSampleStream(sampleFileName))) {
|
||||||
try {
|
assertEquals(expectedResult, FileMagic.valueOf(in) == FileMagic.OLE2);
|
||||||
boolean actualResult;
|
}
|
||||||
try {
|
|
||||||
actualResult = POIFSFileSystem.hasPOIFSHeader(in);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
assertEquals(expectedResult, actualResult);
|
|
||||||
} finally {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFileCorruption() throws Exception {
|
public void testFileCorruption() throws Exception {
|
||||||
|
@ -109,11 +100,12 @@ public class TestOfficeXMLException extends TestCase {
|
||||||
|
|
||||||
// detect header
|
// detect header
|
||||||
InputStream in = FileMagic.prepareToCheckMagic(testInput);
|
InputStream in = FileMagic.prepareToCheckMagic(testInput);
|
||||||
assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
|
|
||||||
|
assertFalse(FileMagic.valueOf(in) == FileMagic.OLE2);
|
||||||
|
|
||||||
// check if InputStream is still intact
|
// check if InputStream is still intact
|
||||||
byte[] test = new byte[3];
|
byte[] test = new byte[3];
|
||||||
in.read(test);
|
assertEquals(3, in.read(test));
|
||||||
assertTrue(Arrays.equals(testData, test));
|
assertTrue(Arrays.equals(testData, test));
|
||||||
assertEquals(-1, in.read());
|
assertEquals(-1, in.read());
|
||||||
}
|
}
|
||||||
|
@ -127,11 +119,12 @@ public class TestOfficeXMLException extends TestCase {
|
||||||
|
|
||||||
// detect header
|
// detect header
|
||||||
InputStream in = FileMagic.prepareToCheckMagic(testInput);
|
InputStream in = FileMagic.prepareToCheckMagic(testInput);
|
||||||
assertFalse(OPOIFSFileSystem.hasPOIFSHeader(in));
|
assertFalse(FileMagic.valueOf(in) == FileMagic.OLE2);
|
||||||
|
assertEquals(FileMagic.UNKNOWN, FileMagic.valueOf(in));
|
||||||
|
|
||||||
// check if InputStream is still intact
|
// check if InputStream is still intact
|
||||||
byte[] test = new byte[3];
|
byte[] test = new byte[3];
|
||||||
in.read(test);
|
assertEquals(3, in.read(test));
|
||||||
assertTrue(Arrays.equals(testData, test));
|
assertTrue(Arrays.equals(testData, test));
|
||||||
assertEquals(-1, in.read());
|
assertEquals(-1, in.read());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue