List of usage examples for org.apache.commons.vfs2 FileContent getLastModifiedTime
long getLastModifiedTime() throws FileSystemException;
From source file:org.obiba.opal.web.FilesResourceTest.java
@Test public void testCreateFolder_FolderCreatedSuccessfully() throws FileSystemException, URISyntaxException { expect(fileObjectMock.getType()).andReturn(FileType.FOLDER).atLeastOnce(); expect(fileObjectMock.exists()).andReturn(true).atLeastOnce(); FileObject childFolderMock = createMock(FileObject.class); FileName fileNameMock = createMock(FileName.class); expect(fileNameMock.getBaseName()).andReturn("folder").atLeastOnce(); expect(fileNameMock.getPath()).andReturn("folder1/folder").atLeastOnce(); expect(childFolderMock.getName()).andReturn(fileNameMock).atLeastOnce(); expect(childFolderMock.exists()).andReturn(false).atLeastOnce(); FileContent mockContent = createMock(FileContent.class); expect(childFolderMock.getContent()).andReturn(mockContent).atLeastOnce(); expect(mockContent.getLastModifiedTime()).andReturn((long) 1).atLeastOnce(); childFolderMock.createFolder();//from w w w. j a va2 s .com FileObject parentFolderMock = createMock(FileObject.class); expect(childFolderMock.getParent()).andReturn(parentFolderMock).atLeastOnce(); expect(childFolderMock.isReadable()).andReturn(true).atLeastOnce(); expect(childFolderMock.isWriteable()).andReturn(true).atLeastOnce(); expect(parentFolderMock.isWriteable()).andReturn(true).atLeastOnce(); expect(fileObjectMock.resolveFile("folder")).andReturn(childFolderMock).atLeastOnce(); expect(uriInfoMock.getBaseUriBuilder()).andReturn(UriBuilder.fromPath("/")); replay(fileObjectMock, uriInfoMock, parentFolderMock, childFolderMock, fileNameMock, mockContent); Response response = getFileResource().createFolder("folder1", "folder", uriInfoMock); assertThat(response.getStatus()).isEqualTo(Status.CREATED.getStatusCode()); verify(fileObjectMock, uriInfoMock, parentFolderMock, childFolderMock, fileNameMock, mockContent); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.file.FilePollingConsumer.java
/** * Actual processing of the file/folder//from w ww .j a v a 2s . c o m * * @param file * @return * @throws synapseException */ private FileObject processFile(FileObject file) throws SynapseException { try { FileContent content = file.getContent(); String fileName = file.getName().getBaseName(); String filePath = file.getName().getPath(); String fileURI = file.getName().getURI(); if (injectHandler != null) { Map<String, Object> transportHeaders = new HashMap<String, Object>(); transportHeaders.put(VFSConstants.FILE_PATH, filePath); transportHeaders.put(VFSConstants.FILE_NAME, fileName); transportHeaders.put(VFSConstants.FILE_URI, fileURI); try { transportHeaders.put(VFSConstants.FILE_LENGTH, content.getSize()); transportHeaders.put(VFSConstants.LAST_MODIFIED, content.getLastModifiedTime()); } catch (FileSystemException e) { log.warn("Unable to set file length or last modified date header.", e); } injectHandler.setTransportHeaders(transportHeaders); // injectHandler if (!injectHandler.invoke(file, name)) { return null; } } } catch (FileSystemException e) { log.error("Error reading file content or attributes : " + VFSUtils.maskURLPassword(file.toString()), e); } return file; }
From source file:org.wso2.carbon.transport.file.connector.server.FileConsumer.java
/** * Actual processing of the file/folder/*from ww w .j a v a 2s.c o m*/ * * @param file * @return */ private FileObject processFile(FileObject file) throws FileServerConnectorException { FileContent content; String fileURI; String fileName = file.getName().getBaseName(); String filePath = file.getName().getPath(); fileURI = file.getName().getURI(); try { content = file.getContent(); } catch (FileSystemException e) { throw new FileServerConnectorException( "Could not read content of file at URI: " + FileTransportUtils.maskURLPassword(fileURI) + ". ", e); } InputStream inputStream; try { inputStream = content.getInputStream(); } catch (FileSystemException e) { throw new FileServerConnectorException("Error occurred when trying to get " + "input stream from file at URI :" + FileTransportUtils.maskURLPassword(fileURI), e); } CarbonMessage cMessage = new StreamingCarbonMessage(inputStream); cMessage.setProperty(org.wso2.carbon.messaging.Constants.PROTOCOL, Constants.PROTOCOL_NAME); cMessage.setProperty(Constants.FILE_TRANSPORT_PROPERTY_SERVICE_NAME, serviceName); cMessage.setHeader(Constants.FILE_PATH, filePath); cMessage.setHeader(Constants.FILE_NAME, fileName); cMessage.setHeader(Constants.FILE_URI, fileURI); try { cMessage.setHeader(Constants.FILE_LENGTH, Long.toString(content.getSize())); cMessage.setHeader(Constants.LAST_MODIFIED, Long.toString(content.getLastModifiedTime())); } catch (FileSystemException e) { log.warn("Unable to set file length or last modified date header.", e); } FileServerConnectorCallback callback = new FileServerConnectorCallback(); try { messageProcessor.receive(cMessage, callback); } catch (Exception e) { throw new FileServerConnectorException("Failed to send stream from file: " + FileTransportUtils.maskURLPassword(fileURI) + " to message processor. ", e); } try { callback.waitTillDone(timeOutInterval, deleteIfNotAck, fileURI); } catch (InterruptedException e) { throw new FileServerConnectorException("Interrupted while waiting for message " + "processor to consume the file input stream. Aborting processing of file: " + FileTransportUtils.maskURLPassword(fileURI), e); } return file; }
From source file:tain.kr.test.vfs.v01.Shell.java
/** * Does an 'ls' command./*from w w w. jav a2 s . co m*/ */ private void ls(final String[] cmd) throws FileSystemException { int pos = 1; final boolean recursive; if (cmd.length > pos && cmd[pos].equals("-R")) { recursive = true; pos++; } else { recursive = false; } final FileObject file; if (cmd.length > pos) { file = mgr.resolveFile(cwd, cmd[pos]); } else { file = cwd; } if (file.getType() == FileType.FOLDER) { // List the contents System.out.println("Contents of " + file.getName()); listChildren(file, recursive, ""); } else { // Stat the file System.out.println(file.getName()); final FileContent content = file.getContent(); System.out.println("Size: " + content.getSize() + " bytes."); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime())); System.out.println("Last modified: " + lastMod); } }