Package org.apache.derbyTesting.functionTests.util.streams

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream


     */
    public static void transferAlphabetData(OutputStream writer, long length)
            throws IOException {
        byte[] buffer = new byte[8*1024];
        int bytesRead = 0;
        LoopingAlphabetStream contents = new LoopingAlphabetStream(length);
        while ((bytesRead = contents.read(buffer)) > 0) {
            writer.write(buffer, 0, bytesRead);
        }
    }
View Full Code Here


    /**
     * Tests the BlobOutputStream.write(byte  b[], int off, int len) method
     **/
    public void testBlobWrite3Param() throws Exception {
        InputStream streamIn = new LoopingAlphabetStream(streamSize[0]);
        assertTrue("FAIL -- file not found", streamIn != null);

        PreparedStatement stmt3 = prepareStatement(
            "SELECT b FROM testBlobX1 WHERE a = 1");
        ResultSet rs3 = stmt3.executeQuery();
        rs3.next();
        Blob blob = rs3.getBlob(1);

        assertTrue ("FAIL -- blob is NULL", (blob != null));

        int count = 0;
        byte[] buffer = new byte[1024];
        OutputStream outstream = blob.setBinaryStream(1L);
        while ((count = streamIn.read(buffer)) != -1) {
            outstream.write(buffer, 0, count);
        }
        outstream.close();
        streamIn.close();

        PreparedStatement stmt4 = prepareStatement(
            "UPDATE testBlobX1 SET b = ? WHERE a = 1");
        stmt4.setBlob(1,  blob);
        stmt4.executeUpdate();
        stmt4.close();
        rs3.close();

        rs3 = stmt3.executeQuery();
        assertTrue("FAIL -- blob not found", rs3.next());

        long new_length = rs3.getBlob(1).length();
        assertEquals("FAIL -- wrong blob length;",
                streamSize[0], new_length);

        // Check contents ...
        InputStream fStream = new LoopingAlphabetStream(streamSize[0]);
        InputStream lStream = rs3.getBlob(1).getBinaryStream();
        assertTrue("FAIL - Blob and file contents do not match",
                compareLob2File(fStream, lStream));

        fStream.close();
        lStream.close();
        rs3.close();
        stmt3.close();
    }
View Full Code Here

    /**
     * Tests the BlobOutputStream.write(int b) method
     **/
    public void testBlobWrite1Param() throws Exception {
        InputStream streamIn = new LoopingAlphabetStream(streamSize[1]);

        PreparedStatement stmt3 = prepareStatement(
            "SELECT b FROM testBlobX1 WHERE a = 1");
        ResultSet rs3 = stmt3.executeQuery();
        rs3.next();
        Blob blob = rs3.getBlob(1);

        assertTrue("FAIL -- blob is NULL", blob != null);

        int buffer;
        OutputStream outstream = blob.setBinaryStream(1L);
        while ((buffer = streamIn.read()) != -1) {
            outstream.write(buffer);
        }
        outstream.close();
        streamIn.close();

        PreparedStatement stmt4 = prepareStatement(
            "UPDATE testBlobX1 SET b = ? WHERE a = 1");
        stmt4.setBlob(1,  blob);
        stmt4.executeUpdate();
        stmt4.close();

        rs3.close();
        rs3 = stmt3.executeQuery();

        assertTrue("FAIL -- blob not found", rs3.next());

        long new_length = rs3.getBlob(1).length();
        assertEquals("FAIL -- wrong blob length", streamSize[1], new_length);

        // Check contents ...
        InputStream fStream = new LoopingAlphabetStream(streamSize[1]);
        InputStream lStream = rs3.getBlob(1).getBinaryStream();
        assertTrue("FAIL - Blob and file contents do not match",
                compareLob2File(fStream, lStream));

        fStream.close();
        lStream.close();
        rs3.close();
        stmt3.close();
    }
View Full Code Here

    /**
     * Tests the ClobOutputStream.write(int b) method
     **/
    public void testClobAsciiWrite1Param() throws Exception
    {
        InputStream streamIn = new LoopingAlphabetStream(streamSize[1]);

        PreparedStatement stmt3 = prepareStatement(
            "SELECT c FROM testBlobX1 WHERE a = 1");
        ResultSet rs3 = stmt3.executeQuery();
        rs3.next();
        Clob clob = rs3.getClob(1);

        assertTrue("FAIL -- clob is NULL", clob != null);
        int buffer;
        OutputStream outstream = clob.setAsciiStream(1L);
        while ((buffer = streamIn.read()) != -1) {
            outstream.write(buffer);
        }
        outstream.close();
        streamIn.close();

        PreparedStatement stmt4 = prepareStatement(
            "UPDATE testBlobX1 SET c = ? WHERE a = 1");
        stmt4.setClob(1,  clob);
        stmt4.executeUpdate();
        stmt4.close();

        rs3.close();
        rs3 = stmt3.executeQuery();
        assertTrue("FAIL -- clob not found", rs3.next());

        long new_length = rs3.getClob(1).length();
        assertEquals("FAIL -- wrong clob length", streamSize[1], new_length);

        // Check contents ...
        InputStream fStream = new LoopingAlphabetStream(streamSize[1]);
        InputStream lStream = rs3.getClob(1).getAsciiStream();
        assertTrue("FAIL - Clob and file contents do not match", compareLob2File(fStream, lStream));
        fStream.close();
        lStream.close();
        rs3.close();
        stmt3.close();
    }
View Full Code Here

    /**
     * Tests the ClobOutputStream.write(byte  b[], int off, int len) method
     **/
    public void testClobAsciiWrite3Param() throws Exception {
        InputStream streamIn = new LoopingAlphabetStream(streamSize[0]);
        assertTrue("FAIL -- file not found", streamIn != null);

        PreparedStatement stmt3 = prepareStatement(
            "SELECT c FROM testBlobX1 WHERE a = 1");
        ResultSet rs3 = stmt3.executeQuery();
        rs3.next();
        Clob clob = rs3.getClob(1);

        assertTrue("FAIL -- clob is NULL", clob != null);

        int count = 0;
        byte[] buffer = new byte[1024];
        OutputStream outstream = clob.setAsciiStream(1L);
        while ((count = streamIn.read(buffer)) != -1) {
            outstream.write(buffer, 0, count);
        }
        outstream.close();
        streamIn.close();

        PreparedStatement stmt4 = prepareStatement(
            "UPDATE testBlobX1 SET c = ? WHERE a = 1");
        stmt4.setClob(1,  clob);
        stmt4.executeUpdate();
        stmt4.close();

        rs3.close();
        rs3 = stmt3.executeQuery();

        assertTrue("FAIL -- clob not found", rs3.next());

        long new_length = rs3.getClob(1).length();
        assertEquals("FAIL -- wrong clob length",
                streamSize[0], new_length);
        // Check contents ...
        InputStream fStream = new LoopingAlphabetStream(streamSize[0]);
        InputStream lStream = rs3.getClob(1).getAsciiStream();
        assertTrue("FAIL - Clob and file contents do not match",
                compareLob2File(fStream, lStream));

        fStream.close();
        lStream.close();
        rs3.close();
        stmt3.close();
    }
View Full Code Here

        int length = 1*1024;
        setBinaryStreamOnBlob(key, length, -1, 0, true);
        psFetchBlob.setInt(1, key);
        ResultSet rs = psFetchBlob.executeQuery();
        assertTrue("Empty resultset", rs.next());
        assertEquals(new LoopingAlphabetStream(length),
                     rs.getBinaryStream(1));
        assertFalse("Resultset should have been exhausted", rs.next());
        rs.close();
    }
View Full Code Here

        int length = 32*1024;
        setBinaryStreamOnBlob(key, length, -1, 0, true);
        psFetchBlob.setInt(1, key);
        ResultSet rs = psFetchBlob.executeQuery();
        assertTrue("Empty resultset", rs.next());
        assertEquals(new LoopingAlphabetStream(length),
                     rs.getBinaryStream(1));
        assertFalse("Resultset should have been exhausted", rs.next());
        rs.close();
    }
View Full Code Here

        int length = 65*1024;
        setBinaryStreamOnBlob(key, length, -1, 0, true);
        psFetchBlob.setInt(1, key);
        ResultSet rs = psFetchBlob.executeQuery();
        assertTrue("Empty resultset", rs.next());
        LoopingAlphabetStream s1 = new LoopingAlphabetStream(length);
        assertEquals(new LoopingAlphabetStream(length),
                     rs.getBinaryStream(1));
        assertFalse("Resultset should have been exhausted", rs.next());
        rs.close();
    }
View Full Code Here

        int length = 1*1024;
        setAsciiStream(psInsertClob, key, length, -1, 0, true);
        psFetchClob.setInt(1, key);
        ResultSet rs = psFetchClob.executeQuery();
        assertTrue("Empty resultset", rs.next());
        assertEquals(new LoopingAlphabetStream(length),
                     rs.getAsciiStream(1));
        assertFalse("Resultset should have been exhausted", rs.next());
        rs.close();
    }
View Full Code Here

        int length = 32*1024;
        setAsciiStream(psInsertClob, key, length, -1, 0, true);
        psFetchClob.setInt(1, key);
        ResultSet rs = psFetchClob.executeQuery();
        assertTrue("Empty resultset", rs.next());
        assertEquals(new LoopingAlphabetStream(length),
                     rs.getAsciiStream(1));
        assertFalse("Resultset should have been exhausted", rs.next());
        rs.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.