List of usage examples for org.apache.commons.vfs FileObject createFile
public void createFile() throws FileSystemException;
From source file:com.panet.imeta.core.vfs.KettleVFS.java
public static OutputStream getOutputStream(FileObject fileObject, boolean append) throws IOException { FileObject parent = fileObject.getParent(); if (parent != null) { if (!parent.exists()) { throw new IOException( Messages.getString("KettleVFS.Exception.ParentDirectoryDoesNotExist", getFilename(parent))); }//from w w w .jav a2s . co m } try { fileObject.createFile(); FileContent content = fileObject.getContent(); return content.getOutputStream(append); } catch (FileSystemException e) { // Perhaps if it's a local file, we can retry using the standard // File object. This is because on Windows there is a bug in VFS. // if (fileObject instanceof LocalFile) { try { String filename = getFilename(fileObject); return new FileOutputStream(new File(filename), append); } catch (Exception e2) { throw e; // throw the original exception: hide the retry. } } else { throw e; } } }
From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java
/** * <p>//from w w w. jav a2 s .c om * ?? ? ? . * </p> * @param filepath * <code>String</code> * @return * @throws Exception */ public static long touch(final String filepath) throws Exception { long currentTime = 0; final FileObject file = manager.resolveFile(basefile, filepath); if (!file.exists()) { file.createFile(); } file.getContent().setLastModifiedTime(currentTime = System.currentTimeMillis()); return currentTime; }
From source file:com.nary.util.LogFileObject.java
private LogFileObject(FileObject logPath) throws Exception { filename = logPath;//from w w w. j a va 2 s . c o m if (!logPath.exists()) logPath.createFile(); outFileRandomAccess = logPath.getContent().getRandomAccessContent(RandomAccessMode.READWRITE); logFileSize = outFileRandomAccess.length(); outFileRandomAccess.seek(logFileSize); }
From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java
public void testCopyFile() throws FileSystemException { FileObject srcObject = ROOT.resolveFile(FILE); srcObject.createFile(); assertTrue("source object should exist", srcObject.exists()); FileObject dstObject = ROOT.resolveFile(FILE + ".dst"); assertFalse("destination should not exist", dstObject.exists()); dstObject.copyFrom(srcObject, ALL_FILE_SELECTOR); assertTrue("destination should exist after copy", dstObject.exists()); srcObject.delete();/*from w w w . j a v a 2 s . c o m*/ dstObject.delete(); }
From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java
public void testCopyFileWithAttribute() throws FileSystemException { if (!BUCKETID.startsWith("s3:")) { FileObject srcObject = ROOT.resolveFile(FILE); srcObject.createFile(); srcObject.getContent().setAttribute(ATTR_TESTKEY, ATTR_TESTVALUE); assertTrue("source object should exist", srcObject.exists()); assertEquals("source object attribute missing", ATTR_TESTVALUE, srcObject.getContent().getAttribute(ATTR_TESTKEY)); FileObject dstObject = ROOT.resolveFile(FILE + ".dst"); assertFalse("destination should not exist", dstObject.exists()); dstObject.copyFrom(srcObject, ALL_FILE_SELECTOR); assertTrue("destination should exist after copy", dstObject.exists()); assertEquals("destination object attribute missing", ATTR_TESTVALUE, dstObject.getContent().getAttribute(ATTR_TESTKEY)); srcObject.delete();/*from www . jav a 2 s . co m*/ dstObject.delete(); } else { LogFactory.getLog(S3FileProviderTest.class) .info(String.format("ignoring property test for '%s'", ROOT)); } }
From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java
public void testCreateEmptyFile() throws IOException { FileObject object = ROOT.resolveFile(FILE + ".empty"); assertFalse(object.exists());/*from w ww.j a va2 s .co m*/ object.createFile(); assertTrue(object.exists()); assertEquals(FileType.FILE, object.getType()); }
From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java
@Test public void testRandomReadWriteAccessOpenAutocloseWrite() throws Exception { final FileObject fo = openFileObject("out.txt"); fo.createFile(); final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READWRITE); try {/*w w w. j a va 2 s . c o m*/ 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 testRandomReadWriteAccessOpenWriteAutocloseGetPosWrite() throws Exception { final FileObject fo = openFileObject("out.txt"); fo.createFile(); final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READWRITE); try {//from w w w.ja v a2 s .c o m 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 testRandomReadWriteAccessOpenWriteSeekAutocloseGetPosWrite() throws Exception { final FileObject fo = openFileObject("out.txt"); fo.createFile(); final RandomAccessContent rac = openRandomAccessContent(fo, RandomAccessMode.READWRITE); try {// w w w . j a v a 2 s . c o m 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:com.rapleaf.ramhdfs.RamFileSystem.java
@Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { if (exists(f) && !overwrite) { throw new IOException("File already exists:" + f); }/*from ww w . j a v a 2s .com*/ Path parent = f.getParent(); if (parent != null && !mkdirs(parent)) { throw new IOException("Mkdirs failed to create " + parent.toString()); } FileObject fo = pathToFileObject(f); fo.createFile(); fo.getContent().setLastModifiedTime(System.currentTimeMillis()); setPermission(f, permission); return new FSDataOutputStream(new BufferedOutputStream(new RamFSOutputStream(fo), bufferSize), statistics); }