Search in sources :

Example 31 with PushbackInputStream

use of java.io.PushbackInputStream in project poi by apache.

the class TestOfficeXMLException method confirmIsPOIFS.

private void confirmIsPOIFS(String sampleFileName, boolean expectedResult) throws IOException {
    InputStream in = new PushbackInputStream(openSampleStream(sampleFileName), 10);
    try {
        boolean actualResult;
        try {
            actualResult = POIFSFileSystem.hasPOIFSHeader(in);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        assertEquals(expectedResult, actualResult);
    } finally {
        in.close();
    }
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PushbackInputStream(java.io.PushbackInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 32 with PushbackInputStream

use of java.io.PushbackInputStream in project poi by apache.

the class TestOfficeXMLException method testFileCorruptionOPOIFS.

public void testFileCorruptionOPOIFS() throws Exception {
    // create test InputStream
    byte[] testData = { (byte) 1, (byte) 2, (byte) 3 };
    InputStream testInput = new ByteArrayInputStream(testData);
    // detect header
    InputStream in = new PushbackInputStream(testInput, 10);
    assertFalse(OPOIFSFileSystem.hasPOIFSHeader(in));
    // check if InputStream is still intact
    byte[] test = new byte[3];
    in.read(test);
    assertTrue(Arrays.equals(testData, test));
    assertEquals(-1, in.read());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PushbackInputStream(java.io.PushbackInputStream) InputStream(java.io.InputStream)

Example 33 with PushbackInputStream

use of java.io.PushbackInputStream in project poi by apache.

the class TestOfficeXMLException method testFileCorruption.

public void testFileCorruption() throws Exception {
    // create test InputStream
    byte[] testData = { (byte) 1, (byte) 2, (byte) 3 };
    InputStream testInput = new ByteArrayInputStream(testData);
    // detect header
    InputStream in = new PushbackInputStream(testInput, 10);
    assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
    // check if InputStream is still intact
    byte[] test = new byte[3];
    in.read(test);
    assertTrue(Arrays.equals(testData, test));
    assertEquals(-1, in.read());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PushbackInputStream(java.io.PushbackInputStream) InputStream(java.io.InputStream)

Example 34 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

the class CertificateFactory method engineGenerateCertificate.

/**
     * Generates a certificate object and initializes it with the data
     * read from the input stream inStream.
     */
public java.security.cert.Certificate engineGenerateCertificate(InputStream in) throws CertificateException {
    if (currentStream == null) {
        currentStream = in;
        sData = null;
        sDataObjectCount = 0;
    } else if (// reset if input stream has changed
    currentStream != in) {
        currentStream = in;
        sData = null;
        sDataObjectCount = 0;
    }
    try {
        if (sData != null) {
            if (sDataObjectCount != sData.size()) {
                return getCertificate();
            } else {
                sData = null;
                sDataObjectCount = 0;
                return null;
            }
        }
        PushbackInputStream pis = new PushbackInputStream(in);
        int tag = pis.read();
        if (tag == -1) {
            return null;
        }
        pis.unread(tag);
        if (// assume ascii PEM encoded.
        tag != 0x30) {
            return readPEMCertificate(pis);
        } else {
            return readDERCertificate(new ASN1InputStream(pis));
        }
    } catch (Exception e) {
        throw new ExCertificateException(e);
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PushbackInputStream(java.io.PushbackInputStream) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException)

Example 35 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

the class CertificateFactory method engineGenerateCRL.

/**
     * Generates a certificate revocation list (CRL) object and initializes
     * it with the data read from the input stream inStream.
     */
public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
    if (currentCrlStream == null) {
        currentCrlStream = inStream;
        sCrlData = null;
        sCrlDataObjectCount = 0;
    } else if (// reset if input stream has changed
    currentCrlStream != inStream) {
        currentCrlStream = inStream;
        sCrlData = null;
        sCrlDataObjectCount = 0;
    }
    try {
        if (sCrlData != null) {
            if (sCrlDataObjectCount != sCrlData.size()) {
                return getCRL();
            } else {
                sCrlData = null;
                sCrlDataObjectCount = 0;
                return null;
            }
        }
        PushbackInputStream pis = new PushbackInputStream(inStream);
        int tag = pis.read();
        if (tag == -1) {
            return null;
        }
        pis.unread(tag);
        if (// assume ascii PEM encoded.
        tag != 0x30) {
            return readPEMCRL(pis);
        } else {
            // lazy evaluate to help processing of large CRLs
            return readDERCRL(new ASN1InputStream(pis, true));
        }
    } catch (CRLException e) {
        throw e;
    } catch (Exception e) {
        throw new CRLException(e.toString());
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PushbackInputStream(java.io.PushbackInputStream) CRLException(java.security.cert.CRLException) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException)

Aggregations

PushbackInputStream (java.io.PushbackInputStream)80 IOException (java.io.IOException)42 InputStream (java.io.InputStream)18 ByteArrayInputStream (java.io.ByteArrayInputStream)16 FileInputStream (java.io.FileInputStream)6 CertificateException (java.security.cert.CertificateException)5 Test (org.junit.Test)5 File (java.io.File)4 CRLException (java.security.cert.CRLException)4 CertificateParsingException (java.security.cert.CertificateParsingException)4 InputStreamReader (java.io.InputStreamReader)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Charset (java.nio.charset.Charset)2