private static byte[] readTail(byte[] expectedTail, LittleEndianInput in) { byte[] result = new byte[TAIL_SIZE]; in.readFully(result); // if (false) { // Quite a few examples in the unit tests which don't have the exact expected tail // for (int i = 0; i < expectedTail.length; i++) { // if (expectedTail[i] != result[i]) { // logger.log( POILogger.ERROR, "Mismatch in tail byte [" + i + "]" // + "expected " + (expectedTail[i] & 0xFF) + " but got " + (result[i] & 0xFF)); // } // } // } return result; } private static void writeTail(byte[] tail, LittleEndianOutput out) {
public UnknownSubRecord(LittleEndianInput in, int sid, int size) { _sid = sid; byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); in.readFully(buf); _data = buf; } @Override
private static byte[] readRawData(LittleEndianInput in, int size) { if (size < 0) { throw new IllegalArgumentException("Negative size (" + size + ")"); } if (size == 0) { return EMPTY_BYTE_ARRAY; } byte[] result = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); in.readFully(result); return result; }
public static String readCompressedUnicode(LittleEndianInput in, int nChars) { byte[] buf = IOUtils.safelyAllocate(nChars, MAX_RECORD_LENGTH); in.readFully(buf); return new String(buf, ISO_8859_1); }
public static String readUnicodeLE(LittleEndianInput in, int nChars) { byte[] bytes = IOUtils.safelyAllocate(nChars * 2, MAX_RECORD_LENGTH); in.readFully(bytes); return new String(bytes, UTF16LE); }
public GroupMarkerSubRecord(LittleEndianInput in, int size) { byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); in.readFully(buf); reserved = buf; }
protected XOREncryptionVerifier(LittleEndianInput is) { /** * key (2 bytes): An unsigned integer that specifies the obfuscation key. * See [MS-OFFCRYPTO], 2.3.6.2 section, the first step of initializing XOR * array where it describes the generation of 16-bit XorKey value. */ byte key[] = new byte[2]; is.readFully(key); setEncryptedKey(key); /** * verificationBytes (2 bytes): An unsigned integer that specifies * the password verification identifier. */ byte verifier[] = new byte[2]; is.readFully(verifier); setEncryptedVerifier(verifier); }
public void read( LittleEndianInput lei ) { int size = lei.readInt(); _value = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); if ( size > 0 ) { lei.readFully(_value); } } }
public FtCblsSubRecord(LittleEndianInput in, int size) { if (size != ENCODED_SIZE) { throw new RecordFormatException("Unexpected size (" + size + ")"); } //just grab the raw data byte[] buf = IOUtils.safelyAllocate(size, ENCODED_SIZE); in.readFully(buf); reserved = buf; }
/** * When there are no array constants present, <tt>encodedTokenLen</tt>==<tt>totalEncodedLen</tt> * @param encodedTokenLen number of bytes in the stream taken by the plain formula tokens * @param totalEncodedLen the total number of bytes in the formula (includes trailing encoding * for array constants, but does not include 2 bytes for initial <tt>ushort encodedTokenLen</tt> field. * @return A new formula object as read from the stream. Possibly empty, never <code>null</code>. */ public static Formula read(int encodedTokenLen, LittleEndianInput in, int totalEncodedLen) { byte[] byteEncoding = IOUtils.safelyAllocate(totalEncodedLen, MAX_ENCODED_LEN); in.readFully(byteEncoding); return new Formula(byteEncoding, encodedTokenLen); }
/** * Read the record data from the supplied <code>RecordInputStream</code> * * @param in the input to read from * @param size the provided size - must be 22 */ public NoteStructureSubRecord(LittleEndianInput in, int size) { if (size != ENCODED_SIZE) { throw new RecordFormatException("Unexpected size (" + size + ")"); } //just grab the raw data byte[] buf = IOUtils.safelyAllocate(size, ENCODED_SIZE); in.readFully(buf); reserved = buf; }
protected BinaryRC4EncryptionVerifier(LittleEndianInput is) { byte salt[] = new byte[16]; is.readFully(salt); setSalt(salt); byte encryptedVerifier[] = new byte[16]; is.readFully(encryptedVerifier); setEncryptedVerifier(encryptedVerifier); byte encryptedVerifierHash[] = new byte[16]; is.readFully(encryptedVerifierHash); setEncryptedVerifierHash(encryptedVerifierHash); setSpinCount(-1); setCipherAlgorithm(CipherAlgorithm.rc4); setChainingMode(null); setEncryptedKey(null); setHashAlgorithm(HashAlgorithm.md5); }
public static String readUtf8LPP4(LittleEndianInput is) { int length = is.readInt(); if (length == 0 || length == 4) { /* int skip = */ is.readInt(); return length == 0 ? null : ""; } byte data[] = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH); is.readFully(data); // Padding (variable): A set of bytes that MUST be of correct size such that the size of the UTF-8-LP-P4 // structure is a multiple of 4 bytes. If Padding is present, each byte MUST be 0x00. If // the length is exactly 0x00000000, this specifies a null string, and the entire structure uses // exactly 4 bytes. If the length is exactly 0x00000004, this specifies an empty string, and the // entire structure also uses exactly 4 bytes int scratchedBytes = length%4; if (scratchedBytes > 0) { for (int i=0; i<(4-scratchedBytes); i++) { is.readByte(); } } return new String(data, 0, data.length, StandardCharsets.UTF_8); }
protected void readFully(byte[] buf, int off, int len, boolean isPlain) { int origLen = len; if (buf == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > buf.length - off) { throw new IndexOutOfBoundsException(); } while (len > 0) { int nextChunk = Math.min(available(),len); if (nextChunk == 0) { if (!hasNextRecord()) { throw new RecordFormatException("Can't read the remaining "+len+" bytes of the requested "+origLen+" bytes. No further record exists."); } else { nextRecord(); nextChunk = Math.min(available(),len); assert(nextChunk > 0); } } checkRecordPosition(nextChunk); if (isPlain) { _dataInput.readPlain(buf, off, nextChunk); } else { _dataInput.readFully(buf, off, nextChunk); } _currentDataOffset+=nextChunk; off += nextChunk; len -= nextChunk; } }
public ExtendedColor(LittleEndianInput in) { type = in.readInt(); if (type == TYPE_INDEXED) { colorIndex = in.readInt(); } else if (type == TYPE_RGB) { rgba = new byte[4]; in.readFully(rgba); } else if (type == TYPE_THEMED) { themeIndex = in.readInt(); } else { // Ignored in.readInt(); } tint = in.readDouble(); }
protected StandardEncryptionVerifier(LittleEndianInput is, StandardEncryptionHeader header) { int saltSize = is.readInt(); if (saltSize!=16) { throw new RuntimeException("Salt size != 16 !?"); } byte salt[] = new byte[16]; is.readFully(salt); setSalt(salt); byte encryptedVerifier[] = new byte[16]; is.readFully(encryptedVerifier); setEncryptedVerifier(encryptedVerifier); verifierHashSize = is.readInt(); byte encryptedVerifierHash[] = new byte[header.getCipherAlgorithm().encryptedVerifierHashLength]; is.readFully(encryptedVerifierHash); setEncryptedVerifierHash(encryptedVerifierHash); setSpinCount(SPIN_COUNT); setCipherAlgorithm(header.getCipherAlgorithm()); setChainingMode(header.getChainingMode()); setEncryptedKey(null); setHashAlgorithm(header.getHashAlgorithm()); }
public GroupMarkerSubRecord(LittleEndianInput in, int size) { byte[] buf = new byte[size]; in.readFully(buf); reserved = buf; }
public static String readUnicodeLE(LittleEndianInput in, int nChars) { byte[] bytes = IOUtils.safelyAllocate(nChars * 2, MAX_RECORD_LENGTH); in.readFully(bytes); return new String(bytes, UTF16LE); }
public UnknownSubRecord(LittleEndianInput in, int sid, int size) { _sid = sid; byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); in.readFully(buf); _data = buf; } @Override
public FtCblsSubRecord(LittleEndianInput in, int size) { if (size != ENCODED_SIZE) { throw new RecordFormatException("Unexpected size (" + size + ")"); } //just grab the raw data byte[] buf = IOUtils.safelyAllocate(size, ENCODED_SIZE); in.readFully(buf); reserved = buf; }