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

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

Introduction

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

Prototype

public void close() throws FileSystemException;

Source Link

Document

Closes this file, and its content.

Usage

From source file:com.thinkberg.moxo.vfs.s3.S3FileProviderTest.java

public void testCreateFile() throws IOException {
    FileObject object = VFS.getManager().resolveFile(ROOT + "/newfile.txt");
    object.getContent().getOutputStream().write(0xfc);
    object.close();
}

From source file:com.panet.imeta.job.entry.validator.FileDoesNotExistValidator.java

public boolean validate(CheckResultSourceInterface source, String propertyName,
        List<CheckResultInterface> remarks, ValidatorContext context) {

    String filename = ValidatorUtils.getValueAsString(source, propertyName);
    VariableSpace variableSpace = getVariableSpace(source, propertyName, remarks, context);
    boolean failIfExists = getFailIfExists(source, propertyName, remarks, context);

    if (null == variableSpace) {
        return false;
    }/*from w w w.j a v a 2  s . c  o m*/

    String realFileName = variableSpace.environmentSubstitute(filename);
    FileObject fileObject = null;
    try {
        fileObject = KettleVFS.getFileObject(realFileName);

        if (fileObject.exists() && failIfExists) {
            JobEntryValidatorUtils.addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks,
                    JobEntryValidatorUtils.getLevelOnFail(context, VALIDATOR_NAME));
            return false;
        }
        try {
            fileObject.close(); // Just being paranoid
        } catch (IOException ignored) {
        }
    } catch (Exception e) {
        JobEntryValidatorUtils.addExceptionRemark(source, propertyName, VALIDATOR_NAME, remarks, e);
        return false;
    }
    return true;
}

From source file:com.panet.imeta.job.entry.validator.FileExistsValidator.java

public boolean validate(CheckResultSourceInterface source, String propertyName,
        List<CheckResultInterface> remarks, ValidatorContext context) {

    String filename = ValidatorUtils.getValueAsString(source, propertyName);
    VariableSpace variableSpace = getVariableSpace(source, propertyName, remarks, context);
    boolean failIfDoesNotExist = getFailIfDoesNotExist(source, propertyName, remarks, context);

    if (null == variableSpace) {
        return false;
    }/*from  w  ww  .j  a v a2 s. co m*/

    String realFileName = variableSpace.environmentSubstitute(filename);
    FileObject fileObject = null;
    try {
        fileObject = KettleVFS.getFileObject(realFileName);
        if (fileObject == null || (fileObject != null && !fileObject.exists() && failIfDoesNotExist)) {
            JobEntryValidatorUtils.addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks,
                    JobEntryValidatorUtils.getLevelOnFail(context, VALIDATOR_NAME));
            return false;
        }
        try {
            fileObject.close(); // Just being paranoid
        } catch (IOException ignored) {
        }
    } catch (Exception e) {
        JobEntryValidatorUtils.addExceptionRemark(source, propertyName, VALIDATOR_NAME, remarks, e);
        return false;
    }
    return true;
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testOutputStreamOpenAutocloseWrite() throws Exception {
    final FileObject fo = openFileObject("out.txt");
    final Writer writer = openWriter(fo);
    try {/*from ww  w. ja  v  a 2  s . co m*/
        Thread.sleep(SLEEP_TIME);
        writer.write("test");
    } finally {
        writer.close();
    }
    assertContentEquals(fo, "test");
    fo.close();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testOutputStreamOpenWriteAutocloseFlush() throws Exception {
    final FileObject fo = openFileObject("out.txt");
    final Writer writer = openWriter(fo);
    try {//from w w  w. ja v a  2  s  .  c  o  m
        writer.write("ghi");
        Thread.sleep(SLEEP_TIME);
        writer.flush();
        assertContentEquals(fo, "ghi");
    } finally {
        writer.close();
    }
    fo.close();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testOutputStreamOpenWriteAutocloseWrite() throws Exception {
    final FileObject fo = openFileObject("out.txt");
    final Writer writer = openWriter(fo);
    try {//  ww  w  .j a v a2s .c om
        writer.write("abc");
        Thread.sleep(SLEEP_TIME);
        writer.write("def");
    } finally {
        writer.close();
    }
    assertContentEquals(fo, "abcdef");
    fo.close();
}

From source file:com.panet.imeta.core.row.ValueDataUtil.java

public static Long ChecksumCRC32(ValueMetaInterface metaA, Object dataA) {
    long checksum = 0;
    FileObject file = null;
    try {//from www.  j ava2s  .c o m
        file = KettleVFS.getFileObject(dataA.toString());
        CheckedInputStream cis = null;

        // Computer CRC32 checksum
        cis = new CheckedInputStream((FileInputStream) ((LocalFile) file).getInputStream(), new CRC32());
        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        }

        checksum = cis.getChecksum().getValue();

    } catch (Exception e) {
    } finally {
        if (file != null)
            try {
                file.close();
            } catch (Exception e) {
            }
        ;
    }
    return checksum;
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testInputStreamOpenAutocloseRead() throws Exception {
    final FileObject fo = openFileObject(TEST_FILENAME);
    final BufferedReader reader = openBufferedReader(fo);
    try {/*from  w  w  w.  j ava 2  s . c  o m*/
        Thread.sleep(SLEEP_TIME);
        for (int i = 0; i < TEST_FILE_A_CHARS_NUMBER; i++) {
            assertTrue('a' == reader.read());
        }
    } finally {
        reader.close();
    }
    fo.close();
}

From source file:com.panet.imeta.core.row.ValueDataUtil.java

public static Object loadFileContentInBinary(ValueMetaInterface metaA, Object dataA)
        throws KettleValueException {
    if (dataA == null)
        return null;

    FileObject file = null;
    FileInputStream fis = null;//w  w w.ja v a2s.c o m
    try {
        file = KettleVFS.getFileObject(dataA.toString());
        fis = (FileInputStream) ((LocalFile) file).getInputStream();
        int fileSize = (int) file.getContent().getSize();
        byte[] content = Const.createByteArray(fileSize);
        fis.read(content, 0, fileSize);
        return content;
    } catch (Exception e) {
        throw new KettleValueException(e);
    } finally {
        try {
            if (file != null)
                file.close();
            if (fis != null)
                fis.close();
        } catch (Exception e) {
        }
        ;
    }
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

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