Add some @Overrides suggested by Eclipse, generics and some warnings,
convert some tabs to spaces. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1553466 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3f39b60f53
commit
60ca1a5de4
@ -77,6 +77,7 @@ public abstract class CellRecord extends StandardRecord implements CellValueReco
|
|||||||
return (short) _formatIndex;
|
return (short) _formatIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final String toString() {
|
public final String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String recordName = getRecordName();
|
String recordName = getRecordName();
|
||||||
@ -113,6 +114,7 @@ public abstract class CellRecord extends StandardRecord implements CellValueReco
|
|||||||
*/
|
*/
|
||||||
protected abstract int getValueDataSize();
|
protected abstract int getValueDataSize();
|
||||||
|
|
||||||
|
@Override
|
||||||
public final void serialize(LittleEndianOutput out) {
|
public final void serialize(LittleEndianOutput out) {
|
||||||
out.writeShort(getRow());
|
out.writeShort(getRow());
|
||||||
out.writeShort(getColumn());
|
out.writeShort(getColumn());
|
||||||
@ -120,6 +122,7 @@ public abstract class CellRecord extends StandardRecord implements CellValueReco
|
|||||||
serializeValue(out);
|
serializeValue(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected final int getDataSize() {
|
protected final int getDataSize() {
|
||||||
return 6 + getValueDataSize();
|
return 6 + getValueDataSize();
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,7 @@ public final class ExternalNameRecord extends StandardRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getDataSize(){
|
protected int getDataSize(){
|
||||||
int result = 2 + 4; // short and int
|
int result = 2 + 4; // short and int
|
||||||
result += StringUtil.getEncodedSize(field_4_name) - 1; //size is byte, not short
|
result += StringUtil.getEncodedSize(field_4_name) - 1; //size is byte, not short
|
||||||
@ -141,6 +142,7 @@ public final class ExternalNameRecord extends StandardRecord {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void serialize(LittleEndianOutput out) {
|
public void serialize(LittleEndianOutput out) {
|
||||||
out.writeShort(field_1_option_flag);
|
out.writeShort(field_1_option_flag);
|
||||||
out.writeShort(field_2_ixals);
|
out.writeShort(field_2_ixals);
|
||||||
@ -198,10 +200,12 @@ public final class ExternalNameRecord extends StandardRecord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public short getSid() {
|
public short getSid() {
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append("[EXTERNALNAME]\n");
|
sb.append("[EXTERNALNAME]\n");
|
||||||
|
@ -81,10 +81,12 @@ public final class NumberRecord extends CellRecord {
|
|||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public short getSid() {
|
public short getSid() {
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
NumberRecord rec = new NumberRecord();
|
NumberRecord rec = new NumberRecord();
|
||||||
copyBaseFields(rec);
|
copyBaseFields(rec);
|
||||||
|
@ -49,6 +49,7 @@ public abstract class Record extends RecordBase {
|
|||||||
/**
|
/**
|
||||||
* get a string representation of the record (for biffview/debugging)
|
* get a string representation of the record (for biffview/debugging)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
@ -59,6 +60,7 @@ public abstract class Record extends RecordBase {
|
|||||||
|
|
||||||
public abstract short getSid();
|
public abstract short getSid();
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
if (false) {
|
if (false) {
|
||||||
// TODO - implement clone in a more standardised way
|
// TODO - implement clone in a more standardised way
|
||||||
|
@ -92,10 +92,12 @@ public final class UnknownRecord extends StandardRecord {
|
|||||||
/**
|
/**
|
||||||
* spit the record out AS IS. no interpretation or identification
|
* spit the record out AS IS. no interpretation or identification
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void serialize(LittleEndianOutput out) {
|
public void serialize(LittleEndianOutput out) {
|
||||||
out.write(_rawData);
|
out.write(_rawData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getDataSize() {
|
protected int getDataSize() {
|
||||||
return _rawData.length;
|
return _rawData.length;
|
||||||
}
|
}
|
||||||
@ -103,6 +105,7 @@ public final class UnknownRecord extends StandardRecord {
|
|||||||
/**
|
/**
|
||||||
* print a sort of string representation ([UNKNOWN RECORD] id = x [/UNKNOWN RECORD])
|
* print a sort of string representation ([UNKNOWN RECORD] id = x [/UNKNOWN RECORD])
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String biffName = getBiffName(_sid);
|
String biffName = getBiffName(_sid);
|
||||||
if (biffName == null) {
|
if (biffName == null) {
|
||||||
@ -119,6 +122,7 @@ public final class UnknownRecord extends StandardRecord {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public short getSid() {
|
public short getSid() {
|
||||||
return (short) _sid;
|
return (short) _sid;
|
||||||
}
|
}
|
||||||
@ -279,6 +283,7 @@ public final class UnknownRecord extends StandardRecord {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
// immutable - OK to return this
|
// immutable - OK to return this
|
||||||
return this;
|
return this;
|
||||||
|
@ -19,9 +19,12 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.dev;
|
package org.apache.poi.poifs.dev;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
|
import java.io.LineNumberReader;
|
||||||
import java.util.*;
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains methods used to inspect POIFSViewable objects
|
* This class contains methods used to inspect POIFSViewable objects
|
||||||
@ -47,12 +50,12 @@ public class POIFSViewEngine
|
|||||||
* @return a List of Strings holding the content
|
* @return a List of Strings holding the content
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static List inspectViewable(final Object viewable,
|
public static List<String> inspectViewable(final Object viewable,
|
||||||
final boolean drilldown,
|
final boolean drilldown,
|
||||||
final int indentLevel,
|
final int indentLevel,
|
||||||
final String indentString)
|
final String indentString)
|
||||||
{
|
{
|
||||||
List objects = new ArrayList();
|
List<String> objects = new ArrayList<String>();
|
||||||
|
|
||||||
if (viewable instanceof POIFSViewable)
|
if (viewable instanceof POIFSViewable)
|
||||||
{
|
{
|
||||||
@ -75,7 +78,7 @@ public class POIFSViewEngine
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Iterator iter = inspected.getViewableIterator();
|
Iterator<Object> iter = inspected.getViewableIterator();
|
||||||
|
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
|
@ -54,8 +54,7 @@ public interface POIFSViewable
|
|||||||
* @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
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public Iterator<Object> getViewableIterator();
|
||||||
public Iterator getViewableIterator();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Give viewers a hint as to whether to call getViewableArray or
|
* Give viewers a hint as to whether to call getViewableArray or
|
||||||
|
@ -19,9 +19,10 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.dev;
|
package org.apache.poi.poifs.dev;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
|
|
||||||
@ -76,9 +77,9 @@ public class POIFSViewer
|
|||||||
{
|
{
|
||||||
POIFSViewable fs =
|
POIFSViewable fs =
|
||||||
new POIFSFileSystem(new FileInputStream(filename));
|
new POIFSFileSystem(new FileInputStream(filename));
|
||||||
List strings = POIFSViewEngine.inspectViewable(fs, true,
|
List<String> strings = POIFSViewEngine.inspectViewable(fs, true,
|
||||||
0, " ");
|
0, " ");
|
||||||
Iterator iter = strings.iterator();
|
Iterator<String> iter = strings.iterator();
|
||||||
|
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
|
@ -521,10 +521,9 @@ 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
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
public Iterator<Object> getViewableIterator()
|
||||||
public Iterator getViewableIterator()
|
|
||||||
{
|
{
|
||||||
List components = new ArrayList();
|
List<Object> components = new ArrayList<Object>();
|
||||||
|
|
||||||
components.add(getProperty());
|
components.add(getProperty());
|
||||||
Iterator<Entry> iter = _entries.iterator();
|
Iterator<Entry> iter = _entries.iterator();
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.filesystem;
|
package org.apache.poi.poifs.filesystem;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.poifs.dev.POIFSViewable;
|
import org.apache.poi.poifs.dev.POIFSViewable;
|
||||||
import org.apache.poi.poifs.property.DocumentProperty;
|
import org.apache.poi.poifs.property.DocumentProperty;
|
||||||
@ -85,6 +87,7 @@ public class DocumentNode
|
|||||||
* @return true if the Entry is a DocumentEntry, else false
|
* @return true if the Entry is a DocumentEntry, else false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isDocumentEntry()
|
public boolean isDocumentEntry()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@ -101,6 +104,7 @@ public class DocumentNode
|
|||||||
* false
|
* false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
protected boolean isDeleteOK()
|
protected boolean isDeleteOK()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@ -129,9 +133,9 @@ public class DocumentNode
|
|||||||
* back end store
|
* back end store
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Iterator getViewableIterator()
|
public Iterator<Object> getViewableIterator()
|
||||||
{
|
{
|
||||||
List components = new ArrayList();
|
List<Object> components = new ArrayList<Object>();
|
||||||
|
|
||||||
components.add(getProperty());
|
components.add(getProperty());
|
||||||
components.add(_document);
|
components.add(_document);
|
||||||
|
@ -168,8 +168,8 @@ public final class NPOIFSDocument implements POIFSViewable {
|
|||||||
* @return an Iterator; may not be null, but may have an empty back end
|
* @return an Iterator; may not be null, but may have an empty back end
|
||||||
* store
|
* store
|
||||||
*/
|
*/
|
||||||
public Iterator getViewableIterator() {
|
public Iterator<Object> getViewableIterator() {
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptyList().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,17 +46,15 @@ import org.apache.poi.poifs.nio.FileBackedDataSource;
|
|||||||
import org.apache.poi.poifs.property.DirectoryProperty;
|
import org.apache.poi.poifs.property.DirectoryProperty;
|
||||||
import org.apache.poi.poifs.property.NPropertyTable;
|
import org.apache.poi.poifs.property.NPropertyTable;
|
||||||
import org.apache.poi.poifs.storage.BATBlock;
|
import org.apache.poi.poifs.storage.BATBlock;
|
||||||
|
import org.apache.poi.poifs.storage.BATBlock.BATBlockAndIndex;
|
||||||
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
|
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
|
||||||
import org.apache.poi.poifs.storage.BlockAllocationTableWriter;
|
import org.apache.poi.poifs.storage.BlockAllocationTableWriter;
|
||||||
import org.apache.poi.poifs.storage.HeaderBlock;
|
import org.apache.poi.poifs.storage.HeaderBlock;
|
||||||
import org.apache.poi.poifs.storage.HeaderBlockConstants;
|
import org.apache.poi.poifs.storage.HeaderBlockConstants;
|
||||||
import org.apache.poi.poifs.storage.HeaderBlockWriter;
|
import org.apache.poi.poifs.storage.HeaderBlockWriter;
|
||||||
import org.apache.poi.poifs.storage.BATBlock.BATBlockAndIndex;
|
|
||||||
import org.apache.poi.util.CloseIgnoringInputStream;
|
import org.apache.poi.util.CloseIgnoringInputStream;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
import org.apache.poi.util.LongField;
|
import org.apache.poi.util.LongField;
|
||||||
import org.apache.poi.util.POILogFactory;
|
|
||||||
import org.apache.poi.util.POILogger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the main class of the POIFS system; it manages the entire
|
* This is the main class of the POIFS system; it manages the entire
|
||||||
@ -67,8 +65,8 @@ import org.apache.poi.util.POILogger;
|
|||||||
public class NPOIFSFileSystem extends BlockStore
|
public class NPOIFSFileSystem extends BlockStore
|
||||||
implements POIFSViewable, Closeable
|
implements POIFSViewable, Closeable
|
||||||
{
|
{
|
||||||
private static final POILogger _logger =
|
// private static final POILogger _logger =
|
||||||
POILogFactory.getLogger(NPOIFSFileSystem.class);
|
// POILogFactory.getLogger(NPOIFSFileSystem.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method for clients that want to avoid the auto-close behaviour of the constructor.
|
* Convenience method for clients that want to avoid the auto-close behaviour of the constructor.
|
||||||
@ -157,6 +155,7 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
*
|
*
|
||||||
* @exception IOException on errors reading, or on invalid data
|
* @exception IOException on errors reading, or on invalid data
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public NPOIFSFileSystem(File file, boolean readOnly)
|
public NPOIFSFileSystem(File file, boolean readOnly)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -420,6 +419,7 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
/**
|
/**
|
||||||
* Load the block at the given offset.
|
* Load the block at the given offset.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected ByteBuffer getBlockAt(final int offset) throws IOException {
|
protected ByteBuffer getBlockAt(final int offset) throws IOException {
|
||||||
// The header block doesn't count, so add one
|
// The header block doesn't count, so add one
|
||||||
long startAt = (offset+1) * bigBlockSize.getBigBlockSize();
|
long startAt = (offset+1) * bigBlockSize.getBigBlockSize();
|
||||||
@ -430,6 +430,7 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
* Load the block at the given offset,
|
* Load the block at the given offset,
|
||||||
* extending the file if needed
|
* extending the file if needed
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected ByteBuffer createBlockIfNeeded(final int offset) throws IOException {
|
protected ByteBuffer createBlockIfNeeded(final int offset) throws IOException {
|
||||||
try {
|
try {
|
||||||
return getBlockAt(offset);
|
return getBlockAt(offset);
|
||||||
@ -448,6 +449,7 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
* Returns the BATBlock that handles the specified offset,
|
* Returns the BATBlock that handles the specified offset,
|
||||||
* and the relative index within it
|
* and the relative index within it
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected BATBlockAndIndex getBATBlockAndIndex(final int offset) {
|
protected BATBlockAndIndex getBATBlockAndIndex(final int offset) {
|
||||||
return BATBlock.getBATBlockAndIndex(
|
return BATBlock.getBATBlockAndIndex(
|
||||||
offset, _header, _bat_blocks
|
offset, _header, _bat_blocks
|
||||||
@ -457,6 +459,7 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
/**
|
/**
|
||||||
* Works out what block follows the specified one.
|
* Works out what block follows the specified one.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected int getNextBlock(final int offset) {
|
protected int getNextBlock(final int offset) {
|
||||||
BATBlockAndIndex bai = getBATBlockAndIndex(offset);
|
BATBlockAndIndex bai = getBATBlockAndIndex(offset);
|
||||||
return bai.getBlock().getValueAt( bai.getIndex() );
|
return bai.getBlock().getValueAt( bai.getIndex() );
|
||||||
@ -465,6 +468,7 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
/**
|
/**
|
||||||
* Changes the record of what block follows the specified one.
|
* Changes the record of what block follows the specified one.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void setNextBlock(final int offset, final int nextBlock) {
|
protected void setNextBlock(final int offset, final int nextBlock) {
|
||||||
BATBlockAndIndex bai = getBATBlockAndIndex(offset);
|
BATBlockAndIndex bai = getBATBlockAndIndex(offset);
|
||||||
bai.getBlock().setValueAt(
|
bai.getBlock().setValueAt(
|
||||||
@ -477,6 +481,7 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
* This method will extend the file if needed, and if doing
|
* This method will extend the file if needed, and if doing
|
||||||
* so, allocate new FAT blocks to address the extra space.
|
* so, allocate new FAT blocks to address the extra space.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected int getFreeBlock() throws IOException {
|
protected int getFreeBlock() throws IOException {
|
||||||
// First up, do we have any spare ones?
|
// First up, do we have any spare ones?
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@ -743,12 +748,22 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
FileInputStream istream = new FileInputStream(args[ 0 ]);
|
FileInputStream istream = new FileInputStream(args[ 0 ]);
|
||||||
|
try {
|
||||||
FileOutputStream ostream = new FileOutputStream(args[ 1 ]);
|
FileOutputStream ostream = new FileOutputStream(args[ 1 ]);
|
||||||
|
try {
|
||||||
new NPOIFSFileSystem(istream).writeFilesystem(ostream);
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(istream);
|
||||||
istream.close();
|
try {
|
||||||
|
fs.writeFilesystem(ostream);
|
||||||
|
} finally {
|
||||||
|
fs.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
ostream.close();
|
ostream.close();
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
istream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the root entry
|
* Get the root entry
|
||||||
@ -818,13 +833,13 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
* back end store
|
* back end store
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Iterator getViewableIterator()
|
public Iterator<Object> getViewableIterator()
|
||||||
{
|
{
|
||||||
if (!preferArray())
|
if (!preferArray())
|
||||||
{
|
{
|
||||||
return (( POIFSViewable ) getRoot()).getViewableIterator();
|
return (( POIFSViewable ) getRoot()).getViewableIterator();
|
||||||
}
|
}
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptyList().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -860,12 +875,15 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
public int getBigBlockSize() {
|
public int getBigBlockSize() {
|
||||||
return bigBlockSize.getBigBlockSize();
|
return bigBlockSize.getBigBlockSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The Big Block size, normally 512 bytes, sometimes 4096 bytes
|
* @return The Big Block size, normally 512 bytes, sometimes 4096 bytes
|
||||||
*/
|
*/
|
||||||
public POIFSBigBlockSize getBigBlockSizeDetails() {
|
public POIFSBigBlockSize getBigBlockSizeDetails() {
|
||||||
return bigBlockSize;
|
return bigBlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getBlockStoreBlockSize() {
|
protected int getBlockStoreBlockSize() {
|
||||||
return getBigBlockSize();
|
return getBigBlockSize();
|
||||||
}
|
}
|
||||||
|
@ -376,8 +376,8 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
|
|||||||
* @return an Iterator; may not be null, but may have an empty back end
|
* @return an Iterator; may not be null, but may have an empty back end
|
||||||
* store
|
* store
|
||||||
*/
|
*/
|
||||||
public Iterator getViewableIterator() {
|
public Iterator<Object> getViewableIterator() {
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptyList().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,17 +37,7 @@ import org.apache.poi.poifs.dev.POIFSViewable;
|
|||||||
import org.apache.poi.poifs.property.DirectoryProperty;
|
import org.apache.poi.poifs.property.DirectoryProperty;
|
||||||
import org.apache.poi.poifs.property.Property;
|
import org.apache.poi.poifs.property.Property;
|
||||||
import org.apache.poi.poifs.property.PropertyTable;
|
import org.apache.poi.poifs.property.PropertyTable;
|
||||||
import org.apache.poi.poifs.storage.BATBlock;
|
import org.apache.poi.poifs.storage.*;
|
||||||
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
|
|
||||||
import org.apache.poi.poifs.storage.BlockAllocationTableWriter;
|
|
||||||
import org.apache.poi.poifs.storage.BlockList;
|
|
||||||
import org.apache.poi.poifs.storage.BlockWritable;
|
|
||||||
import org.apache.poi.poifs.storage.HeaderBlockConstants;
|
|
||||||
import org.apache.poi.poifs.storage.HeaderBlock;
|
|
||||||
import org.apache.poi.poifs.storage.HeaderBlockWriter;
|
|
||||||
import org.apache.poi.poifs.storage.RawDataBlockList;
|
|
||||||
import org.apache.poi.poifs.storage.SmallBlockTableReader;
|
|
||||||
import org.apache.poi.poifs.storage.SmallBlockTableWriter;
|
|
||||||
import org.apache.poi.util.CloseIgnoringInputStream;
|
import org.apache.poi.util.CloseIgnoringInputStream;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
import org.apache.poi.util.LongField;
|
import org.apache.poi.util.LongField;
|
||||||
@ -75,7 +65,7 @@ public class POIFSFileSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PropertyTable _property_table;
|
private PropertyTable _property_table;
|
||||||
private List _documents;
|
private List<POIFSViewable> _documents;
|
||||||
private DirectoryNode _root;
|
private DirectoryNode _root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +82,7 @@ public class POIFSFileSystem
|
|||||||
{
|
{
|
||||||
HeaderBlock header_block = new HeaderBlock(bigBlockSize);
|
HeaderBlock header_block = new HeaderBlock(bigBlockSize);
|
||||||
_property_table = new PropertyTable(header_block);
|
_property_table = new PropertyTable(header_block);
|
||||||
_documents = new ArrayList();
|
_documents = new ArrayList<POIFSViewable>();
|
||||||
_root = null;
|
_root = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +300,7 @@ public class POIFSFileSystem
|
|||||||
|
|
||||||
// create a list of BATManaged objects: the documents plus the
|
// create a list of BATManaged objects: the documents plus the
|
||||||
// property table and the small block table
|
// property table and the small block table
|
||||||
List bm_objects = new ArrayList();
|
List<Object> bm_objects = new ArrayList<Object>();
|
||||||
|
|
||||||
bm_objects.addAll(_documents);
|
bm_objects.addAll(_documents);
|
||||||
bm_objects.add(_property_table);
|
bm_objects.add(_property_table);
|
||||||
@ -319,7 +309,7 @@ public class POIFSFileSystem
|
|||||||
|
|
||||||
// walk the list, allocating space for each and assigning each
|
// walk the list, allocating space for each and assigning each
|
||||||
// a starting block number
|
// a starting block number
|
||||||
Iterator iter = bm_objects.iterator();
|
Iterator<Object> iter = bm_objects.iterator();
|
||||||
|
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
@ -363,7 +353,7 @@ public class POIFSFileSystem
|
|||||||
// property table, the small block store, the small block
|
// property table, the small block store, the small block
|
||||||
// allocation table, the block allocation table, and the
|
// allocation table, the block allocation table, and the
|
||||||
// extended block allocation table blocks)
|
// extended block allocation table blocks)
|
||||||
List writers = new ArrayList();
|
List<Object> writers = new ArrayList<Object>();
|
||||||
|
|
||||||
writers.add(header_block_writer);
|
writers.add(header_block_writer);
|
||||||
writers.addAll(_documents);
|
writers.addAll(_documents);
|
||||||
@ -485,14 +475,14 @@ public class POIFSFileSystem
|
|||||||
|
|
||||||
private void processProperties(final BlockList small_blocks,
|
private void processProperties(final BlockList small_blocks,
|
||||||
final BlockList big_blocks,
|
final BlockList big_blocks,
|
||||||
final Iterator properties,
|
final Iterator<Property> properties,
|
||||||
final DirectoryNode dir,
|
final DirectoryNode dir,
|
||||||
final int headerPropertiesStartAt)
|
final int headerPropertiesStartAt)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
while (properties.hasNext())
|
while (properties.hasNext())
|
||||||
{
|
{
|
||||||
Property property = ( Property ) properties.next();
|
Property property = properties.next();
|
||||||
String name = property.getName();
|
String name = property.getName();
|
||||||
DirectoryNode parent = (dir == null)
|
DirectoryNode parent = (dir == null)
|
||||||
? (( DirectoryNode ) getRoot())
|
? (( DirectoryNode ) getRoot())
|
||||||
@ -561,13 +551,13 @@ public class POIFSFileSystem
|
|||||||
* back end store
|
* back end store
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Iterator getViewableIterator()
|
public Iterator<Object> getViewableIterator()
|
||||||
{
|
{
|
||||||
if (!preferArray())
|
if (!preferArray())
|
||||||
{
|
{
|
||||||
return (( POIFSViewable ) getRoot()).getViewableIterator();
|
return (( POIFSViewable ) getRoot()).getViewableIterator();
|
||||||
}
|
}
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptyList().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +36,7 @@ public class ByteArrayBackedDataSource extends DataSource {
|
|||||||
this(data, data.length);
|
this(data, data.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ByteBuffer read(int length, long position) {
|
public ByteBuffer read(int length, long position) {
|
||||||
if(position >= size) {
|
if(position >= size) {
|
||||||
throw new IndexOutOfBoundsException(
|
throw new IndexOutOfBoundsException(
|
||||||
@ -48,6 +49,7 @@ public class ByteArrayBackedDataSource extends DataSource {
|
|||||||
return ByteBuffer.wrap(buffer, (int)position, toRead);
|
return ByteBuffer.wrap(buffer, (int)position, toRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void write(ByteBuffer src, long position) {
|
public void write(ByteBuffer src, long position) {
|
||||||
// Extend if needed
|
// Extend if needed
|
||||||
long endPosition = position + src.capacity();
|
long endPosition = position + src.capacity();
|
||||||
@ -79,14 +81,17 @@ public class ByteArrayBackedDataSource extends DataSource {
|
|||||||
buffer = nb;
|
buffer = nb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void copyTo(OutputStream stream) throws IOException {
|
public void copyTo(OutputStream stream) throws IOException {
|
||||||
stream.write(buffer, 0, (int)size);
|
stream.write(buffer, 0, (int)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long size() {
|
public long size() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
buffer = null;
|
buffer = null;
|
||||||
size = -1;
|
size = -1;
|
||||||
|
@ -35,16 +35,19 @@ import org.apache.poi.util.IOUtils;
|
|||||||
public class FileBackedDataSource extends DataSource {
|
public class FileBackedDataSource extends DataSource {
|
||||||
private FileChannel channel;
|
private FileChannel channel;
|
||||||
|
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public FileBackedDataSource(File file) throws FileNotFoundException {
|
public FileBackedDataSource(File file) throws FileNotFoundException {
|
||||||
if(!file.exists()) {
|
if(!file.exists()) {
|
||||||
throw new FileNotFoundException(file.toString());
|
throw new FileNotFoundException(file.toString());
|
||||||
}
|
}
|
||||||
this.channel = (new RandomAccessFile(file, "r")).getChannel();
|
this.channel = (new RandomAccessFile(file, "r")).getChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileBackedDataSource(FileChannel channel) {
|
public FileBackedDataSource(FileChannel channel) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ByteBuffer read(int length, long position) throws IOException {
|
public ByteBuffer read(int length, long position) throws IOException {
|
||||||
if(position >= size()) {
|
if(position >= size()) {
|
||||||
throw new IllegalArgumentException("Position " + position + " past the end of the file");
|
throw new IllegalArgumentException("Position " + position + " past the end of the file");
|
||||||
@ -67,10 +70,12 @@ public class FileBackedDataSource extends DataSource {
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void write(ByteBuffer src, long position) throws IOException {
|
public void write(ByteBuffer src, long position) throws IOException {
|
||||||
channel.write(src, position);
|
channel.write(src, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void copyTo(OutputStream stream) throws IOException {
|
public void copyTo(OutputStream stream) throws IOException {
|
||||||
// Wrap the OutputSteam as a channel
|
// Wrap the OutputSteam as a channel
|
||||||
WritableByteChannel out = Channels.newChannel(stream);
|
WritableByteChannel out = Channels.newChannel(stream);
|
||||||
@ -78,10 +83,12 @@ public class FileBackedDataSource extends DataSource {
|
|||||||
channel.transferTo(0, channel.size(), out);
|
channel.transferTo(0, channel.size(), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long size() throws IOException {
|
public long size() throws IOException {
|
||||||
return channel.size();
|
return channel.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
channel.close();
|
channel.close();
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,13 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.property;
|
package org.apache.poi.poifs.property;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.poi.hpsf.ClassID;
|
import org.apache.poi.hpsf.ClassID;
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.poifs.dev.POIFSViewable;
|
import org.apache.poi.poifs.dev.POIFSViewable;
|
||||||
import org.apache.poi.util.ByteField;
|
import org.apache.poi.util.ByteField;
|
||||||
@ -498,9 +499,9 @@ public abstract class Property implements Child, POIFSViewable {
|
|||||||
* @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 getViewableIterator()
|
public Iterator<Object> getViewableIterator()
|
||||||
{
|
{
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptyList().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,12 +42,14 @@ public final class ExpPtg extends ControlPtg {
|
|||||||
this.field_2_first_col = firstCol;
|
this.field_2_first_col = firstCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void write(LittleEndianOutput out) {
|
public void write(LittleEndianOutput out) {
|
||||||
out.writeByte(sid + getPtgClass());
|
out.writeByte(sid + getPtgClass());
|
||||||
out.writeShort(field_1_first_row);
|
out.writeShort(field_1_first_row);
|
||||||
out.writeShort(field_2_first_col);
|
out.writeShort(field_2_first_col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return SIZE;
|
return SIZE;
|
||||||
}
|
}
|
||||||
@ -60,10 +62,12 @@ public final class ExpPtg extends ControlPtg {
|
|||||||
return field_2_first_col;
|
return field_2_first_col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toFormulaString() {
|
public String toFormulaString() {
|
||||||
throw new RuntimeException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't");
|
throw new RuntimeException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buffer = new StringBuffer("[Array Formula or Shared Formula]\n");
|
StringBuffer buffer = new StringBuffer("[Array Formula or Shared Formula]\n");
|
||||||
buffer.append("row = ").append(getRow()).append("\n");
|
buffer.append("row = ").append(getRow()).append("\n");
|
||||||
|
@ -245,6 +245,7 @@ public abstract class Ptg {
|
|||||||
* This helps get rid of gratuitous diffs when comparing two dumps
|
* This helps get rid of gratuitous diffs when comparing two dumps
|
||||||
* Subclasses may output more relevant information by overriding this method
|
* Subclasses may output more relevant information by overriding this method
|
||||||
**/
|
**/
|
||||||
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return this.getClass().toString();
|
return this.getClass().toString();
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@ public final class TestAbortableListener extends TestCase {
|
|||||||
countSeen = 0;
|
countSeen = 0;
|
||||||
lastRecordSeen = null;
|
lastRecordSeen = null;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public short abortableProcessRecord(Record record) {
|
public short abortableProcessRecord(Record record) {
|
||||||
countSeen++;
|
countSeen++;
|
||||||
lastRecordSeen = record;
|
lastRecordSeen = record;
|
||||||
|
@ -549,7 +549,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
|
|||||||
// Open the two filesystems
|
// Open the two filesystems
|
||||||
DirectoryNode[] files = new DirectoryNode[2];
|
DirectoryNode[] files = new DirectoryNode[2];
|
||||||
files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"))).getRoot();
|
files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"))).getRoot();
|
||||||
files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("Simple.xls"))).getRoot();
|
NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("Simple.xls"));
|
||||||
|
try {
|
||||||
|
files[1] = npoifsFileSystem.getRoot();
|
||||||
|
|
||||||
// Open without preserving nodes
|
// Open without preserving nodes
|
||||||
for(DirectoryNode dir : files) {
|
for(DirectoryNode dir : files) {
|
||||||
@ -566,13 +568,18 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
|
|||||||
HSSFCell cell = sheet.getRow(0).getCell(0);
|
HSSFCell cell = sheet.getRow(0).getCell(0);
|
||||||
assertEquals("replaceMe", cell .getRichStringCellValue().getString());
|
assertEquals("replaceMe", cell .getRichStringCellValue().getString());
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
npoifsFileSystem.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWordDocEmbeddedInXls() throws IOException {
|
public void testWordDocEmbeddedInXls() throws IOException {
|
||||||
// Open the two filesystems
|
// Open the two filesystems
|
||||||
DirectoryNode[] files = new DirectoryNode[2];
|
DirectoryNode[] files = new DirectoryNode[2];
|
||||||
files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"))).getRoot();
|
files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"))).getRoot();
|
||||||
files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithEmbeddedObjects.xls"))).getRoot();
|
NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithEmbeddedObjects.xls"));
|
||||||
|
try {
|
||||||
|
files[1] = npoifsFileSystem.getRoot();
|
||||||
|
|
||||||
// Check the embedded parts
|
// Check the embedded parts
|
||||||
for(DirectoryNode root : files) {
|
for(DirectoryNode root : files) {
|
||||||
@ -593,6 +600,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
|
|||||||
}
|
}
|
||||||
assertTrue(found);
|
assertTrue(found);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
npoifsFileSystem.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user