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

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

Introduction

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

Prototype

public void close() throws IOException;

Source Link

Document

Closes this random access file stream and releases any system resources associated with the stream.

Usage

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testRandomReadWriteAccessOpenAutocloseWrite() throws Exception {
    final FileObject fo = openFileObject("out.txt");
    fo.createFile();/*from w  w w  . java  2s. c  o m*/
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READWRITE);
    try {
        Thread.sleep(SLEEP_TIME);
        rac.write("test".getBytes());
    } finally {
        rac.close();
    }
    assertContentEquals(fo, "test");
    fo.close();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testRandomReadOnlyAccessOpenAutocloseRead() throws Exception {
    final FileObject fo = openFileObject(TEST_FILENAME);
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READ);
    try {/*from  w  w  w  .jav a 2  s .  c om*/
        Thread.sleep(SLEEP_TIME);
        for (int i = 0; i < TEST_FILE_A_CHARS_NUMBER; i++) {
            assertTrue('a' == rac.readByte());
        }
    } finally {
        rac.close();
    }
    fo.close();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testRandomReadWriteAccessOpenWriteAutocloseGetPosWrite() throws Exception {
    final FileObject fo = openFileObject("out.txt");
    fo.createFile();// ww  w  .  java 2  s . 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 {/*  w w w.jav  a 2  s. c o m*/
        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 testRandomReadOnlyAccessInputStreamOpenAutocloseRead() throws Exception {
    final FileObject fo = openFileObject(TEST_FILENAME);
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READ);
    final BufferedReader reader = getBufferedReader(rac.getInputStream());
    try {//from   www  .  ja  v  a  2  s .co m
        Thread.sleep(SLEEP_TIME);
        for (int i = 0; i < TEST_FILE_A_CHARS_NUMBER; i++) {
            assertTrue('a' == reader.read());
        }
    } 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();//  ww  w  .  ja v a 2  s.c o m
    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 testRandomReadOnlyAccessOpenReadAutocloseRead() throws Exception {
    final FileObject fo = openFileObject(TEST_FILENAME);
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READ);
    try {//  w  w w.j  av  a 2 s  . co  m
        for (int i = 0; i < TEST_FILE_A_CHARS_NUMBER; i++) {
            assertTrue('a' == rac.readByte());
        }
        Thread.sleep(SLEEP_TIME);
        for (int i = 0; i < TEST_FILE_B_CHARS_NUMBER; i++) {
            assertTrue('b' == rac.readByte());
        }
    } finally {
        rac.close();
    }
    fo.close();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testRandomReadOnlyAccessInputStreamOpenReadAutocloseRead() throws Exception {
    final FileObject fo = openFileObject(TEST_FILENAME);
    final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READ);
    final BufferedReader reader = getBufferedReader(rac.getInputStream());
    try {//ww w .ja v a 2  s .  co m
        for (int i = 0; i < TEST_FILE_A_CHARS_NUMBER; i++) {
            assertTrue('a' == reader.read());
        }
        Thread.sleep(SLEEP_TIME);
        for (int i = 0; i < TEST_FILE_B_CHARS_NUMBER; i++) {
            assertTrue('b' == reader.read());
        }
    } finally {
        rac.close();
    }
    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 {//  w  w  w. j  a  v a2 s  .com
        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();
}