Search in sources :

Example 11 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class ClipboardData method toByteArray.

byte[] toByteArray() {
    byte[] result = new byte[LittleEndianConsts.INT_SIZE * 2 + _value.length];
    LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(result, 0);
    try {
        bos.writeInt(LittleEndianConsts.INT_SIZE + _value.length);
        bos.writeInt(_format);
        bos.write(_value);
        return result;
    } finally {
        IOUtils.closeQuietly(bos);
    }
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream)

Example 12 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class ContinuableRecord method serialize.

public final int serialize(int offset, byte[] data) {
    LittleEndianOutput leo = new LittleEndianByteArrayOutputStream(data, offset);
    ContinuableRecordOutput out = new ContinuableRecordOutput(leo, getSid());
    serialize(out);
    out.terminate();
    return out.getTotalSize();
}
Also used : LittleEndianOutput(org.apache.poi.util.LittleEndianOutput) LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream)

Example 13 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class HSLFSlideShowEncrypted method encryptPicture.

protected void encryptPicture(byte[] pictstream, int offset) {
    if (dea == null) {
        return;
    }
    encryptInit();
    // NOSONAR
    LittleEndianByteArrayOutputStream los = new LittleEndianByteArrayOutputStream(pictstream, offset);
    ChunkedCipherOutputStream ccos = null;
    try {
        enc.setChunkSize(-1);
        ccos = enc.getDataStream(los, 0);
        int recInst = fieldRecInst.getValue(LittleEndian.getUShort(pictstream, offset));
        int recType = LittleEndian.getUShort(pictstream, offset + 2);
        final int rlen = (int) LittleEndian.getUInt(pictstream, offset + 4);
        ccos.write(pictstream, offset, 8);
        ccos.flush();
        offset += 8;
        int endOffset = offset + rlen;
        if (recType == 0xF007) {
            // TOOD: get a real example file ... to actual test the FBSE entry
            // not sure where the foDelay block is
            // File BLIP Store Entry (FBSE)
            int cbName = LittleEndian.getUShort(pictstream, offset + 33);
            for (int part : BLIB_STORE_ENTRY_PARTS) {
                ccos.write(pictstream, offset, part);
                ccos.flush();
                offset += part;
            }
            if (cbName > 0) {
                ccos.write(pictstream, offset, cbName);
                ccos.flush();
                offset += cbName;
            }
            if (offset == endOffset) {
                // no embedded blip
                return;
            }
            // fall through, read embedded blip now
            // update header data
            recInst = fieldRecInst.getValue(LittleEndian.getUShort(pictstream, offset));
            recType = LittleEndian.getUShort(pictstream, offset + 2);
            ccos.write(pictstream, offset, 8);
            ccos.flush();
            offset += 8;
        }
        int rgbUidCnt = (recInst == 0x217 || recInst == 0x3D5 || recInst == 0x46B || recInst == 0x543 || recInst == 0x6E1 || recInst == 0x6E3 || recInst == 0x6E5 || recInst == 0x7A9) ? 2 : 1;
        for (int i = 0; i < rgbUidCnt; i++) {
            // rgbUid 1/2
            ccos.write(pictstream, offset, 16);
            ccos.flush();
            offset += 16;
        }
        if (recType == 0xF01A || recType == 0XF01B || recType == 0XF01C) {
            // metafileHeader
            ccos.write(pictstream, offset, 34);
            offset += 34;
            ccos.flush();
        } else {
            // tag
            ccos.write(pictstream, offset, 1);
            offset += 1;
            ccos.flush();
        }
        int blipLen = endOffset - offset;
        ccos.write(pictstream, offset, blipLen);
        ccos.flush();
    } catch (Exception e) {
        throw new EncryptedPowerPointFileException(e);
    } finally {
        IOUtils.closeQuietly(ccos);
        IOUtils.closeQuietly(los);
    }
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) ChunkedCipherOutputStream(org.apache.poi.poifs.crypt.ChunkedCipherOutputStream) EncryptedPowerPointFileException(org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException) EncryptedPowerPointFileException(org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) CorruptPowerPointFileException(org.apache.poi.hslf.exceptions.CorruptPowerPointFileException) EncryptedDocumentException(org.apache.poi.EncryptedDocumentException)

Example 14 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class TestHyperlinkRecord method testGUID.

@Test
public void testGUID() {
    GUID g;
    g = GUID.parse("3F2504E0-4F89-11D3-9A0C-0305E82C3301");
    confirmGUID(g, 0x3F2504E0, 0x4F89, 0x11D3, 0x9A0C0305E82C3301L);
    assertEquals("3F2504E0-4F89-11D3-9A0C-0305E82C3301", g.formatAsString());
    g = GUID.parse("13579BDF-0246-8ACE-0123-456789ABCDEF");
    confirmGUID(g, 0x13579BDF, 0x0246, 0x8ACE, 0x0123456789ABCDEFL);
    assertEquals("13579BDF-0246-8ACE-0123-456789ABCDEF", g.formatAsString());
    byte[] buf = new byte[16];
    g.serialize(new LittleEndianByteArrayOutputStream(buf, 0));
    String expectedDump = "[DF, 9B, 57, 13, 46, 02, CE, 8A, 01, 23, 45, 67, 89, AB, CD, EF]";
    assertEquals(expectedDump, HexDump.toHex(buf));
    // STD Moniker
    g = createFromStreamDump("[D0, C9, EA, 79, F9, BA, CE, 11, 8C, 82, 00, AA, 00, 4B, A9, 0B]");
    assertEquals("79EAC9D0-BAF9-11CE-8C82-00AA004BA90B", g.formatAsString());
    // URL Moniker
    g = createFromStreamDump("[E0, C9, EA, 79, F9, BA, CE, 11, 8C, 82, 00, AA, 00, 4B, A9, 0B]");
    assertEquals("79EAC9E0-BAF9-11CE-8C82-00AA004BA90B", g.formatAsString());
    // File Moniker
    g = createFromStreamDump("[03, 03, 00, 00, 00, 00, 00, 00, C0, 00, 00, 00, 00, 00, 00, 46]");
    assertEquals("00000303-0000-0000-C000-000000000046", g.formatAsString());
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) GUID(org.apache.poi.hssf.record.HyperlinkRecord.GUID) Test(org.junit.Test)

Example 15 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class StandardEncryptor method createEncryptionInfoEntry.

protected void createEncryptionInfoEntry(DirectoryNode dir) throws IOException {
    final EncryptionInfo info = getEncryptionInfo();
    final StandardEncryptionHeader header = (StandardEncryptionHeader) info.getHeader();
    final StandardEncryptionVerifier verifier = (StandardEncryptionVerifier) info.getVerifier();
    EncryptionRecord er = new EncryptionRecord() {

        @Override
        public void write(LittleEndianByteArrayOutputStream bos) {
            bos.writeShort(info.getVersionMajor());
            bos.writeShort(info.getVersionMinor());
            bos.writeInt(info.getEncryptionFlags());
            header.write(bos);
            verifier.write(bos);
        }
    };
    createEncryptionEntry(dir, "EncryptionInfo", er);
// TODO: any properties???
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo)

Aggregations

LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)20 EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)5 IOException (java.io.IOException)4 EncryptionInfo (org.apache.poi.poifs.crypt.EncryptionInfo)4 EncryptionRecord (org.apache.poi.poifs.crypt.standard.EncryptionRecord)3 Test (org.junit.Test)3 ChunkedCipherOutputStream (org.apache.poi.poifs.crypt.ChunkedCipherOutputStream)2 CryptoAPIEncryptionHeader (org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader)2 CryptoAPIEncryptionVerifier (org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionVerifier)2 LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)2 EncryptionDocument (com.microsoft.schemas.office.x2006.encryption.EncryptionDocument)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 HashMap (java.util.HashMap)1 NoSuchElementException (java.util.NoSuchElementException)1 AssertionFailedError (junit.framework.AssertionFailedError)1 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1