Code example for DataInputStream

Methods: available, readUTF

0
    public void test_readUTFLjava_io_DataInput() throws IOException { 
        os.writeUTF(unihw);
        os.close();
        openDataInputStream(); 
        assertTrue("Failed to write string in UTF format",
                dis.available() == unihw.length() + 2);
        assertTrue("Incorrect string read", DataInputStream.readUTF(dis)
                .equals(unihw));
 
        // Regression test for HARMONY-5336 
        new TestDataInputStream().readUTF(); 
    } 
 
    /** 
     * @tests java.io.DataInputStream#skipBytes(int) 
     */ 
    public void test_skipBytesI() throws IOException { 
        byte fileBytes[] = fileString.getBytes();
        os.write(fileBytes);
        os.close();
        openDataInputStream(); 
        dis.skipBytes(100);
        byte rbytes[] = new byte[fileString.length()];
        dis.read(rbytes, 0, 50);
        dis.close();
        assertTrue("Incorrect data read", new String(rbytes, 0, 50)
                .equals(fileString.substring(100, 150)));
 
        int skipped = 0;
        openDataInputStream(); 
        try { 
            skipped = dis.skipBytes(50000);
        } catch (EOFException e) {
        } 
        assertTrue("Skipped should report " + fileString.length() + " not "
                + skipped, skipped == fileString.length());
    } 
 
    private void openDataInputStream() throws IOException { 
        dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
    } 
 
    /** 
     * Sets up the fixture, for example, open a network connection. This method 
     * is called before a test is executed.