You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/12/30 03:35:11 UTC
svn commit: r1053791 [2/18] - in /poi/branches/NIO_32_BRANCH: ./
src/contrib/src/org/apache/poi/contrib/poibrowser/ src/java/org/apache/poi/
src/java/org/apache/poi/hpsf/ src/java/org/apache/poi/hpsf/extractor/
src/java/org/apache/poi/hssf/record/ src/...
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/SummaryInformation.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/SummaryInformation.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/SummaryInformation.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/SummaryInformation.java Thu Dec 30 02:35:06 2010
@@ -24,15 +24,12 @@ import org.apache.poi.hpsf.wellknown.Pro
/**
* <p>Convenience class representing a Summary Information stream in a
* Microsoft Office document.</p>
- *
+ *
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
* @see DocumentSummaryInformation
- * @version $Id$
- * @since 2002-02-09
*/
-public class SummaryInformation extends SpecialPropertySet
-{
+public final class SummaryInformation extends SpecialPropertySet {
/**
* <p>The document name a summary information stream usually has in a POIFS
@@ -48,7 +45,7 @@ public class SummaryInformation extends
/**
* <p>Creates a {@link SummaryInformation} from a given {@link
* PropertySet}.</p>
- *
+ *
* @param ps A property set which should be created from a summary
* information stream.
* @throws UnexpectedPropertySetTypeException if <var>ps</var> does not
@@ -67,7 +64,7 @@ public class SummaryInformation extends
/**
* <p>Returns the title (or <code>null</code>).</p>
- *
+ *
* @return The title or <code>null</code>
*/
public String getTitle()
@@ -79,7 +76,7 @@ public class SummaryInformation extends
/**
* <p>Sets the title.</p>
- *
+ *
* @param title The title to set.
*/
public void setTitle(final String title)
@@ -103,7 +100,7 @@ public class SummaryInformation extends
/**
* <p>Returns the subject (or <code>null</code>).</p>
- *
+ *
* @return The subject or <code>null</code>
*/
public String getSubject()
@@ -115,7 +112,7 @@ public class SummaryInformation extends
/**
* <p>Sets the subject.</p>
- *
+ *
* @param subject The subject to set.
*/
public void setSubject(final String subject)
@@ -139,7 +136,7 @@ public class SummaryInformation extends
/**
* <p>Returns the author (or <code>null</code>).</p>
- *
+ *
* @return The author or <code>null</code>
*/
public String getAuthor()
@@ -151,7 +148,7 @@ public class SummaryInformation extends
/**
* <p>Sets the author.</p>
- *
+ *
* @param author The author to set.
*/
public void setAuthor(final String author)
@@ -175,7 +172,7 @@ public class SummaryInformation extends
/**
* <p>Returns the keywords (or <code>null</code>).</p>
- *
+ *
* @return The keywords or <code>null</code>
*/
public String getKeywords()
@@ -187,7 +184,7 @@ public class SummaryInformation extends
/**
* <p>Sets the keywords.</p>
- *
+ *
* @param keywords The keywords to set.
*/
public void setKeywords(final String keywords)
@@ -211,7 +208,7 @@ public class SummaryInformation extends
/**
* <p>Returns the comments (or <code>null</code>).</p>
- *
+ *
* @return The comments or <code>null</code>
*/
public String getComments()
@@ -223,7 +220,7 @@ public class SummaryInformation extends
/**
* <p>Sets the comments.</p>
- *
+ *
* @param comments The comments to set.
*/
public void setComments(final String comments)
@@ -247,7 +244,7 @@ public class SummaryInformation extends
/**
* <p>Returns the template (or <code>null</code>).</p>
- *
+ *
* @return The template or <code>null</code>
*/
public String getTemplate()
@@ -259,7 +256,7 @@ public class SummaryInformation extends
/**
* <p>Sets the template.</p>
- *
+ *
* @param template The template to set.
*/
public void setTemplate(final String template)
@@ -283,7 +280,7 @@ public class SummaryInformation extends
/**
* <p>Returns the last author (or <code>null</code>).</p>
- *
+ *
* @return The last author or <code>null</code>
*/
public String getLastAuthor()
@@ -295,7 +292,7 @@ public class SummaryInformation extends
/**
* <p>Sets the last author.</p>
- *
+ *
* @param lastAuthor The last author to set.
*/
public void setLastAuthor(final String lastAuthor)
@@ -319,7 +316,7 @@ public class SummaryInformation extends
/**
* <p>Returns the revision number (or <code>null</code>). </p>
- *
+ *
* @return The revision number or <code>null</code>
*/
public String getRevNumber()
@@ -331,7 +328,7 @@ public class SummaryInformation extends
/**
* <p>Sets the revision number.</p>
- *
+ *
* @param revNumber The revision number to set.
*/
public void setRevNumber(final String revNumber)
@@ -356,24 +353,24 @@ public class SummaryInformation extends
/**
* <p>Returns the total time spent in editing the document (or
* <code>0</code>).</p>
- *
+ *
* @return The total time spent in editing the document or 0 if the {@link
* SummaryInformation} does not contain this information.
*/
public long getEditTime()
{
final Date d = (Date) getProperty(PropertyIDMap.PID_EDITTIME);
- if (d == null)
+ if (d == null) {
return 0;
- else
- return Util.dateToFileTime(d);
+ }
+ return Util.dateToFileTime(d);
}
/**
* <p>Sets the total time spent in editing the document.</p>
- *
+ *
* @param time The time to set.
*/
public void setEditTime(final long time)
@@ -398,7 +395,7 @@ public class SummaryInformation extends
/**
* <p>Returns the last printed time (or <code>null</code>).</p>
- *
+ *
* @return The last printed time or <code>null</code>
*/
public Date getLastPrinted()
@@ -410,7 +407,7 @@ public class SummaryInformation extends
/**
* <p>Sets the lastPrinted.</p>
- *
+ *
* @param lastPrinted The lastPrinted to set.
*/
public void setLastPrinted(final Date lastPrinted)
@@ -435,7 +432,7 @@ public class SummaryInformation extends
/**
* <p>Returns the creation time (or <code>null</code>).</p>
- *
+ *
* @return The creation time or <code>null</code>
*/
public Date getCreateDateTime()
@@ -447,7 +444,7 @@ public class SummaryInformation extends
/**
* <p>Sets the creation time.</p>
- *
+ *
* @param createDateTime The creation time to set.
*/
public void setCreateDateTime(final Date createDateTime)
@@ -472,7 +469,7 @@ public class SummaryInformation extends
/**
* <p>Returns the last save time (or <code>null</code>).</p>
- *
+ *
* @return The last save time or <code>null</code>
*/
public Date getLastSaveDateTime()
@@ -484,7 +481,7 @@ public class SummaryInformation extends
/**
* <p>Sets the total time spent in editing the document.</p>
- *
+ *
* @param time The time to set.
*/
public void setLastSaveDateTime(final Date time)
@@ -511,7 +508,7 @@ public class SummaryInformation extends
/**
* <p>Returns the page count or 0 if the {@link SummaryInformation} does
* not contain a page count.</p>
- *
+ *
* @return The page count or 0 if the {@link SummaryInformation} does not
* contain a page count.
*/
@@ -524,7 +521,7 @@ public class SummaryInformation extends
/**
* <p>Sets the page count.</p>
- *
+ *
* @param pageCount The page count to set.
*/
public void setPageCount(final int pageCount)
@@ -549,7 +546,7 @@ public class SummaryInformation extends
/**
* <p>Returns the word count or 0 if the {@link SummaryInformation} does
* not contain a word count.</p>
- *
+ *
* @return The word count or <code>null</code>
*/
public int getWordCount()
@@ -561,7 +558,7 @@ public class SummaryInformation extends
/**
* <p>Sets the word count.</p>
- *
+ *
* @param wordCount The word count to set.
*/
public void setWordCount(final int wordCount)
@@ -586,7 +583,7 @@ public class SummaryInformation extends
/**
* <p>Returns the character count or 0 if the {@link SummaryInformation}
* does not contain a char count.</p>
- *
+ *
* @return The character count or <code>null</code>
*/
public int getCharCount()
@@ -598,7 +595,7 @@ public class SummaryInformation extends
/**
* <p>Sets the character count.</p>
- *
+ *
* @param charCount The character count to set.
*/
public void setCharCount(final int charCount)
@@ -624,12 +621,12 @@ public class SummaryInformation extends
* <p>Returns the thumbnail (or <code>null</code>) <strong>when this
* method is implemented. Please note that the return type is likely to
* change!</strong></p>
- *
+ *
* <p><strong>Hint to developers:</strong> Drew Varner <Drew.Varner
* -at- sc.edu> said that this is an image in WMF or Clipboard (BMP?)
* format. However, we won't do any conversion into any image type but
* instead just return a byte array.</p>
- *
+ *
* @return The thumbnail or <code>null</code>
*/
public byte[] getThumbnail()
@@ -641,7 +638,7 @@ public class SummaryInformation extends
/**
* <p>Sets the thumbnail.</p>
- *
+ *
* @param thumbnail The thumbnail to set.
*/
public void setThumbnail(final byte[] thumbnail)
@@ -666,7 +663,7 @@ public class SummaryInformation extends
/**
* <p>Returns the application name (or <code>null</code>).</p>
- *
+ *
* @return The application name or <code>null</code>
*/
public String getApplicationName()
@@ -678,7 +675,7 @@ public class SummaryInformation extends
/**
* <p>Sets the application name.</p>
- *
+ *
* @param applicationName The application name to set.
*/
public void setApplicationName(final String applicationName)
@@ -702,24 +699,24 @@ public class SummaryInformation extends
/**
* <p>Returns a security code which is one of the following values:</p>
- *
+ *
* <ul>
- *
+ *
* <li><p>0 if the {@link SummaryInformation} does not contain a
* security field or if there is no security on the document. Use
* {@link PropertySet#wasNull()} to distinguish between the two
* cases!</p></li>
- *
+ *
* <li><p>1 if the document is password protected</p></li>
- *
+ *
* <li><p>2 if the document is read-only recommended</p></li>
- *
+ *
* <li><p>4 if the document is read-only enforced</p></li>
- *
+ *
* <li><p>8 if the document is locked for annotations</p></li>
- *
+ *
* </ul>
- *
+ *
* @return The security code or <code>null</code>
*/
public int getSecurity()
@@ -731,7 +728,7 @@ public class SummaryInformation extends
/**
* <p>Sets the security code.</p>
- *
+ *
* @param security The security code to set.
*/
public void setSecurity(final int security)
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Thumbnail.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Thumbnail.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Thumbnail.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Thumbnail.java Thu Dec 30 02:35:06 2010
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hpsf;
import org.apache.poi.util.LittleEndian;
@@ -24,11 +24,8 @@ import org.apache.poi.util.LittleEndian;
*
* @author Drew Varner (Drew.Varner inOrAround sc.edu)
* @see SummaryInformation#getThumbnail()
- * @version $Id$
- * @since 2002-04-29
*/
-public class Thumbnail
-{
+public final class Thumbnail {
/**
* <p>Offset in bytes where the Clipboard Format Tag starts in the
@@ -130,7 +127,7 @@ public class Thumbnail
* <p>A <code>byte[]</code> to hold a thumbnail image in ({@link
* Variant#VT_CF VT_CF}) format.</p>
*/
- private byte[] thumbnailData = null;
+ private byte[] _thumbnailData = null;
@@ -156,7 +153,7 @@ public class Thumbnail
*/
public Thumbnail(final byte[] thumbnailData)
{
- this.thumbnailData = thumbnailData;
+ this._thumbnailData = thumbnailData;
}
@@ -170,7 +167,7 @@ public class Thumbnail
*/
public byte[] getThumbnail()
{
- return thumbnailData;
+ return _thumbnailData;
}
@@ -184,7 +181,7 @@ public class Thumbnail
*/
public void setThumbnail(final byte[] thumbnail)
{
- this.thumbnailData = thumbnail;
+ this._thumbnailData = thumbnail;
}
@@ -263,21 +260,18 @@ public class Thumbnail
if (!(getClipboardFormatTag() == CFTAG_WINDOWS))
throw new HPSFException("Clipboard Format Tag of Thumbnail must " +
"be CFTAG_WINDOWS.");
- if (!(getClipboardFormat() == CF_METAFILEPICT))
+ if (!(getClipboardFormat() == CF_METAFILEPICT)) {
throw new HPSFException("Clipboard Format of Thumbnail must " +
"be CF_METAFILEPICT.");
- else
- {
- byte[] thumbnail = getThumbnail();
- int wmfImageLength = thumbnail.length - OFFSET_WMFDATA;
- byte[] wmfImage = new byte[wmfImageLength];
- System.arraycopy(thumbnail,
- OFFSET_WMFDATA,
- wmfImage,
- 0,
- wmfImageLength);
- return wmfImage;
}
+ byte[] thumbnail = getThumbnail();
+ int wmfImageLength = thumbnail.length - OFFSET_WMFDATA;
+ byte[] wmfImage = new byte[wmfImageLength];
+ System.arraycopy(thumbnail,
+ OFFSET_WMFDATA,
+ wmfImage,
+ 0,
+ wmfImageLength);
+ return wmfImage;
}
-
}
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/TypeWriter.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/TypeWriter.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/TypeWriter.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/TypeWriter.java Thu Dec 30 02:35:06 2010
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hpsf;
import java.io.IOException;
@@ -27,8 +27,6 @@ import org.apache.poi.util.LittleEndian;
*
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
- * @version $Id$
- * @since 2003-02-20
*/
public class TypeWriter
{
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java Thu Dec 30 02:35:06 2010
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hpsf;
/**
@@ -27,8 +27,6 @@ package org.apache.poi.hpsf;
*
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
- * @version $Id$
- * @since 2002-02-09
*/
public class UnexpectedPropertySetTypeException extends HPSFException
{
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/UnsupportedVariantTypeException.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/UnsupportedVariantTypeException.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/UnsupportedVariantTypeException.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/UnsupportedVariantTypeException.java Thu Dec 30 02:35:06 2010
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hpsf;
import org.apache.poi.util.HexDump;
@@ -28,8 +28,6 @@ import org.apache.poi.util.HexDump;
*
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
- * @since 2003-08-05
- * @version $Id$
*/
public abstract class UnsupportedVariantTypeException
extends VariantTypeException
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Util.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Util.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Util.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Util.java Thu Dec 30 02:35:06 2010
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hpsf;
import java.io.IOException;
@@ -27,8 +27,6 @@ import java.util.Date;
* <p>Provides various static utility methods.</p>
*
* @author Rainer Klute (klute@rainer-klute.de)
- * @version $Id$
- * @since 2002-02-09
*/
public class Util
{
@@ -179,7 +177,7 @@ public class Util
*
* @param date The date to be converted
* @return The filetime
- *
+ *
* @see #filetimeToDate(long)
* @see #filetimeToDate(int, int)
*/
@@ -213,10 +211,10 @@ public class Util
* @return <code>true</code> if the collections are equal, else
* <code>false</code>.
*/
- public static boolean equals(final Collection c1, final Collection c2)
+ public static boolean equals(Collection<?> c1, Collection<?> c2)
{
- final Object[] o1 = c1.toArray();
- final Object[] o2 = c2.toArray();
+ Object[] o1 = c1.toArray();
+ Object[] o2 = c2.toArray();
return internalEquals(o1, o2);
}
@@ -231,14 +229,14 @@ public class Util
* @return <code>true</code> if the object arrays are equal,
* <code>false</code> if they are not.
*/
- public static boolean equals(final Object[] c1, final Object[] c2)
+ public static boolean equals(Object[] c1, Object[] c2)
{
- final Object[] o1 = (Object[]) c1.clone();
- final Object[] o2 = (Object[]) c2.clone();
+ final Object[] o1 = c1.clone();
+ final Object[] o2 = c2.clone();
return internalEquals(o1, o2);
}
- private static boolean internalEquals(final Object[] o1, final Object[] o2)
+ private static boolean internalEquals(Object[] o1, Object[] o2)
{
for (int i1 = 0; i1 < o1.length; i1++)
{
@@ -328,9 +326,9 @@ public class Util
/**
* <p>Returns a textual representation of a {@link Throwable}, including a
* stacktrace.</p>
- *
+ *
* @param t The {@link Throwable}
- *
+ *
* @return a string containing the output of a call to
* <code>t.printStacktrace()</code>.
*/
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Variant.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Variant.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Variant.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/Variant.java Thu Dec 30 02:35:06 2010
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hpsf;
import java.util.Collections;
@@ -34,8 +34,6 @@ import java.util.Map;
* <strong>[S]</strong> - may appear in a Safe Array.</p>
*
* @author Rainer Klute (klute@rainer-klute.de)
- * @version $Id$
- * @since 2002-02-09
*/
public class Variant
{
@@ -353,32 +351,32 @@ public class Variant
/**
* <p>Denotes a variant type with a length that is unknown to HPSF yet.</p>
*/
- public static final Integer LENGTH_UNKNOWN = new Integer(-2);
+ public static final Integer LENGTH_UNKNOWN = Integer.valueOf(-2);
/**
* <p>Denotes a variant type with a variable length.</p>
*/
- public static final Integer LENGTH_VARIABLE = new Integer(-1);
+ public static final Integer LENGTH_VARIABLE = Integer.valueOf(-1);
/**
* <p>Denotes a variant type with a length of 0 bytes.</p>
*/
- public static final Integer LENGTH_0 = new Integer(0);
+ public static final Integer LENGTH_0 = Integer.valueOf(0);
/**
* <p>Denotes a variant type with a length of 2 bytes.</p>
*/
- public static final Integer LENGTH_2 = new Integer(2);
+ public static final Integer LENGTH_2 = Integer.valueOf(2);
/**
* <p>Denotes a variant type with a length of 4 bytes.</p>
*/
- public static final Integer LENGTH_4 = new Integer(4);
+ public static final Integer LENGTH_4 = Integer.valueOf(4);
/**
* <p>Denotes a variant type with a length of 8 bytes.</p>
*/
- public static final Integer LENGTH_8 = new Integer(8);
+ public static final Integer LENGTH_8 = Integer.valueOf(8);
@@ -386,92 +384,92 @@ public class Variant
{
/* Initialize the number-to-name map: */
Map tm1 = new HashMap();
- tm1.put(new Long(0), "VT_EMPTY");
- tm1.put(new Long(1), "VT_NULL");
- tm1.put(new Long(2), "VT_I2");
- tm1.put(new Long(3), "VT_I4");
- tm1.put(new Long(4), "VT_R4");
- tm1.put(new Long(5), "VT_R8");
- tm1.put(new Long(6), "VT_CY");
- tm1.put(new Long(7), "VT_DATE");
- tm1.put(new Long(8), "VT_BSTR");
- tm1.put(new Long(9), "VT_DISPATCH");
- tm1.put(new Long(10), "VT_ERROR");
- tm1.put(new Long(11), "VT_BOOL");
- tm1.put(new Long(12), "VT_VARIANT");
- tm1.put(new Long(13), "VT_UNKNOWN");
- tm1.put(new Long(14), "VT_DECIMAL");
- tm1.put(new Long(16), "VT_I1");
- tm1.put(new Long(17), "VT_UI1");
- tm1.put(new Long(18), "VT_UI2");
- tm1.put(new Long(19), "VT_UI4");
- tm1.put(new Long(20), "VT_I8");
- tm1.put(new Long(21), "VT_UI8");
- tm1.put(new Long(22), "VT_INT");
- tm1.put(new Long(23), "VT_UINT");
- tm1.put(new Long(24), "VT_VOID");
- tm1.put(new Long(25), "VT_HRESULT");
- tm1.put(new Long(26), "VT_PTR");
- tm1.put(new Long(27), "VT_SAFEARRAY");
- tm1.put(new Long(28), "VT_CARRAY");
- tm1.put(new Long(29), "VT_USERDEFINED");
- tm1.put(new Long(30), "VT_LPSTR");
- tm1.put(new Long(31), "VT_LPWSTR");
- tm1.put(new Long(64), "VT_FILETIME");
- tm1.put(new Long(65), "VT_BLOB");
- tm1.put(new Long(66), "VT_STREAM");
- tm1.put(new Long(67), "VT_STORAGE");
- tm1.put(new Long(68), "VT_STREAMED_OBJECT");
- tm1.put(new Long(69), "VT_STORED_OBJECT");
- tm1.put(new Long(70), "VT_BLOB_OBJECT");
- tm1.put(new Long(71), "VT_CF");
- tm1.put(new Long(72), "VT_CLSID");
+ tm1.put(Long.valueOf(0), "VT_EMPTY");
+ tm1.put(Long.valueOf(1), "VT_NULL");
+ tm1.put(Long.valueOf(2), "VT_I2");
+ tm1.put(Long.valueOf(3), "VT_I4");
+ tm1.put(Long.valueOf(4), "VT_R4");
+ tm1.put(Long.valueOf(5), "VT_R8");
+ tm1.put(Long.valueOf(6), "VT_CY");
+ tm1.put(Long.valueOf(7), "VT_DATE");
+ tm1.put(Long.valueOf(8), "VT_BSTR");
+ tm1.put(Long.valueOf(9), "VT_DISPATCH");
+ tm1.put(Long.valueOf(10), "VT_ERROR");
+ tm1.put(Long.valueOf(11), "VT_BOOL");
+ tm1.put(Long.valueOf(12), "VT_VARIANT");
+ tm1.put(Long.valueOf(13), "VT_UNKNOWN");
+ tm1.put(Long.valueOf(14), "VT_DECIMAL");
+ tm1.put(Long.valueOf(16), "VT_I1");
+ tm1.put(Long.valueOf(17), "VT_UI1");
+ tm1.put(Long.valueOf(18), "VT_UI2");
+ tm1.put(Long.valueOf(19), "VT_UI4");
+ tm1.put(Long.valueOf(20), "VT_I8");
+ tm1.put(Long.valueOf(21), "VT_UI8");
+ tm1.put(Long.valueOf(22), "VT_INT");
+ tm1.put(Long.valueOf(23), "VT_UINT");
+ tm1.put(Long.valueOf(24), "VT_VOID");
+ tm1.put(Long.valueOf(25), "VT_HRESULT");
+ tm1.put(Long.valueOf(26), "VT_PTR");
+ tm1.put(Long.valueOf(27), "VT_SAFEARRAY");
+ tm1.put(Long.valueOf(28), "VT_CARRAY");
+ tm1.put(Long.valueOf(29), "VT_USERDEFINED");
+ tm1.put(Long.valueOf(30), "VT_LPSTR");
+ tm1.put(Long.valueOf(31), "VT_LPWSTR");
+ tm1.put(Long.valueOf(64), "VT_FILETIME");
+ tm1.put(Long.valueOf(65), "VT_BLOB");
+ tm1.put(Long.valueOf(66), "VT_STREAM");
+ tm1.put(Long.valueOf(67), "VT_STORAGE");
+ tm1.put(Long.valueOf(68), "VT_STREAMED_OBJECT");
+ tm1.put(Long.valueOf(69), "VT_STORED_OBJECT");
+ tm1.put(Long.valueOf(70), "VT_BLOB_OBJECT");
+ tm1.put(Long.valueOf(71), "VT_CF");
+ tm1.put(Long.valueOf(72), "VT_CLSID");
Map tm2 = new HashMap(tm1.size(), 1.0F);
tm2.putAll(tm1);
numberToName = Collections.unmodifiableMap(tm2);
/* Initialize the number-to-length map: */
tm1.clear();
- tm1.put(new Long(0), LENGTH_0);
- tm1.put(new Long(1), LENGTH_UNKNOWN);
- tm1.put(new Long(2), LENGTH_2);
- tm1.put(new Long(3), LENGTH_4);
- tm1.put(new Long(4), LENGTH_4);
- tm1.put(new Long(5), LENGTH_8);
- tm1.put(new Long(6), LENGTH_UNKNOWN);
- tm1.put(new Long(7), LENGTH_UNKNOWN);
- tm1.put(new Long(8), LENGTH_UNKNOWN);
- tm1.put(new Long(9), LENGTH_UNKNOWN);
- tm1.put(new Long(10), LENGTH_UNKNOWN);
- tm1.put(new Long(11), LENGTH_UNKNOWN);
- tm1.put(new Long(12), LENGTH_UNKNOWN);
- tm1.put(new Long(13), LENGTH_UNKNOWN);
- tm1.put(new Long(14), LENGTH_UNKNOWN);
- tm1.put(new Long(16), LENGTH_UNKNOWN);
- tm1.put(new Long(17), LENGTH_UNKNOWN);
- tm1.put(new Long(18), LENGTH_UNKNOWN);
- tm1.put(new Long(19), LENGTH_UNKNOWN);
- tm1.put(new Long(20), LENGTH_UNKNOWN);
- tm1.put(new Long(21), LENGTH_UNKNOWN);
- tm1.put(new Long(22), LENGTH_UNKNOWN);
- tm1.put(new Long(23), LENGTH_UNKNOWN);
- tm1.put(new Long(24), LENGTH_UNKNOWN);
- tm1.put(new Long(25), LENGTH_UNKNOWN);
- tm1.put(new Long(26), LENGTH_UNKNOWN);
- tm1.put(new Long(27), LENGTH_UNKNOWN);
- tm1.put(new Long(28), LENGTH_UNKNOWN);
- tm1.put(new Long(29), LENGTH_UNKNOWN);
- tm1.put(new Long(30), LENGTH_VARIABLE);
- tm1.put(new Long(31), LENGTH_UNKNOWN);
- tm1.put(new Long(64), LENGTH_8);
- tm1.put(new Long(65), LENGTH_UNKNOWN);
- tm1.put(new Long(66), LENGTH_UNKNOWN);
- tm1.put(new Long(67), LENGTH_UNKNOWN);
- tm1.put(new Long(68), LENGTH_UNKNOWN);
- tm1.put(new Long(69), LENGTH_UNKNOWN);
- tm1.put(new Long(70), LENGTH_UNKNOWN);
- tm1.put(new Long(71), LENGTH_UNKNOWN);
- tm1.put(new Long(72), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(0), LENGTH_0);
+ tm1.put(Long.valueOf(1), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(2), LENGTH_2);
+ tm1.put(Long.valueOf(3), LENGTH_4);
+ tm1.put(Long.valueOf(4), LENGTH_4);
+ tm1.put(Long.valueOf(5), LENGTH_8);
+ tm1.put(Long.valueOf(6), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(7), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(8), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(9), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(10), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(11), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(12), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(13), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(14), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(16), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(17), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(18), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(19), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(20), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(21), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(22), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(23), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(24), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(25), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(26), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(27), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(28), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(29), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(30), LENGTH_VARIABLE);
+ tm1.put(Long.valueOf(31), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(64), LENGTH_8);
+ tm1.put(Long.valueOf(65), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(66), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(67), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(68), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(69), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(70), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(71), LENGTH_UNKNOWN);
+ tm1.put(Long.valueOf(72), LENGTH_UNKNOWN);
tm2 = new HashMap(tm1.size(), 1.0F);
tm2.putAll(tm1);
numberToLength = Collections.unmodifiableMap(tm2);
@@ -488,7 +486,7 @@ public class Variant
*/
public static String getVariantName(final long variantType)
{
- final String name = (String) numberToName.get(new Long(variantType));
+ final String name = (String) numberToName.get(Long.valueOf(variantType));
return name != null ? name : "unknown variant type";
}
@@ -503,7 +501,7 @@ public class Variant
*/
public static int getVariantLength(final long variantType)
{
- final Long key = new Long((int) variantType);
+ final Long key = Long.valueOf((int) variantType);
final Long length = (Long) numberToLength.get(key);
if (length == null)
return -2;
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/VariantSupport.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/VariantSupport.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/VariantSupport.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/VariantSupport.java Thu Dec 30 02:35:06 2010
@@ -29,10 +29,10 @@ import org.apache.poi.util.LittleEndianC
/**
* <p>Supports reading and writing of variant data.</p>
- *
+ *
* <p><strong>FIXME (3):</strong> Reading and writing should be made more
* uniform than it is now. The following items should be resolved:
- *
+ *
* <ul>
*
* <li><p>Reading requires a length parameter that is 4 byte greater than the
@@ -45,8 +45,6 @@ import org.apache.poi.util.LittleEndianC
*
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
- * @since 2003-08-08
- * @version $Id$
*/
public class VariantSupport extends Variant
{
@@ -70,7 +68,7 @@ public class VariantSupport extends Vari
* on or off.</p>
*
* @return <code>true</code> if logging is turned on, else
- * <code>false</code>.
+ * <code>false</code>.
*/
public static boolean isLogUnsupportedTypes()
{
@@ -99,7 +97,7 @@ public class VariantSupport extends Vari
{
if (unsupportedMessage == null)
unsupportedMessage = new LinkedList();
- Long vt = new Long(ex.getVariantType());
+ Long vt = Long.valueOf(ex.getVariantType());
if (!unsupportedMessage.contains(vt))
{
System.err.println(ex.getMessage());
@@ -123,7 +121,7 @@ public class VariantSupport extends Vari
* <p>Checks whether HPSF supports the specified variant type. Unsupported
* types should be implemented included in the {@link #SUPPORTED_TYPES}
* array.</p>
- *
+ *
* @see Variant
* @param variantType the variant type to check
* @return <code>true</code> if HPFS supports this type, else
@@ -141,7 +139,7 @@ public class VariantSupport extends Vari
/**
* <p>Reads a variant type from a byte array.</p>
- *
+ *
* @param src The byte array
* @param offset The offset in the byte array where the variant starts
* @param length The length of the variant including the variant type field
@@ -184,7 +182,7 @@ public class VariantSupport extends Vari
* Read a short. In Java it is represented as an
* Integer object.
*/
- value = new Integer(LittleEndian.getShort(src, o1));
+ value = Integer.valueOf(LittleEndian.getShort(src, o1));
break;
}
case Variant.VT_I4:
@@ -193,7 +191,7 @@ public class VariantSupport extends Vari
* Read a word. In Java it is represented as an
* Integer object.
*/
- value = new Integer(LittleEndian.getInt(src, o1));
+ value = Integer.valueOf(LittleEndian.getInt(src, o1));
break;
}
case Variant.VT_I8:
@@ -202,7 +200,7 @@ public class VariantSupport extends Vari
* Read a double word. In Java it is represented as a
* Long object.
*/
- value = new Long(LittleEndian.getLong(src, o1));
+ value = Long.valueOf(LittleEndian.getLong(src, o1));
break;
}
case Variant.VT_R8:
@@ -274,9 +272,20 @@ public class VariantSupport extends Vari
}
case Variant.VT_CF:
{
+ if(l1 < 0) {
+ /**
+ * YK: reading the ClipboardData packet (VT_CF) is not quite correct.
+ * The size of the data is determined by the first four bytes of the packet
+ * while the current implementation calculates it in the Section constructor.
+ * Test files in Bugzilla 42726 and 45583 clearly show that this approach does not always work.
+ * The workaround below attempts to gracefully handle such cases instead of throwing exceptions.
+ *
+ * August 20, 2009
+ */
+ l1 = LittleEndian.getInt(src, o1); o1 += LittleEndian.INT_SIZE;
+ }
final byte[] v = new byte[l1];
- for (int i = 0; i < l1; i++)
- v[i] = src[(o1 + i)];
+ System.arraycopy(src, o1, v, 0, v.length);
value = v;
break;
}
@@ -309,16 +318,16 @@ public class VariantSupport extends Vari
/**
- * <p>Turns a codepage number into the equivalent character encoding's
+ * <p>Turns a codepage number into the equivalent character encoding's
* name.</p>
*
* @param codepage The codepage number
- *
- * @return The character encoding's name. If the codepage number is 65001,
+ *
+ * @return The character encoding's name. If the codepage number is 65001,
* the encoding name is "UTF-8". All other positive numbers are mapped to
- * "cp" followed by the number, e.g. if the codepage number is 1252 the
+ * "cp" followed by the number, e.g. if the codepage number is 1252 the
* returned character encoding name will be "cp1252".
- *
+ *
* @exception UnsupportedEncodingException if the specified codepage is
* less than zero.
*/
@@ -491,7 +500,7 @@ public class VariantSupport extends Vari
}
case Variant.VT_LPWSTR:
{
- final int nrOfChars = ((String) value).length() + 1;
+ final int nrOfChars = ((String) value).length() + 1;
length += TypeWriter.writeUIntToStream(out, nrOfChars);
char[] s = Util.pad4((String) value);
for (int i = 0; i < s.length; i++)
@@ -511,7 +520,7 @@ public class VariantSupport extends Vari
}
case Variant.VT_CF:
{
- final byte[] b = (byte[]) value;
+ final byte[] b = (byte[]) value;
out.write(b);
length = b.length;
break;
@@ -537,7 +546,7 @@ public class VariantSupport extends Vari
+ value.getClass().toString() + ", "
+ value.toString());
}
- length += TypeWriter.writeToStream(out,
+ length += TypeWriter.writeToStream(out,
((Integer) value).intValue());
break;
}
@@ -549,7 +558,7 @@ public class VariantSupport extends Vari
}
case Variant.VT_R8:
{
- length += TypeWriter.writeToStream(out,
+ length += TypeWriter.writeToStream(out,
((Double) value).doubleValue());
break;
}
@@ -570,7 +579,7 @@ public class VariantSupport extends Vari
* is a byte array we can write it nevertheless. */
if (value instanceof byte[])
{
- final byte[] b = (byte[]) value;
+ final byte[] b = (byte[]) value;
out.write(b);
length = b.length;
writeUnsupportedTypeMessage
@@ -584,5 +593,4 @@ public class VariantSupport extends Vari
return length;
}
-
}
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/VariantTypeException.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/VariantTypeException.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/VariantTypeException.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/VariantTypeException.java Thu Dec 30 02:35:06 2010
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hpsf;
/**
@@ -23,8 +23,6 @@ package org.apache.poi.hpsf;
*
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
- * @since 2004-06-21
- * @version $Id$
*/
public abstract class VariantTypeException extends HPSFException
{
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/WritingNotSupportedException.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/WritingNotSupportedException.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/WritingNotSupportedException.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/WritingNotSupportedException.java Thu Dec 30 02:35:06 2010
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hpsf;
/**
@@ -26,8 +26,6 @@ package org.apache.poi.hpsf;
*
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
- * @since 2003-08-08
- * @version $Id$
*/
public class WritingNotSupportedException
extends UnsupportedVariantTypeException
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java Thu Dec 30 02:35:06 2010
@@ -14,8 +14,11 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpsf.extractor;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
@@ -28,12 +31,13 @@ import org.apache.poi.hpsf.Property;
import org.apache.poi.hpsf.SpecialPropertySet;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian;
/**
* Extracts all of the HPSF properties, both
- * build in and custom, returning them in
+ * build in and custom, returning them in
* textual form.
*/
public class HPSFPropertiesExtractor extends POITextExtractor {
@@ -46,54 +50,59 @@ public class HPSFPropertiesExtractor ext
public HPSFPropertiesExtractor(POIFSFileSystem fs) {
super(new PropertiesOnlyDocument(fs));
}
-
+ public HPSFPropertiesExtractor(NPOIFSFileSystem fs) {
+ super(new PropertiesOnlyDocument(fs));
+ }
+
public String getDocumentSummaryInformationText() {
DocumentSummaryInformation dsi = document.getDocumentSummaryInformation();
StringBuffer text = new StringBuffer();
// Normal properties
text.append( getPropertiesText(dsi) );
-
+
// Now custom ones
- CustomProperties cps = dsi.getCustomProperties();
- Iterator keys = cps.keySet().iterator();
- while(keys.hasNext()) {
- String key = (String)keys.next();
- String val = getPropertyValueText( cps.get(key) );
- text.append(key + " = " + val + "\n");
+ CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
+ if(cps != null) {
+ Iterator<String> keys = cps.nameSet().iterator();
+ while(keys.hasNext()) {
+ String key = keys.next();
+ String val = getPropertyValueText( cps.get(key) );
+ text.append(key + " = " + val + "\n");
+ }
}
-
+
// All done
return text.toString();
}
public String getSummaryInformationText() {
SummaryInformation si = document.getSummaryInformation();
-
+
// Just normal properties
return getPropertiesText(si);
}
-
+
private static String getPropertiesText(SpecialPropertySet ps) {
if(ps == null) {
// Not defined, oh well
return "";
}
-
+
StringBuffer text = new StringBuffer();
-
+
PropertyIDMap idMap = ps.getPropertySetIDMap();
Property[] props = ps.getProperties();
for(int i=0; i<props.length; i++) {
- String type = Long.toString( props[i].getID() );
+ String type = Long.toString( props[i].getID() );
Object typeObj = idMap.get(props[i].getID());
if(typeObj != null) {
type = typeObj.toString();
}
-
+
String val = getPropertyValueText( props[i].getValue() );
text.append(type + " = " + val + "\n");
}
-
+
return text.toString();
}
private static String getPropertyValueText(Object val) {
@@ -121,13 +130,13 @@ public class HPSFPropertiesExtractor ext
}
/**
- * Return the text of all the properties defined in
+ * @return the text of all the properties defined in
* the document.
*/
public String getText() {
return getSummaryInformationText() + getDocumentSummaryInformationText();
}
-
+
/**
* Prevent recursion!
*/
@@ -136,16 +145,28 @@ public class HPSFPropertiesExtractor ext
}
/**
- * So we can get at the properties of any
+ * So we can get at the properties of any
* random OLE2 document.
*/
- private static class PropertiesOnlyDocument extends POIDocument {
- private PropertiesOnlyDocument(POIFSFileSystem fs) {
+ private static final class PropertiesOnlyDocument extends POIDocument {
+ public PropertiesOnlyDocument(NPOIFSFileSystem fs) {
+ super(fs.getRoot());
+ }
+ public PropertiesOnlyDocument(POIFSFileSystem fs) {
super(fs);
}
- public void write(OutputStream out) throws IOException {
+ public void write(OutputStream out) {
throw new IllegalStateException("Unable to write, only for properties!");
}
}
+
+ public static void main(String[] args) throws IOException {
+ for(String file : args) {
+ HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(
+ new NPOIFSFileSystem(new File(file))
+ );
+ System.out.println(ext.getText());
+ }
+ }
}
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hssf/record/StyleRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hssf/record/StyleRecord.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hssf/record/StyleRecord.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hssf/record/StyleRecord.java Thu Dec 30 02:35:06 2010
@@ -73,7 +73,7 @@ public final class StyleRecord extends R
byte[] string = in.readRemainder();
if (fHighByte.isSet(field_3_string_options)) {
- field_4_name= StringUtil.getFromUnicodeBE(string, 0, field_2_name_length);
+ field_4_name= StringUtil.getFromUnicodeLE(string, 0, field_2_name_length);
} else {
field_4_name=StringUtil.getFromCompressedUnicode(string, 0, field_2_name_length);
}
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Thu Dec 30 02:35:06 2010
@@ -257,7 +257,6 @@ public class HSSFWorkbook extends POIDoc
// If we're not preserving nodes, don't track the
// POIFS any more
if(! preserveNodes) {
- this.filesystem = null;
this.directory = null;
}
@@ -1163,7 +1162,7 @@ public class HSSFWorkbook extends POIDoc
excepts.add("WORKBOOK");
// Copy over all the other nodes to our new poifs
- copyNodes(this.filesystem,fs,excepts);
+ copyNodes(this.directory.getFileSystem(),fs,excepts);
}
fs.writeFilesystem(stream);
//poifs.writeFilesystem(stream);
@@ -1664,7 +1663,7 @@ public class HSSFWorkbook extends POIDoc
Object sub = subRecordIter.next();
if (sub instanceof EmbeddedObjectRefSubRecord)
{
- objects.add(new HSSFObjectData((ObjRecord) obj, filesystem));
+ objects.add(new HSSFObjectData((ObjRecord) obj, this.directory.getFileSystem()));
}
}
}
Added: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java?rev=1053791&view=auto
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java (added)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java Thu Dec 30 02:35:06 2010
@@ -0,0 +1,64 @@
+
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+
+package org.apache.poi.poifs.common;
+
+import org.apache.poi.util.LittleEndianConsts;
+
+/**
+ * <p>A class describing attributes of the Big Block Size</p>
+ */
+public final class POIFSBigBlockSize
+{
+ private int bigBlockSize;
+ private short headerValue;
+
+ protected POIFSBigBlockSize(int bigBlockSize, short headerValue) {
+ this.bigBlockSize = bigBlockSize;
+ this.headerValue = headerValue;
+ }
+
+ public int getBigBlockSize() {
+ return bigBlockSize;
+ }
+
+ /**
+ * Returns the value that gets written into the
+ * header.
+ * Is the power of two that corresponds to the
+ * size of the block, eg 512 => 9
+ */
+ public short getHeaderValue() {
+ return headerValue;
+ }
+
+ public int getPropertiesPerBlock() {
+ return bigBlockSize / POIFSConstants.PROPERTY_SIZE;
+ }
+
+ public int getBATEntriesPerBlock() {
+ return bigBlockSize / LittleEndianConsts.INT_SIZE;
+ }
+ public int getXBATEntriesPerBlock() {
+ return getBATEntriesPerBlock() - 1;
+ }
+ public int getNextXBATChainOffset() {
+ return getXBATEntriesPerBlock() * LittleEndianConsts.INT_SIZE;
+ }
+}
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/common/POIFSConstants.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/common/POIFSConstants.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/common/POIFSConstants.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/common/POIFSConstants.java Thu Dec 30 02:35:06 2010
@@ -21,21 +21,48 @@ package org.apache.poi.poifs.common;
/**
* <p>A repository for constants shared by POI classes.</p>
- *
- * @author Marc Johnson (mjohnson at apache dot org)
*/
-
public interface POIFSConstants
{
/** Most files use 512 bytes as their big block size */
- public static final int BIG_BLOCK_SIZE = 0x0200;
+ public static final int SMALLER_BIG_BLOCK_SIZE = 0x0200;
+ public static final POIFSBigBlockSize SMALLER_BIG_BLOCK_SIZE_DETAILS =
+ new POIFSBigBlockSize(SMALLER_BIG_BLOCK_SIZE, (short)9);
/** Some use 4096 bytes */
public static final int LARGER_BIG_BLOCK_SIZE = 0x1000;
+ public static final POIFSBigBlockSize LARGER_BIG_BLOCK_SIZE_DETAILS =
+ new POIFSBigBlockSize(LARGER_BIG_BLOCK_SIZE, (short)12);
- public static final int END_OF_CHAIN = -2;
+ /** How big a block in the small block stream is. Fixed size */
+ public static final int SMALL_BLOCK_SIZE = 0x0040;
+
+ /** How big a single property is */
public static final int PROPERTY_SIZE = 0x0080;
+
+ /**
+ * The minimum size of a document before it's stored using
+ * Big Blocks (normal streams). Smaller documents go in the
+ * Mini Stream (SBAT / Small Blocks)
+ */
+ public static final int BIG_BLOCK_MINIMUM_DOCUMENT_SIZE = 0x1000;
+
+ /** The highest sector number you're allowed, 0xFFFFFFFA */
+ public static final int LARGEST_REGULAR_SECTOR_NUMBER = -5;
+
+ /** Indicates the sector holds a DIFAT block (0xFFFFFFFC) */
+ public static final int DIFAT_SECTOR_BLOCK = -4;
+ /** Indicates the sector holds a FAT block (0xFFFFFFFD) */
+ public static final int FAT_SECTOR_BLOCK = -3;
+ /** Indicates the sector is the end of a chain (0xFFFFFFFE) */
+ public static final int END_OF_CHAIN = -2;
+ /** Indicates the sector is not used (0xFFFFFFFF) */
public static final int UNUSED_BLOCK = -1;
+ /** The first 4 bytes of an OOXML file, used in detection */
public static final byte[] OOXML_FILE_HEADER =
new byte[] { 0x50, 0x4b, 0x03, 0x04 };
+
+ /** HACKY: For backwards compatibility on 3.2 */
+ public static final int BIG_BLOCK_SIZE = SMALLER_BIG_BLOCK_SIZE;
+
} // end public interface POIFSConstants;
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSDump.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSDump.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSDump.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSDump.java Thu Dec 30 02:35:06 2010
@@ -1,74 +1,74 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.poifs.dev;
-
-import org.apache.poi.poifs.filesystem.*;
-
-import java.io.FileInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.FileOutputStream;
-import java.util.Iterator;
-
-/**
- *
- * Dump internal structure of a OLE2 file into file system
- *
- * @author Yegor Kozlov
- */
-public class POIFSDump {
-
- public static void main(String[] args) throws Exception {
- for (int i = 0; i < args.length; i++) {
- System.out.println("Dumping " + args[i]);
- FileInputStream is = new FileInputStream(args[i]);
- POIFSFileSystem fs = new POIFSFileSystem(is);
- is.close();
-
- DirectoryEntry root = fs.getRoot();
- File file = new File(root.getName());
- file.mkdir();
-
- dump(root, file);
- }
- }
-
-
- public static void dump(DirectoryEntry root, File parent) throws IOException {
- for(Iterator it = root.getEntries(); it.hasNext();){
- Entry entry = (Entry)it.next();
- if(entry instanceof DocumentNode){
- DocumentNode node = (DocumentNode)entry;
- DocumentInputStream is = new DocumentInputStream(node);
- byte[] bytes = new byte[node.getSize()];
- is.read(bytes);
- is.close();
-
- FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
- out.write(bytes);
- out.close();
- } else if (entry instanceof DirectoryEntry){
- DirectoryEntry dir = (DirectoryEntry)entry;
- File file = new File(parent, entry.getName());
- file.mkdir();
- dump(dir, file);
- } else {
- System.err.println("Skipping unsupported POIFS entry: " + entry);
- }
- }
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.poifs.dev;
+
+import org.apache.poi.poifs.filesystem.*;
+
+import java.io.FileInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.util.Iterator;
+
+/**
+ *
+ * Dump internal structure of a OLE2 file into file system
+ *
+ * @author Yegor Kozlov
+ */
+public class POIFSDump {
+
+ public static void main(String[] args) throws Exception {
+ for (int i = 0; i < args.length; i++) {
+ System.out.println("Dumping " + args[i]);
+ FileInputStream is = new FileInputStream(args[i]);
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+ is.close();
+
+ DirectoryEntry root = fs.getRoot();
+ File file = new File(root.getName());
+ file.mkdir();
+
+ dump(root, file);
+ }
+ }
+
+
+ public static void dump(DirectoryEntry root, File parent) throws IOException {
+ for(Iterator it = root.getEntries(); it.hasNext();){
+ Entry entry = (Entry)it.next();
+ if(entry instanceof DocumentNode){
+ DocumentNode node = (DocumentNode)entry;
+ DocumentInputStream is = new DocumentInputStream(node);
+ byte[] bytes = new byte[node.getSize()];
+ is.read(bytes);
+ is.close();
+
+ FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
+ out.write(bytes);
+ out.close();
+ } else if (entry instanceof DirectoryEntry){
+ DirectoryEntry dir = (DirectoryEntry)entry;
+ File file = new File(parent, entry.getName());
+ file.mkdir();
+ dump(dir, file);
+ } else {
+ System.err.println("Skipping unsupported POIFS entry: " + entry);
+ }
+ }
+ }
+}
Added: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java?rev=1053791&view=auto
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java (added)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java Thu Dec 30 02:35:06 2010
@@ -0,0 +1,152 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.poifs.dev;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.poi.poifs.common.POIFSBigBlockSize;
+import org.apache.poi.poifs.common.POIFSConstants;
+import org.apache.poi.poifs.property.PropertyTable;
+import org.apache.poi.poifs.storage.BlockAllocationTableReader;
+import org.apache.poi.poifs.storage.BlockList;
+import org.apache.poi.poifs.storage.HeaderBlock;
+import org.apache.poi.poifs.storage.ListManagedBlock;
+import org.apache.poi.poifs.storage.RawDataBlockList;
+import org.apache.poi.poifs.storage.SmallBlockTableReader;
+import org.apache.poi.util.HexDump;
+import org.apache.poi.util.IntList;
+
+/**
+ * A very low level debugging tool, for printing out core
+ * information on the headers and FAT blocks.
+ * You probably only want to use this if you're trying
+ * to understand POIFS, or if you're trying to track
+ * down the source of corruption in a file.
+ */
+public class POIFSHeaderDumper {
+ /**
+ * Display the entries of multiple POIFS files
+ *
+ * @param args the names of the files to be displayed
+ */
+ public static void main(final String args[]) throws Exception {
+ if (args.length == 0) {
+ System.err.println("Must specify at least one file to view");
+ System.exit(1);
+ }
+
+ for (int j = 0; j < args.length; j++) {
+ viewFile(args[j]);
+ }
+ }
+
+ public static void viewFile(final String filename) throws Exception {
+ InputStream inp = new FileInputStream(filename);
+
+ // Header
+ HeaderBlock header_block = new HeaderBlock(inp);
+ displayHeader(header_block);
+
+ // Raw blocks
+ POIFSBigBlockSize bigBlockSize = header_block.getBigBlockSize();
+ RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);
+ displayRawBlocksSummary(data_blocks);
+
+ // Main FAT Table
+ BlockAllocationTableReader batReader =
+ new BlockAllocationTableReader(
+ header_block.getBigBlockSize(),
+ header_block.getBATCount(),
+ header_block.getBATArray(),
+ header_block.getXBATCount(),
+ header_block.getXBATIndex(),
+ data_blocks);
+ displayBATReader(batReader);
+
+ // Properties Table
+ PropertyTable properties =
+ new PropertyTable(header_block, data_blocks);
+
+ // Mini Fat
+ BlockList sbat =
+ SmallBlockTableReader.getSmallDocumentBlocks(
+ bigBlockSize, data_blocks, properties.getRoot(),
+ header_block.getSBATStart()
+ );
+ }
+
+ public static void displayHeader(HeaderBlock header_block) throws Exception {
+ System.out.println("Header Details:");
+ System.out.println(" Block size: " + header_block.getBigBlockSize().getBigBlockSize());
+ System.out.println(" BAT (FAT) header blocks: " + header_block.getBATArray().length);
+ System.out.println(" BAT (FAT) block count: " + header_block.getBATCount());
+ System.out.println(" XBAT (FAT) block count: " + header_block.getXBATCount());
+ System.out.println(" XBAT (FAT) block 1 at: " + header_block.getXBATIndex());
+ System.out.println(" SBAT (MiniFAT) block count: " + header_block.getSBATCount());
+ System.out.println(" SBAT (MiniFAT) block 1 at: " + header_block.getSBATStart());
+ System.out.println(" Property table at: " + header_block.getPropertyStart());
+ System.out.println("");
+ }
+
+ public static void displayRawBlocksSummary(RawDataBlockList data_blocks) throws Exception {
+ System.out.println("Raw Blocks Details:");
+ System.out.println(" Number of blocks: " + data_blocks.blockCount());
+
+ Method gbm = data_blocks.getClass().getSuperclass().getDeclaredMethod("get", int.class);
+ gbm.setAccessible(true);
+
+ for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) {
+ ListManagedBlock block = (ListManagedBlock)gbm.invoke(data_blocks, Integer.valueOf(i));
+ byte[] data = new byte[Math.min(48, block.getData().length)];
+ System.arraycopy(block.getData(), 0, data, 0, data.length);
+
+ System.out.println(" Block #" + i + ":");
+ System.out.println(HexDump.dump(data, 0, 0));
+ }
+
+ System.out.println("");
+ }
+
+ public static void displayBATReader(BlockAllocationTableReader batReader) throws Exception {
+ System.out.println("Sectors, as referenced from the FAT:");
+ Field entriesF = batReader.getClass().getDeclaredField("_entries");
+ entriesF.setAccessible(true);
+ IntList entries = (IntList)entriesF.get(batReader);
+
+ for(int i=0; i<entries.size(); i++) {
+ int bn = entries.get(i);
+ String bnS = Integer.toString(bn);
+ if(bn == POIFSConstants.END_OF_CHAIN) {
+ bnS = "End Of Chain";
+ } else if(bn == POIFSConstants.DIFAT_SECTOR_BLOCK) {
+ bnS = "DI Fat Block";
+ } else if(bn == POIFSConstants.FAT_SECTOR_BLOCK) {
+ bnS = "Normal Fat Block";
+ } else if(bn == POIFSConstants.UNUSED_BLOCK) {
+ bnS = "Block Not Used (Free)";
+ }
+
+ System.out.println(" Block # " + i + " -> " + bnS);
+ }
+
+ System.out.println("");
+ }
+}
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSLister.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSLister.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSLister.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSLister.java Thu Dec 30 02:35:06 2010
@@ -17,82 +17,88 @@
package org.apache.poi.poifs.dev;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
-import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentNode;
+import org.apache.poi.poifs.filesystem.Entry;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
* A lister of the entries in POIFS files.
- *
+ *
* Much simpler than {@link POIFSViewer}
*/
public class POIFSLister {
- /**
- * Display the entries of multiple POIFS files
- *
- * @param args the names of the files to be displayed
- */
- public static void main(final String args[]) throws IOException {
- if (args.length == 0)
- {
- System.err.println("Must specify at least one file to view");
- System.exit(1);
- }
-
- boolean withSizes = false;
- for (int j = 0; j < args.length; j++) {
- if(args[j].equalsIgnoreCase("-size") ||
- args[j].equalsIgnoreCase("-sizes")) {
- withSizes = true;
- } else {
- viewFile(args[j], withSizes);
- }
- }
- }
-
- public static void viewFile(final String filename, boolean withSizes) throws IOException
- {
- POIFSFileSystem fs = new POIFSFileSystem(
- new FileInputStream(filename)
- );
- displayDirectory(fs.getRoot(), "", withSizes);
- }
-
- public static void displayDirectory(DirectoryNode dir, String indent, boolean withSizes) {
- System.out.println(indent + dir.getName() + " -");
- String newIndent = indent + " ";
-
- boolean hadChildren = false;
- for(Iterator it = dir.getEntries(); it.hasNext(); ) {
- hadChildren = true;
- Object entry = it.next();
- if(entry instanceof DirectoryNode) {
- displayDirectory((DirectoryNode)entry, newIndent, withSizes);
- } else {
- DocumentNode doc = (DocumentNode)entry;
- String name = doc.getName();
- String size = "";
- if(name.charAt(0) < 10) {
- String altname = "(0x0" + (int)name.charAt(0) + ")" + name.substring(1);
- name = name.substring(1) + " <" + altname + ">";
- }
- if(withSizes) {
- size = " [" +
- doc.getSize() + " / 0x" +
- Integer.toHexString(doc.getSize()) +
- "]";
- }
- System.out.println(newIndent + name + size);
- }
- }
- if(!hadChildren) {
- System.out.println(newIndent + "(no children)");
- }
- }
-}
\ No newline at end of file
+ /**
+ * Display the entries of multiple POIFS files
+ *
+ * @param args the names of the files to be displayed
+ */
+ public static void main(final String args[]) throws IOException {
+ if (args.length == 0) {
+ System.err.println("Must specify at least one file to view");
+ System.exit(1);
+ }
+
+ boolean withSizes = false;
+ boolean newPOIFS = true;
+ for (int j = 0; j < args.length; j++) {
+ if (args[j].equalsIgnoreCase("-size") || args[j].equalsIgnoreCase("-sizes")) {
+ withSizes = true;
+ } else if (args[j].equalsIgnoreCase("-old") || args[j].equalsIgnoreCase("-old-poifs")) {
+ newPOIFS = false;
+ } else {
+ if(newPOIFS) {
+ viewFile(args[j], withSizes);
+ } else {
+ viewFileOld(args[j], withSizes);
+ }
+ }
+ }
+ }
+
+ public static void viewFile(final String filename, boolean withSizes) throws IOException {
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(filename));
+ displayDirectory(fs.getRoot(), "", withSizes);
+ }
+
+ public static void viewFileOld(final String filename, boolean withSizes) throws IOException {
+ POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
+ displayDirectory(fs.getRoot(), "", withSizes);
+ }
+
+ public static void displayDirectory(DirectoryNode dir, String indent, boolean withSizes) {
+ System.out.println(indent + dir.getName() + " -");
+ String newIndent = indent + " ";
+
+ boolean hadChildren = false;
+ for(Iterator<Entry> it = dir.getEntries(); it.hasNext();) {
+ hadChildren = true;
+ Entry entry = it.next();
+ if (entry instanceof DirectoryNode) {
+ displayDirectory((DirectoryNode) entry, newIndent, withSizes);
+ } else {
+ DocumentNode doc = (DocumentNode) entry;
+ String name = doc.getName();
+ String size = "";
+ if (name.charAt(0) < 10) {
+ String altname = "(0x0" + (int) name.charAt(0) + ")" + name.substring(1);
+ name = name.substring(1) + " <" + altname + ">";
+ }
+ if (withSizes) {
+ size = " [" + doc.getSize() + " / 0x" +
+ Integer.toHexString(doc.getSize()) + "]";
+ }
+ System.out.println(newIndent + name + size);
+ }
+ }
+ if (!hadChildren) {
+ System.out.println(newIndent + "(no children)");
+ }
+ }
+}
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSViewable.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSViewable.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSViewable.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/dev/POIFSViewable.java Thu Dec 30 02:35:06 2010
@@ -46,7 +46,7 @@ public interface POIFSViewable
*/
public Object [] getViewableArray();
-
+
/**
* Get an Iterator of objects, some of which may implement
* POIFSViewable
@@ -54,7 +54,7 @@ public interface POIFSViewable
* @return an Iterator; may not be null, but may have an empty
* back end store
*/
-
+ @SuppressWarnings("unchecked")
public Iterator getViewableIterator();
/**
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java Thu Dec 30 02:35:06 2010
@@ -31,7 +31,7 @@ import org.apache.poi.poifs.property.Pro
import org.apache.poi.poifs.property.PropertyTable;
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
import org.apache.poi.poifs.storage.BlockList;
-import org.apache.poi.poifs.storage.HeaderBlockReader;
+import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.poifs.storage.RawDataBlockList;
import org.apache.poi.poifs.storage.SmallBlockTableReader;
@@ -75,29 +75,31 @@ public class POIFSReader
registryClosed = true;
// read the header block from the stream
- HeaderBlockReader header_block_reader = new HeaderBlockReader(stream);
+ HeaderBlock header_block = new HeaderBlock(stream);
// read the rest of the stream into blocks
- RawDataBlockList data_blocks = new RawDataBlockList(stream, header_block_reader.getBigBlockSize());
+ RawDataBlockList data_blocks = new RawDataBlockList(stream, header_block.getBigBlockSize());
// set up the block allocation table (necessary for the
// data_blocks to be manageable
- new BlockAllocationTableReader(header_block_reader.getBATCount(),
- header_block_reader.getBATArray(),
- header_block_reader.getXBATCount(),
- header_block_reader.getXBATIndex(),
+ new BlockAllocationTableReader(header_block.getBigBlockSize(),
+ header_block.getBATCount(),
+ header_block.getBATArray(),
+ header_block.getXBATCount(),
+ header_block.getXBATIndex(),
data_blocks);
// get property table from the document
PropertyTable properties =
- new PropertyTable(header_block_reader.getPropertyStart(),
- data_blocks);
+ new PropertyTable(header_block, data_blocks);
// process documents
processProperties(SmallBlockTableReader
- .getSmallDocumentBlocks(data_blocks, properties
- .getRoot(), header_block_reader
- .getSBATStart()), data_blocks, properties.getRoot()
+ .getSmallDocumentBlocks(
+ header_block.getBigBlockSize(),
+ data_blocks, properties.getRoot(),
+ header_block.getSBATStart()),
+ data_blocks, properties.getRoot()
.getChildren(), new POIFSDocumentPath());
}
@@ -245,13 +247,13 @@ public class POIFSReader
{
document =
new POIFSDocument(name, small_blocks
- .fetchBlocks(startBlock), size);
+ .fetchBlocks(startBlock, -1), size);
}
else
{
document =
new POIFSDocument(name, big_blocks
- .fetchBlocks(startBlock), size);
+ .fetchBlocks(startBlock, -1), size);
}
while (listeners.hasNext())
{
@@ -270,11 +272,11 @@ public class POIFSReader
// consume the document's data and discard it
if (property.shouldUseSmallBlocks())
{
- small_blocks.fetchBlocks(startBlock);
+ small_blocks.fetchBlocks(startBlock, -1);
}
else
{
- big_blocks.fetchBlocks(startBlock);
+ big_blocks.fetchBlocks(startBlock, -1);
}
}
}
Added: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/filesystem/BlockStore.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/filesystem/BlockStore.java?rev=1053791&view=auto
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/filesystem/BlockStore.java (added)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/filesystem/BlockStore.java Thu Dec 30 02:35:06 2010
@@ -0,0 +1,105 @@
+
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.poifs.filesystem;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.poi.poifs.storage.BATBlock.BATBlockAndIndex;
+
+/**
+ * This abstract class describes a way to read, store, chain
+ * and free a series of blocks (be they Big or Small ones)
+ */
+public abstract class BlockStore {
+ /**
+ * Returns the size of the blocks managed through the block store.
+ */
+ protected abstract int getBlockStoreBlockSize();
+
+ /**
+ * Load the block at the given offset.
+ */
+ protected abstract ByteBuffer getBlockAt(final int offset) throws IOException;
+
+ /**
+ * Extends the file if required to hold blocks up to
+ * the specified offset, and return the block from there.
+ */
+ protected abstract ByteBuffer createBlockIfNeeded(final int offset) throws IOException;
+
+ /**
+ * Returns the BATBlock that handles the specified offset,
+ * and the relative index within it
+ */
+ protected abstract BATBlockAndIndex getBATBlockAndIndex(final int offset);
+
+ /**
+ * Works out what block follows the specified one.
+ */
+ protected abstract int getNextBlock(final int offset);
+
+ /**
+ * Changes the record of what block follows the specified one.
+ */
+ protected abstract void setNextBlock(final int offset, final int nextBlock);
+
+ /**
+ * Finds a free block, and returns its offset.
+ * This method will extend the file/stream if needed, and if doing
+ * so, allocate new FAT blocks to address the extra space.
+ */
+ protected abstract int getFreeBlock() throws IOException;
+
+ /**
+ * Creates a Detector for loops in the chain
+ */
+ protected abstract ChainLoopDetector getChainLoopDetector() throws IOException;
+
+ /**
+ * Used to detect if a chain has a loop in it, so
+ * we can bail out with an error rather than
+ * spinning away for ever...
+ */
+ protected class ChainLoopDetector {
+ private boolean[] used_blocks;
+ protected ChainLoopDetector(long rawSize) {
+ int numBlocks = (int)Math.ceil( rawSize / getBlockStoreBlockSize() );
+ used_blocks = new boolean[numBlocks];
+ }
+ protected void claim(int offset) {
+ if(offset >= used_blocks.length) {
+ // They're writing, and have had new blocks requested
+ // for the write to proceed. That means they're into
+ // blocks we've allocated for them, so are safe
+ return;
+ }
+
+ // Claiming an existing block, ensure there's no loop
+ if(used_blocks[offset]) {
+ throw new IllegalStateException(
+ "Potential loop detected - Block " + offset +
+ " was already claimed but was just requested again"
+ );
+ }
+ used_blocks[offset] = true;
+ }
+ }
+}
+
Modified: poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java (original)
+++ poi/branches/NIO_32_BRANCH/src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java Thu Dec 30 02:35:06 2010
@@ -33,7 +33,7 @@ import org.apache.poi.hpsf.ClassID;
*/
public interface DirectoryEntry
- extends Entry
+ extends Entry, Iterable<Entry>
{
/**
@@ -47,7 +47,7 @@ public interface DirectoryEntry
* implementations of Entry.
*/
- public Iterator getEntries();
+ public Iterator<Entry> getEntries();
/**
* is this DirectoryEntry empty?
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org