Example usage for org.apache.commons.vfs RandomAccessContent getFilePointer

List of usage examples for org.apache.commons.vfs RandomAccessContent getFilePointer

Introduction

In this page you can find the example usage for org.apache.commons.vfs RandomAccessContent getFilePointer.

Prototype

public long getFilePointer() throws IOException;

Source Link

Document

Returns the current offset in this file.

Usage

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testRandomReadWriteAccessOpenWriteAutocloseGetPosWrite() throws Exception {
    final FileObject fo = openFileObject("out.txt");
    fo.createFile();/*  w ww  .  j ava2s  .  co  m*/
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READWRITE);
    try {
        rac.write("abc".getBytes());
        Thread.sleep(SLEEP_TIME);
        assertEquals("abc".getBytes().length, rac.getFilePointer());
        rac.write("def".getBytes());
    } finally {
        rac.close();
    }
    assertContentEquals(fo, "abcdef");
    fo.close();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testRandomReadOnlyAccessOpenReadSeekAutocloseGetPosRead() throws Exception {
    final FileObject fo = openFileObject(TEST_FILENAME);
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READ);
    try {/*from   w ww  . ja  v  a 2 s  .  c om*/
        rac.readByte();
        rac.seek(TEST_FILE_A_CHARS_NUMBER);
        Thread.sleep(SLEEP_TIME);
        assertEquals(TEST_FILE_A_CHARS_NUMBER, rac.getFilePointer());
        assertTrue('b' == rac.readByte());
    } finally {
        rac.close();
    }
    fo.close();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testRandomReadWriteAccessOpenWriteSeekAutocloseGetPosWrite() throws Exception {
    final FileObject fo = openFileObject("out.txt");
    fo.createFile();//  w ww.j  a  v  a 2s . com
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READWRITE);
    try {
        rac.write("abcdef".getBytes());
        rac.seek("abc".getBytes().length);
        Thread.sleep(SLEEP_TIME);
        assertEquals("abc".getBytes().length, rac.getFilePointer());
        rac.write("ghi".getBytes());
    } finally {
        rac.close();
    }
    assertContentEquals(fo, "abcghi");
    fo.close();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testRandomReadOnlyAccessInputStreamOpenSeekAutocloseReadGetPos() throws Exception {
    final FileObject fo = openFileObject(TEST_FILENAME);
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READ);
    InputStream is = rac.getInputStream();
    try {//from  w w w  . ja  v  a2 s  .  co  m
        rac.seek(TEST_FILE_A_CHARS_NUMBER);
        // reget input stream
        is = rac.getInputStream();
        Thread.sleep(SLEEP_TIME);
        for (int i = 0; i < TEST_FILE_B_CHARS_NUMBER; i++) {
            assertTrue('b' == is.read());
        }
        assertEquals(TEST_FILE_A_CHARS_NUMBER + TEST_FILE_B_CHARS_NUMBER, rac.getFilePointer());
    } finally {
        rac.close();
    }
    fo.close();
}