Package java.io

Examples of java.io.RandomAccessFile.seek()


        BufferedFileOutput buf = manage(new BufferedFileOutput(file, 100));
        buf.writeDouble(100d);
        buf.writeDouble(-100d);
        buf.flush();

        file.seek(0);
        assertThat(file.readDouble(), is(100d));
        assertThat(file.readDouble(), is(-100d));

        eof(file);
    }
View Full Code Here


        RandomAccessFile file = file();
        BufferedFileOutput buf = manage(new BufferedFileOutput(file, 100));
        buf.writeBytes("Hello, world!");
        buf.flush();

        file.seek(0);
        byte[] expect = "Hello, world!".getBytes(Charset.forName("ascii"));
        byte[] b = new byte[expect.length];
        file.readFully(b);
        assertThat(b, is(expect));
View Full Code Here

        RandomAccessFile file = file();
        BufferedFileOutput buf = manage(new BufferedFileOutput(file, 100));
        buf.writeChars("Hello, world!");
        buf.flush();

        file.seek(0);
        String expect = "Hello, world!";
        for (char e : expect.toCharArray()) {
            char c = file.readChar();
            assertThat(c, is(e));
        }
View Full Code Here

        RandomAccessFile file = file();
        BufferedFileOutput buf = manage(new BufferedFileOutput(file, 100));
        buf.writeUTF("Hello, world!");
        buf.flush();

        file.seek(0);
        assertThat(DataIoUtils.readUTF(file), is("Hello, world!"));

        eof(file);
    }
View Full Code Here

        buf.sync();
        assertThat(buf.getPosition(), is(1L));
        buf.write(2);
        buf.flush();

        file.seek(0);
        assertThat(file.readByte(), is((byte) 1));
        assertThat(file.readByte(), is((byte) 2));

        eof(file);
    }
View Full Code Here

        assertThat(buf.getPosition(), is(1L));
        buf.write(-1);
        buf.seek(2);
        buf.flush();

        file.seek(0);
        assertThat(file.readByte(), is((byte) 0));
        assertThat(file.readByte(), is((byte) -1));
        for (int i = 2; i < 100; i++) {
            assertThat(file.readByte(), is((byte) i));
        }
View Full Code Here

     */
    @Test
    public void testReadUTF() throws Exception {
        RandomAccessFile file = file();
        DataIoUtils.writeUTF(file, "Hello, world!");
        file.seek(0);

        BufferedFileInput buf = manage(new BufferedFileInput(file, 256));
        assertThat(buf.readUTF(), is("Hello, world!"));
        eof(buf);
    }
View Full Code Here

     */
    @Test
    public void testSync() throws Exception {
        RandomAccessFile file = file();
        file.write(bytes(1, 2, 3, 4, 5));
        file.seek(0);
        BufferedFileInput buf = manage(new BufferedFileInput(file, 256));

        assertThat(buf.readByte(), is((byte) 1));
        assertThat(buf.getPosition(), is(1L));

View Full Code Here

        BufferedFileInput buf = manage(new BufferedFileInput(file, 256));

        assertThat(buf.readByte(), is((byte) 1));
        assertThat(buf.getPosition(), is(1L));

        file.seek(3);
        buf.sync();
        assertThat(buf.getPosition(), is(3L));
        assertThat(buf.readByte(), is((byte) 4));
    }
View Full Code Here

     */
    @Test
    public void testSeek() throws Exception {
        RandomAccessFile file = file();
        file.write(range(0, 1023));
        file.seek(0);

        BufferedFileInput buf = manage(new BufferedFileInput(file, 256));
        buf.seek(100);
        assertThat(buf.getPosition(), is(100L));
        assertThat(buf.readByte(), is((byte) 100));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.