Search in sources :

Example 51 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStreamTest method testRead04.

/**
     * Test #4 for <code>read()</code> method<br>
     *
     * Assertion: broken <code>DigestInputStream</code>instance:
     * <code>InputStream</code> not set. <code>read()</code> must
     * not work
     */
public final void testRead04() throws IOException {
    for (int ii = 0; ii < algorithmName.length; ii++) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
            DigestInputStream dis = new DigestInputStream(null, md);
            // must result in an exception
            try {
                for (int i = 0; i < MY_MESSAGE_LEN; i++) {
                    dis.read();
                }
            } catch (Exception e) {
                // Expected.
                return;
            }
            fail("InputStream not set. read() must not work");
        } catch (NoSuchAlgorithmException e) {
        // allowed failure
        }
    }
    fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
Also used : DigestInputStream(java.security.DigestInputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 52 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStream2Test method test_ConstructorLjava_io_InputStreamLjava_security_MessageDigest.

/**
     * java.security.DigestInputStream#DigestInputStream(java.io.InputStream,
     *        java.security.MessageDigest)
     */
public void test_ConstructorLjava_io_InputStreamLjava_security_MessageDigest() {
    // Test for method java.security.DigestInputStream(java.io.InputStream,
    // java.security.MessageDigest)
    DigestInputStream dis = new DigestInputStream(inStream, digest);
    assertNotNull("Constructor returned null instance", dis);
}
Also used : DigestInputStream(java.security.DigestInputStream)

Example 53 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStream2Test method test_read.

/**
     * java.security.DigestInputStream#read()
     */
public void test_read() throws IOException {
    // Test for method int java.security.DigestInputStream.read()
    DigestInputStream dis = new DigestInputStream(inStream, digest);
    // read and compare the data that the inStream has
    int c;
    while ((c = dis.read()) > -1) {
        int d = inStream1.read();
        assertEquals(d, c);
    }
// end while
}
Also used : DigestInputStream(java.security.DigestInputStream)

Example 54 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStream2Test method test_getMessageDigest.

/**
     * java.security.DigestInputStream#getMessageDigest()
     */
public void test_getMessageDigest() {
    // Test for method java.security.MessageDigest
    // java.security.DigestInputStream.getMessageDigest()
    DigestInputStream dis = new DigestInputStream(inStream, digest);
    assertEquals("getMessageDigest returned a bogus result", digest, dis.getMessageDigest());
}
Also used : DigestInputStream(java.security.DigestInputStream)

Example 55 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStream2Test method test_read$BII_Exception.

/**
     * java.security.DigestInputStream#read(byte[], int, int)
     */
public void test_read$BII_Exception() throws IOException {
    DigestInputStream is = new DigestInputStream(inStream, digest);
    byte[] buf = null;
    try {
        is.read(buf, -1, 0);
        fail("Test 1: NullPointerException expected.");
    } catch (NullPointerException e) {
    // Expected.
    }
    buf = new byte[1000];
    try {
        is.read(buf, -1, 0);
        fail("Test 2: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 0, -1);
        fail("Test 3: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, -1, -1);
        fail("Test 4: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 0, 1001);
        fail("Test 5: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 1001, 0);
        fail("Test 6: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 500, 501);
        fail("Test 7: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    is.close();
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
    is = new DigestInputStream(sis, digest);
    try {
        is.read(buf, 0, 100);
        fail("Test 9: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
    is.close();
}
Also used : DigestInputStream(java.security.DigestInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException)

Aggregations

DigestInputStream (java.security.DigestInputStream)75 MessageDigest (java.security.MessageDigest)54 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)35 InputStream (java.io.InputStream)26 IOException (java.io.IOException)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 FileInputStream (java.io.FileInputStream)12 File (java.io.File)11 BufferedInputStream (java.io.BufferedInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DigestOutputStream (java.security.DigestOutputStream)5 HashMap (java.util.HashMap)5 ByteUtil (com.zimbra.common.util.ByteUtil)3 BigInteger (java.math.BigInteger)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Entry (java.util.Map.Entry)3 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)2 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)2