Java Code Examples for java.util.zip.CheckedInputStream

Following code examples demonstrate how to use java.util.zip.CheckedInputStreamfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.util.zip.CheckedInputStreamand various code implementation of this class.

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to CheckedInputStream.class!",
                   CheckedInputStream.class.isAssignableFrom(sut));
    } 


    public void test_skipJ() throws Exception {
        InputStream checkInput = Support_Resources
                .getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput,
                new CRC32());
        long skipValue = 5;
        assertEquals(
                "the value returned by skip(n) is not the same as its parameter",
                skipValue, checkIn.skip(skipValue));
        checkIn.skip(skipValue);
        assertEquals("checkSum value is not correct", 2235765342L, checkIn
                .getChecksum().getValue());
        checkInput.close();
        try {
            checkInput.skip(33);
            fail("IOException expected");
        } catch (IOException ee) {
        }
    } 

    public void test_read() throws Exception {
        InputStream checkInput = Support_Resources
                .getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput,
                new CRC32());
        checkIn.read();
        checkIn.close();
        try {
            checkIn.read();
            fail("IOException expected.");
        } catch (IOException ee) {
        }
        long skipValue = 5;
        checkInput.close();
    } 

    )
    public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Checksum()
            throws Exception {
        InputStream checkInput = Support_Resources
                .getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput,
                new CRC32());
        assertEquals("constructor of checkedInputStream has failed", 0, checkIn
                .getChecksum().getValue());
        checkInput.close();
    } 

    public void test_getChecksum() throws Exception {
        byte outBuf[] = new byte[100];
        File empty = File.createTempFile("empty", ".txt");
        empty.deleteOnExit();
        FileOutputStream outEmp = new FileOutputStream(empty);
        outEmp.close();
        InputStream inEmp = new FileInputStream(empty);
        CheckedInputStream checkEmpty = new CheckedInputStream(inEmp,
                new CRC32());
        while (checkEmpty.read() >= 0) {
        }
        assertEquals("the checkSum value of an empty file is not zero", 0,
                checkEmpty.getChecksum().getValue());
        inEmp.close();

        InputStream checkInput = Support_Resources
                .getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput,
                new CRC32());
        while (checkIn.read() >= 0) {
        }
        assertEquals("the checksum value is incorrect", 2036203193, checkIn
                .getChecksum().getValue());
        checkInput.close();
        checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn2 = new CheckedInputStream(checkInput,
                new CRC32());
        checkIn2.read(outBuf, 0, 10);
        assertEquals("the checksum value is incorrect", 2235765342L, checkIn2
                .getChecksum().getValue());
        checkInput.close();
    } 

Advertisement
Javadoc
An input stream that also maintains a checksum of the data being read. The checksum can then be used

to verify the integrity of the input data. @see Checksum @author David Connelly

Read More
Advertisement