From c47c780b63abf187b71894d99990e232c3d3df3a Mon Sep 17 00:00:00 2001
From: Andreas Beeker The number of bytes occupied by this object in the byte
+ * stream. The bytes making out the class ID in correct order,
* i.e. big-endian. Creates a {@link ClassID} and initializes its value with
* 0x00 bytes.
false
.
*/
@Override
- public boolean equals(final Object o)
- {
- if (o == null || !(o instanceof ClassID))
+ public boolean equals(final Object o) {
+ if (o == null || !(o instanceof ClassID)) {
return false;
+ }
final ClassID cid = (ClassID) o;
- if (bytes.length != cid.bytes.length)
+ if (bytes.length != cid.bytes.length) {
return false;
- for (int i = 0; i < bytes.length; i++)
- if (bytes[i] != cid.bytes[i])
+ }
+ for (int i = 0; i < bytes.length; i++) {
+ if (bytes[i] != cid.bytes[i]) {
return false;
+ }
+ }
return true;
}
@@ -236,8 +227,7 @@ public class ClassID
* @see Object#hashCode()
*/
@Override
- public int hashCode()
- {
+ public int hashCode() {
return new String(bytes, StringUtil.UTF8).hashCode();
}
@@ -248,18 +238,16 @@ public class ClassID
* @return String representation of the Class ID represented by this object.
*/
@Override
- public String toString()
- {
- StringBuffer sbClassId = new StringBuffer(38);
+ public String toString() {
+ StringBuilder sbClassId = new StringBuilder(38);
sbClassId.append('{');
- for (int i = 0; i < 16; i++)
- {
+ for (int i = 0; i < LENGTH; i++) {
sbClassId.append(HexDump.toHex(bytes[i]));
- if (i == 3 || i == 5 || i == 7 || i == 9)
+ if (i == 3 || i == 5 || i == 7 || i == 9) {
sbClassId.append('-');
+ }
}
sbClassId.append('}');
return sbClassId.toString();
}
-
}
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/HDGFLZWCompressor.java b/src/scratchpad/src/org/apache/poi/hdgf/HDGFLZWCompressor.java
index 53215de88e..d79c43c87b 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/HDGFLZWCompressor.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/HDGFLZWCompressor.java
@@ -30,35 +30,35 @@ import java.io.OutputStream;
* TODO Fix this, as it starts to go wrong on
* large streams
*/
-final class HDGFLZWCompressor {
+/* package */ final class HDGFLZWCompressor {
// We use 12 bit codes:
// * 0-255 are real bytes
// * 256-4095 are the substring codes
// Java handily initialises our buffer / dictionary
// to all zeros
- byte[] dict = new byte[4096];
+ private byte[] dict = new byte[4096];
// The next block of data to be written out, minus
// its mask byte
- byte[] buffer = new byte[16];
+ private byte[] buffer = new byte[16];
// And how long it is
// (Un-compressed codes are 1 byte each, compressed codes
// are two)
- int bufferLen = 0;
+ private int bufferLen = 0;
// The raw length of a code is limited to 4 bits + 2
- byte[] rawCode = new byte[18];
+ private byte[] rawCode = new byte[18];
// And how much we're using
- int rawCodeLen = 0;
+ private int rawCodeLen = 0;
// How far through the input and output streams we are
- int posInp = 0;
- int posOut = 0;
+ private int posInp = 0;
+ private int posOut = 0;
// What the next mask byte to output will be
- int nextMask = 0;
+ private int nextMask = 0;
// And how many bits we've already set
- int maskBitsSet = 0;
+ private int maskBitsSet = 0;
public HDGFLZWCompressor() {}
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java
index 23ec352783..ce92ac8dc9 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java
@@ -95,7 +95,7 @@ public final class Chunk {
public int getOnDiskSize() {
int size = header.getSizeInBytes() + contents.length;
if(trailer != null) {
- size += trailer.trailerData.length;
+ size += trailer.getTrailerData().length;
}
if(separator != null) {
size += separator.separatorData.length;
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
index 4b69576ee3..642cdf488e 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
@@ -130,7 +130,7 @@ public final class ChunkFactory {
ChunkHeader header =
ChunkHeader.createChunkHeader(version, data, offset);
// Sanity check
- if(header.length < 0) {
+ if(header.getLength() < 0) {
throw new IllegalArgumentException("Found a chunk with a negative length, which isn't allowed");
}
@@ -144,14 +144,14 @@ public final class ChunkFactory {
"Header called for " + header.getLength() +" bytes, but that would take us past the end of the data!");
endOfDataPos = data.length;
- header.length = data.length - offset - header.getSizeInBytes();
+ header.setLength(data.length - offset - header.getSizeInBytes());
if(header.hasTrailer()) {
- header.length -= 8;
+ header.setLength(header.getLength() - 8);
endOfDataPos -= 8;
}
if(header.hasSeparator()) {
- header.length -= 4;
+ header.setLength(header.getLength() - 4);
endOfDataPos -= 4;
}
}
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java
index 4b38366f7b..df7c9940bd 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java
@@ -25,10 +25,10 @@ import java.nio.charset.Charset;
* A chunk header
*/
public abstract class ChunkHeader {
- protected int type;
- protected int id;
- protected int length;
- protected int unknown1;
+ private int type;
+ private int id;
+ private int length;
+ private int unknown1;
/**
* Creates the appropriate ChunkHeader for the Chunk Header at
@@ -42,23 +42,23 @@ public abstract class ChunkHeader {
} else {
ch = new ChunkHeaderV6();
}
- ch.type = (int)LittleEndian.getUInt(data, offset + 0);
- ch.id = (int)LittleEndian.getUInt(data, offset + 4);
- ch.unknown1 = (int)LittleEndian.getUInt(data, offset + 8);
- ch.length = (int)LittleEndian.getUInt(data, offset + 12);
- ch.unknown2 = LittleEndian.getShort(data, offset + 16);
- ch.unknown3 = LittleEndian.getUByte(data, offset + 18);
+ ch.setType((int)LittleEndian.getUInt(data, offset + 0));
+ ch.setId((int)LittleEndian.getUInt(data, offset + 4));
+ ch.setUnknown1((int)LittleEndian.getUInt(data, offset + 8));
+ ch.setLength((int)LittleEndian.getUInt(data, offset + 12));
+ ch.setUnknown2(LittleEndian.getShort(data, offset + 16));
+ ch.setUnknown3(LittleEndian.getUByte(data, offset + 18));
return ch;
} else if(documentVersion == 5 || documentVersion == 4) {
ChunkHeaderV4V5 ch = new ChunkHeaderV4V5();
- ch.type = LittleEndian.getShort(data, offset + 0);
- ch.id = LittleEndian.getShort(data, offset + 2);
- ch.unknown2 = LittleEndian.getUByte(data, offset + 4);
- ch.unknown3 = LittleEndian.getUByte(data, offset + 5);
- ch.unknown1 = LittleEndian.getShort(data, offset + 6);
- ch.length = (int)LittleEndian.getUInt(data, offset + 8);
+ ch.setType(LittleEndian.getShort(data, offset + 0));
+ ch.setId(LittleEndian.getShort(data, offset + 2));
+ ch.setUnknown2(LittleEndian.getUByte(data, offset + 4));
+ ch.setUnknown3(LittleEndian.getUByte(data, offset + 5));
+ ch.setUnknown1(LittleEndian.getShort(data, offset + 6));
+ ch.setLength((int)LittleEndian.getUInt(data, offset + 8));
return ch;
} else {
@@ -90,6 +90,7 @@ public abstract class ChunkHeader {
public int getId() {
return id;
}
+
/**
* Returns the length of the trunk, excluding the length
* of the header, trailer or separator.
@@ -97,6 +98,7 @@ public abstract class ChunkHeader {
public int getLength() {
return length;
}
+
/**
* Returns the type of the chunk, which affects the
* mandatory information
@@ -104,7 +106,24 @@ public abstract class ChunkHeader {
public int getType() {
return type;
}
+
public int getUnknown1() {
return unknown1;
}
+
+ void setType(int type) {
+ this.type = type;
+ }
+
+ void setId(int id) {
+ this.id = id;
+ }
+
+ void setLength(int length) {
+ this.length = length;
+ }
+
+ void setUnknown1(int unknown1) {
+ this.unknown1 = unknown1;
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java
index b3d84aa503..ca243c9963 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java
@@ -23,30 +23,45 @@ import java.nio.charset.Charset;
* A chunk header from v11+
*/
public final class ChunkHeaderV11 extends ChunkHeaderV6 {
- /**
- * Does the chunk have a separator?
- */
- public boolean hasSeparator() {
- // For some reason, there are two types that don't have a
- // separator despite the flags that indicate they do
- if(type == 0x1f || type == 0xc9) { return false; }
-
- // If there's a trailer, there's a separator
- if(hasTrailer()) { return true; }
-
- if(unknown2 == 2 && unknown3 == 0x55) { return true; }
- if(unknown2 == 2 && unknown3 == 0x54 && type == 0xa9) { return true; }
- if(unknown2 == 2 && unknown3 == 0x54 && type == 0xaa) { return true; }
- if(unknown2 == 2 && unknown3 == 0x54 && type == 0xb4) { return true; }
- if(unknown2 == 2 && unknown3 == 0x54 && type == 0xb6) { return true; }
- if(unknown2 == 3 && unknown3 != 0x50) { return true; }
- if(type == 0x69) { return true; }
-
- return false;
- }
-
- @Override
- public Charset getChunkCharset() {
- return Charset.forName("UTF-16LE");
- }
+ /**
+ * Does the chunk have a separator?
+ */
+ public boolean hasSeparator() {
+ short unknown2 = getUnknown2();
+ short unknown3 = getUnknown3();
+
+ switch (getType()) {
+ case 0x1f: case 0xc9:
+ // For some reason, there are two types that don't have a
+ // separator despite the flags that indicate they do
+ return false;
+
+ case 0x69:
+ return true;
+
+ case 0xa9: case 0xaa: case 0xb4: case 0xb6:
+ if (unknown2 == 2 && unknown3 == 0x54) {
+ return true;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if (
+ (unknown2 == 2 && unknown3 == 0x55) ||
+ (unknown2 == 3 && unknown3 != 0x50)
+ ) {
+ return true;
+ }
+
+ // If there's a trailer, there's a separator
+ return hasTrailer();
+ }
+
+ @Override
+ public Charset getChunkCharset() {
+ return Charset.forName("UTF-16LE");
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java
index bba6a87ddd..b4eb9d83d7 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java
@@ -23,8 +23,8 @@ import java.nio.charset.Charset;
* A chunk header from v4 or v5
*/
public final class ChunkHeaderV4V5 extends ChunkHeader {
- protected short unknown2;
- protected short unknown3;
+ private short unknown2;
+ private short unknown3;
public short getUnknown2() {
return unknown2;
@@ -61,4 +61,12 @@ public final class ChunkHeaderV4V5 extends ChunkHeader {
public Charset getChunkCharset() {
return Charset.forName("ASCII");
}
+
+ void setUnknown2(short unknown2) {
+ this.unknown2 = unknown2;
+ }
+
+ void setUnknown3(short unknown3) {
+ this.unknown3 = unknown3;
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java
index 96546c780b..2a221a7028 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java
@@ -23,8 +23,8 @@ import java.nio.charset.Charset;
* A chunk header from v6
*/
public class ChunkHeaderV6 extends ChunkHeader {
- protected short unknown2;
- protected short unknown3;
+ private short unknown2;
+ private short unknown3;
public short getUnknown2() {
return unknown2;
@@ -45,15 +45,15 @@ public class ChunkHeaderV6 extends ChunkHeader {
* Does the chunk have a trailer?
*/
public boolean hasTrailer() {
- if(unknown1 != 0 || type == 0x71 || type == 0x70) {
- return true;
- }
- if(type == 0x6b || type == 0x6a || type == 0x69 || type == 0x66
- || type == 0x65 || type == 0x2c) {
- return true;
- }
- return false;
+ switch (getType()) {
+ case 0x2c: case 0x65: case 0x66: case 0x69:
+ case 0x6a: case 0x6b: case 0x70: case 0x71:
+ return true;
+ default:
+ return (getUnknown1() != 0);
+ }
}
+
/**
* Does the chunk have a separator?
*/
@@ -66,4 +66,12 @@ public class ChunkHeaderV6 extends ChunkHeader {
public Charset getChunkCharset() {
return Charset.forName("ASCII");
}
+
+ void setUnknown2(short unknown2) {
+ this.unknown2 = unknown2;
+ }
+
+ void setUnknown3(short unknown3) {
+ this.unknown3 = unknown3;
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java
index ad3441d88d..a4c9e178c2 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java
@@ -21,7 +21,7 @@ package org.apache.poi.hdgf.chunks;
* A trailer that follows a chunk
*/
public final class ChunkTrailer {
- protected byte[] trailerData;
+ private byte[] trailerData;
public ChunkTrailer(byte[] data, int offset) {
trailerData = new byte[8];
@@ -31,4 +31,8 @@ public final class ChunkTrailer {
public String toString() {
return "