List of usage examples for org.apache.commons.vfs2.util RandomAccessMode READ
RandomAccessMode READ
To view the source code for org.apache.commons.vfs2.util RandomAccessMode READ.
Click Source Link
From source file:com.github.junrar.vfs2.provider.rar.RandomAccessContentAccess.java
/** * @param rac//w w w . ja v a 2 s. c om * @throws FileSystemException */ public RandomAccessContentAccess(FileObject file) throws FileSystemException { this(file.getContent().getRandomAccessContent(RandomAccessMode.READ)); }
From source file:com.github.junrar.vfs2.provider.rar.VFSVolume.java
@Override public IReadOnlyAccess getReadOnlyAccess() throws IOException { IReadOnlyAccess input = null;/* w w w.ja v a2 s . c o m*/ try { RandomAccessContent rac = file.getContent().getRandomAccessContent(RandomAccessMode.READ); input = new RandomAccessContentAccess(rac); } catch (Exception e) { input = new InputStreamReadOnlyAccessFile(file.getContent().getInputStream()); } return input; }
From source file:org.apache.accumulo.start.classloader.vfs.providers.ReadOnlyHdfsFileProviderTest.java
@Test public void testRandomAccessContent2() throws Exception { FileObject fo = manager.resolveFile(TEST_DIR1); Assert.assertNotNull(fo);/*from w w w . j a v a2s. c o m*/ Assert.assertFalse(fo.exists()); // Create the test file FileObject file = createTestFile(hdfs); file.getContent().getRandomAccessContent(RandomAccessMode.READ).close(); }
From source file:org.freedesktop.mime.MagicEntry.java
public boolean match(FileObject file) throws IOException { RandomAccessContent s = file.getContent().getRandomAccessContent(RandomAccessMode.READ); try {/* w w w. j a v a2 s . com*/ for (Pattern p : this) { byte[] val = p.getValue(); byte[] mask = p.getMask(); // Read in portion of file ByteBuffer buf = ByteBuffer.allocate(p.getRangeLength() + val.length); s.seek(p.getOffset()); byte[] bufArr = buf.array(); s.readFully(bufArr); int valIdx = 0; for (int i = 0; i < bufArr.length; i++) { if ((bufArr[i] & mask[valIdx]) == (val[valIdx] & mask[valIdx])) { valIdx++; if (valIdx == val.length) { return true; } } else { valIdx = 0; } } } } finally { s.close(); } return false; }
From source file:org.mycore.datamodel.ifs2.MCRNode.java
/** * Returns the content of this node for random access read. Be sure not to * write to the node using the returned object, use just for reading! For a * directory, it will return null.//from www . jav a 2 s. com * * @return the content of this file, for random access */ public RandomAccessContent getRandomAccessContent() throws IOException { return isFile() ? fo.getContent().getRandomAccessContent(RandomAccessMode.READ) : null; }
From source file:org.pentaho.platform.repository.solution.filebased.DecoratedFileContentTest.java
License:asdf
@Test public void testGetRandomAccessContent() throws Exception { decorated.getRandomAccessContent(RandomAccessMode.READ); verify(fileContent).getRandomAccessContent(RandomAccessMode.READ); }
From source file:pl.otros.logview.api.io.Utils.java
public static void reloadFileObject(LoadingInfo loadingInfo) throws IOException { loadingInfo.getFileObject().refresh(); long lastFileSize = loadingInfo.getLastFileSize(); long currentSize = loadingInfo.getFileObject().getContent().getSize(); if (currentSize > lastFileSize) { IOUtils.closeQuietly(loadingInfo.getObserableInputStreamImpl()); RandomAccessContent randomAccessContent = loadingInfo.getFileObject().getContent() .getRandomAccessContent(RandomAccessMode.READ); randomAccessContent.seek(lastFileSize); loadingInfo.setLastFileSize(currentSize); ObservableInputStreamImpl observableStream = new ObservableInputStreamImpl( randomAccessContent.getInputStream(), lastFileSize); loadingInfo.setObserableInputStreamImpl(observableStream); if (loadingInfo.isGziped()) { loadingInfo.setContentInputStream(new GZIPInputStream(observableStream)); } else {/* w w w . j a v a2 s . co m*/ loadingInfo.setContentInputStream(observableStream); } } else if (currentSize < lastFileSize) { IOUtils.closeQuietly(loadingInfo.getObserableInputStreamImpl()); InputStream inputStream = loadingInfo.getFileObject().getContent().getInputStream(); ObservableInputStreamImpl observableStream = new ObservableInputStreamImpl(inputStream, 0); loadingInfo.setObserableInputStreamImpl(observableStream); if (loadingInfo.isGziped()) { loadingInfo.setContentInputStream(new GZIPInputStream(observableStream)); } else { loadingInfo.setContentInputStream(observableStream); } loadingInfo.setLastFileSize(loadingInfo.getFileObject().getContent().getSize()); } }
From source file:pl.otros.logview.io.Utils.java
public static void reloadFileObject(LoadingInfo loadingInfo) throws IOException { loadingInfo.getFileObject().refresh(); long lastFileSize = loadingInfo.getLastFileSize(); long currentSize = loadingInfo.getFileObject().getContent().getSize(); if (currentSize > lastFileSize) { IOUtils.closeQuietly(loadingInfo.getObserableInputStreamImpl()); RandomAccessContent randomAccessContent = loadingInfo.getFileObject().getContent() .getRandomAccessContent(RandomAccessMode.READ); randomAccessContent.seek(lastFileSize); loadingInfo.setLastFileSize(currentSize); ObservableInputStreamImpl observableStream = new ObservableInputStreamImpl( randomAccessContent.getInputStream()); loadingInfo.setObserableInputStreamImpl(observableStream); if (loadingInfo.isGziped()) { loadingInfo.setContentInputStream(new GZIPInputStream(observableStream)); } else {/*from www. j a v a 2 s .co m*/ loadingInfo.setContentInputStream(observableStream); } } else if (currentSize < lastFileSize) { IOUtils.closeQuietly(loadingInfo.getObserableInputStreamImpl()); InputStream inputStream = loadingInfo.getFileObject().getContent().getInputStream(); ObservableInputStreamImpl observableStream = new ObservableInputStreamImpl(inputStream); loadingInfo.setObserableInputStreamImpl(observableStream); if (loadingInfo.isGziped()) { loadingInfo.setContentInputStream(new GZIPInputStream(observableStream)); } else { loadingInfo.setContentInputStream(observableStream); } loadingInfo.setLastFileSize(loadingInfo.getFileObject().getContent().getSize()); } }