List of usage examples for org.apache.commons.vfs2 FileContent close
@Override void close() throws FileSystemException;
From source file:org.mycore.common.content.MCRVFSContent.java
@Override public String getETag() throws IOException { FileContent content = fo.getContent(); try {//from w w w . ja v a2s.c o m String systemId = getSystemId(); if (systemId == null) { systemId = fo.getName().getURI(); } long length = content.getSize(); long lastModified = content.getLastModifiedTime(); String eTag = getSimpleWeakETag(systemId, length, lastModified); if (eTag == null) { return null; } return eTag.substring(2); //remove weak } finally { content.close(); } }
From source file:org.mycore.common.content.MCRVFSContent.java
@Override public String getMimeType() throws IOException { if (super.getMimeType() != null) { return super.getMimeType(); }/* w ww . ja v a 2 s. c o m*/ FileContentInfoFactory fileContentInfoFactory = fo.getFileSystem().getFileSystemManager() .getFileContentInfoFactory(); FileContent content = fo.getContent(); try { return fileContentInfoFactory.create(content).getContentType(); } finally { content.close(); } }
From source file:org.mycore.datamodel.ifs2.MCRNode.java
/** * Returns the time this node was last modified, or null if no such time is * defined in the underlying filesystem/*from w w w . j a v a 2 s . co m*/ * * @return the time this node was last modified */ public Date getLastModified() throws IOException { FileContent content = fo.getContent(); try { if (content != null) { return new Date(content.getLastModifiedTime()); } else { return null; } } finally { content.close(); } }
From source file:org.mycore.datamodel.ifs2.MCRStoredMetadata.java
/** * Returns the date this metadata document was last modified * // w w w . j av a 2 s . c o m * @return the date this metadata document was last modified */ public Date getLastModified() throws IOException { FileContent fileContent = fo.getContent(); try { long time = fileContent.getLastModifiedTime(); return new Date(time); } finally { fileContent.close(); } }
From source file:org.mycore.datamodel.ifs2.MCRStoredMetadata.java
/** * Sets the date this metadata document was last modified * //from w w w . j a v a 2 s . c o m * @param date * the date this metadata document was last modified */ public void setLastModified(Date date) throws IOException { if (!isDeleted()) { FileContent fileContent = fo.getContent(); try { fo.getContent().setLastModifiedTime(date.getTime()); } finally { fileContent.close(); } } }
From source file:org.pentaho.platform.repository.solution.filebased.SolutionRepositoryVfsFileObjectTest.java
@Test @SuppressWarnings({ "checkstyle:onestatementperline", "multiple statements help understand the mock definition" }) public void testContentRelatedMethods(@mockit.Mocked final RepositoryFile mockRepoFile, @mockit.Mocked final IAclNodeHelper mockAclHelper, @mockit.Mocked final IUnifiedRepository mockUnifiedRepository, @mockit.Mocked final SimpleRepositoryFileData mockFileData) throws FileSystemException { String fileRef = "/etc/mondrian/SteelWheels/schema.xml"; new mockit.NonStrictExpectations() { //CHECKSTYLE IGNORE check FOR NEXT 6 LINES {//from w w w . j av a 2 s . c o m mockUnifiedRepository.getFile(anyString); result = mockRepoFile; mockUnifiedRepository.getDataForRead((Serializable) any, (Class) any); result = mockFileData; mockAclHelper.canAccess(mockRepoFile, EnumSet.of(RepositoryFilePermission.READ)); result = true; mockFileData.getStream(); result = new ByteArrayInputStream("some string".getBytes()); } }; Deencapsulation.setField(SolutionRepositoryVfsFileObject.class, "repository", mockUnifiedRepository); SolutionRepositoryVfsFileObject solutionRepositoryVfsFileObject = new SolutionRepositoryVfsFileObject( fileRef); Deencapsulation.setField(solutionRepositoryVfsFileObject, "aclHelper", mockAclHelper); FileContent someFileContent = solutionRepositoryVfsFileObject.getContent(); assertThat(someFileContent, is(notNullValue())); assertThat(solutionRepositoryVfsFileObject.isContentOpen(), is(false)); someFileContent.getInputStream(); assertThat(solutionRepositoryVfsFileObject.isContentOpen(), is(true)); someFileContent.close(); assertThat(solutionRepositoryVfsFileObject.isContentOpen(), is(false)); someFileContent = solutionRepositoryVfsFileObject.getContent(); someFileContent.getInputStream(); assertThat(solutionRepositoryVfsFileObject.isContentOpen(), is(true)); solutionRepositoryVfsFileObject.close(); assertThat(solutionRepositoryVfsFileObject.isContentOpen(), is(false)); }