aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/util/LittleEndianInputStream.java
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2014-12-25 01:56:29 +0000
committerAndreas Beeker <kiwiwings@apache.org>2014-12-25 01:56:29 +0000
commit0839a097e36d53bef39743192e1a1ae7fe8af2cf (patch)
tree4e0754c3bc51248488edac80763755c13e5039f9 /src/java/org/apache/poi/util/LittleEndianInputStream.java
parent2668385b172e208a0129ae4fe770da3e0ce3e69d (diff)
downloadpoi-0839a097e36d53bef39743192e1a1ae7fe8af2cf.tar.gz
poi-0839a097e36d53bef39743192e1a1ae7fe8af2cf.zip
- Support for Office Binary Document RC4 CryptoAPI Encryption for HSLF
- Support for Office Binary Document RC4 Encryption - use LittleEndian class in LittleEndianInputStream - add normalize method for HSLF, to remove edit history, which is also necessary for encryption support - update PersistDirectoryEntry handling in PersistPtrHolder to recognize groups while serializing - deprecated PersistPtrHolder.getSlideOffsetDataLocationsLookup() - throws now UnsupportedOperationException, as this wasn't used outside the scope of the class and was quite internal logic of PersistPtrHolder git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647867 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/util/LittleEndianInputStream.java')
-rw-r--r--src/java/org/apache/poi/util/LittleEndianInputStream.java102
1 files changed, 44 insertions, 58 deletions
diff --git a/src/java/org/apache/poi/util/LittleEndianInputStream.java b/src/java/org/apache/poi/util/LittleEndianInputStream.java
index 1a37964a8f..406570f82f 100644
--- a/src/java/org/apache/poi/util/LittleEndianInputStream.java
+++ b/src/java/org/apache/poi/util/LittleEndianInputStream.java
@@ -21,6 +21,8 @@ import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.poi.util.LittleEndian.BufferUnderrunException;
+
/**
* Wraps an {@link InputStream} providing {@link LittleEndianInput}<p/>
*
@@ -33,6 +35,7 @@ public class LittleEndianInputStream extends FilterInputStream implements Little
public LittleEndianInputStream(InputStream is) {
super(is);
}
+
public int available() {
try {
return super.available();
@@ -40,86 +43,75 @@ public class LittleEndianInputStream extends FilterInputStream implements Little
throw new RuntimeException(e);
}
}
+
public byte readByte() {
return (byte)readUByte();
}
+
public int readUByte() {
- int ch;
+ byte buf[] = new byte[1];
try {
- ch = in.read();
+ checkEOF(read(buf), 1);
} catch (IOException e) {
throw new RuntimeException(e);
}
- checkEOF(ch);
- return ch;
+ return LittleEndian.getUByte(buf);
}
+
public double readDouble() {
return Double.longBitsToDouble(readLong());
}
+
public int readInt() {
- int ch1;
- int ch2;
- int ch3;
- int ch4;
+ byte buf[] = new byte[LittleEndianConsts.INT_SIZE];
try {
- ch1 = in.read();
- ch2 = in.read();
- ch3 = in.read();
- ch4 = in.read();
+ checkEOF(read(buf), buf.length);
} catch (IOException e) {
throw new RuntimeException(e);
}
- checkEOF(ch1 | ch2 | ch3 | ch4);
- return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0);
+ return LittleEndian.getInt(buf);
}
+
+ /**
+ * get an unsigned int value from an InputStream
+ *
+ * @return the unsigned int (32-bit) value
+ * @exception IOException
+ * will be propagated back to the caller
+ * @exception BufferUnderrunException
+ * if the stream cannot provide enough bytes
+ */
+ public long readUInt() {
+ long retNum = readInt();
+ return retNum & 0x00FFFFFFFFl;
+ }
+
public long readLong() {
- int b0;
- int b1;
- int b2;
- int b3;
- int b4;
- int b5;
- int b6;
- int b7;
+ byte buf[] = new byte[LittleEndianConsts.LONG_SIZE];
try {
- b0 = in.read();
- b1 = in.read();
- b2 = in.read();
- b3 = in.read();
- b4 = in.read();
- b5 = in.read();
- b6 = in.read();
- b7 = in.read();
+ checkEOF(read(buf), LittleEndianConsts.LONG_SIZE);
} catch (IOException e) {
throw new RuntimeException(e);
}
- checkEOF(b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7);
- return (((long)b7 << 56) +
- ((long)b6 << 48) +
- ((long)b5 << 40) +
- ((long)b4 << 32) +
- ((long)b3 << 24) +
- (b2 << 16) +
- (b1 << 8) +
- (b0 << 0));
+ return LittleEndian.getLong(buf);
}
+
public short readShort() {
return (short)readUShort();
}
+
public int readUShort() {
- int ch1;
- int ch2;
+ byte buf[] = new byte[LittleEndianConsts.SHORT_SIZE];
try {
- ch1 = in.read();
- ch2 = in.read();
+ checkEOF(read(buf), LittleEndianConsts.SHORT_SIZE);
} catch (IOException e) {
throw new RuntimeException(e);
}
- checkEOF(ch1 | ch2);
- return (ch2 << 8) + (ch1 << 0);
+ return LittleEndian.getUShort(buf);
}
- private static void checkEOF(int value) {
- if (value <0) {
+
+ private static void checkEOF(int actualBytes, int expectedBytes) {
+ if (expectedBytes != 0 && (actualBytes == -1 || actualBytes != expectedBytes)) {
throw new RuntimeException("Unexpected end-of-file");
}
}
@@ -129,16 +121,10 @@ public class LittleEndianInputStream extends FilterInputStream implements Little
}
public void readFully(byte[] buf, int off, int len) {
- int max = off+len;
- for(int i=off; i<max; i++) {
- int ch;
- try {
- ch = in.read();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- checkEOF(ch);
- buf[i] = (byte) ch;
- }
+ try {
+ checkEOF(read(buf, off, len), len);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
}