List of usage examples for org.apache.commons.vfs.util RandomAccessMode READWRITE
RandomAccessMode READWRITE
To view the source code for org.apache.commons.vfs.util RandomAccessMode READWRITE.
Click Source Link
From source file:com.nary.util.LogFileObject.java
private LogFileObject(FileObject logPath) throws Exception { filename = logPath;//from w w w .j a v a2 s . c om if (!logPath.exists()) logPath.createFile(); outFileRandomAccess = logPath.getContent().getRandomAccessContent(RandomAccessMode.READWRITE); logFileSize = outFileRandomAccess.length(); outFileRandomAccess.seek(logFileSize); }
From source file:com.newatlanta.appengine.vfs.provider.GaeRandomAccessContent.java
GaeRandomAccessContent(GaeFileObject gfo, RandomAccessMode m, boolean append) throws IOException { EnumSet<StandardOpenOption> options = EnumSet.of(StandardOpenOption.READ); if (m == RandomAccessMode.READWRITE) { options.add(StandardOpenOption.WRITE); gfo.doSetLastModTime(System.currentTimeMillis()); }/*from ww w . ja v a2 s .c om*/ if (append) { options.add(StandardOpenOption.APPEND); } fileChannel = new GaeFileChannel(gfo, options); dataOutput = new DataOutputStream(Channels.newOutputStream(fileChannel)); dataInput = new GaeDataInputStream(Channels.newInputStream(fileChannel)); }
From source file:com.nary.util.LogFileObject.java
private void rotateLogFile() { try {//from w w w.j a v a 2s. c om outFileRandomAccess.close(); // rename the old file to a new one int x = 1; String sfname = filename.getName().getBaseName(); FileObject newFile = filename.getParent().resolveFile(sfname + "." + x); while (newFile.exists()) { newFile = filename.getParent().resolveFile(sfname + "." + (x++)); } filename.moveTo(newFile); //Delete the old one filename.delete(); filename.createFile(); outFileRandomAccess = filename.getContent().getRandomAccessContent(RandomAccessMode.READWRITE); ; logFileSize = 0; } catch (IOException ignoreException) { // - the rotation failed; so lets just reset the current file } }
From source file:com.naryx.tagfusion.cfm.file.vfs.cfVFSData.java
public void openRandomAccessContent() throws IOException { if (fileObject != null) { randomAccessContent = fileObject.getContent().getRandomAccessContent(RandomAccessMode.READWRITE); randomAccessContent.seek(randomAccessContent.length()); } else {//from w w w .jav a 2s. c o m randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.seek(randomAccessFile.length()); } }
From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java
@Test public void testRandomReadWriteAccessOpenAutocloseWrite() throws Exception { final FileObject fo = openFileObject("out.txt"); fo.createFile();// w w w . ja v a 2 s .co 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 testRandomReadWriteAccessOpenWriteAutocloseGetPosWrite() throws Exception { final FileObject fo = openFileObject("out.txt"); fo.createFile();/*from ww w .j a v a 2 s. c om*/ 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 testRandomReadWriteAccessOpenWriteSeekAutocloseGetPosWrite() throws Exception { final FileObject fo = openFileObject("out.txt"); fo.createFile();//from w w w.j a v a 2s. 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:com.newatlanta.appengine.vfs.provider.GaeFileObject.java
/** * Creates an output stream to write the file content to. * //from w ww. java2s . co m * It is guaranteed that there are no open stream (input or output) for * this file when this method is called. * * The returned stream does not have to be buffered. */ @Override protected OutputStream doGetOutputStream(boolean bAppend) throws IOException { return new GaeRandomAccessContent(this, RandomAccessMode.READWRITE, bAppend).getOutputStream(); }
From source file:unitTests.dataspaces.AbstractLimitingFileObjectTest.java
@Test public void testReadOnlyGetContentRandomOutputStream() throws IOException { createRealFile();/*from w w w . ja v a2s . c o m*/ final FileContent content = readOnlyFile.getContent(); try { content.getRandomAccessContent(RandomAccessMode.READWRITE).close(); fail("Expected exception"); } catch (FileSystemException x) { } finally { content.close(); } }
From source file:unitTests.dataspaces.AbstractLimitingFileObjectTest.java
@Test public void testReadWriteGetContentRandomOutputStream() throws IOException { createRealFile();/*from ww w .j a va 2 s. c o m*/ final FileContent content = readWriteFile.getContent(); try { content.getRandomAccessContent(RandomAccessMode.READWRITE).close(); } finally { content.close(); } }