List of usage examples for org.apache.commons.vfs2 FileContent getLastModifiedTime
long getLastModifiedTime() throws FileSystemException;
From source file:com.wipro.ats.bdre.tdimport.FileMonitor.java
private static void putEligibleFileInfoInMap(String fileName, FileContent fc) { // *Start* Eligible files moved to data structure for ingestion to HDFS FileCopyInfo fileCopyInfo = new FileCopyInfo(); try {// w ww . j a va2s .c om fileCopyInfo.setFileName(fileName); fileCopyInfo.setSubProcessId(TDImportRunnableMain.getSubProcessId()); fileCopyInfo.setServerId(Integer.toString(123461)); fileCopyInfo.setSrcLocation(fc.getFile().getName().getPath()); fileCopyInfo.setTdTable(TDImportRunnableMain.getTdTable()); fileCopyInfo.setFileHash(DigestUtils.md5Hex(fc.getInputStream())); fileCopyInfo.setFileSize(fc.getSize()); fileCopyInfo.setTimeStamp(fc.getLastModifiedTime()); fileCopyInfo.setTdDB(TDImportRunnableMain.getTdDB()); fileCopyInfo.setTdUserName(TDImportRunnableMain.getTdUserName()); fileCopyInfo.setTdPassword(TDImportRunnableMain.getTdPassword()); fileCopyInfo.setTdDelimiter(TDImportRunnableMain.getTdDelimiter()); fileCopyInfo.setTdTpdid(TDImportRunnableMain.getTdTpdid()); // putting element to structure addToQueue(fileName, fileCopyInfo); } catch (Exception err) { LOGGER.error("Error adding file to queue ", err); throw new BDREException(err); } // *End* Eligible files moved to data structure for ingestion to HDFS }
From source file:com.wipro.ats.bdre.filemon.FileMonitor.java
private static void putEligibleFileInfoInMap(String fileName, FileContent fc) { // *Start* Eligible files moved to data structure for ingestion to HDFS FileCopyInfo fileCopyInfo = new FileCopyInfo(); try {/*from www. j a va2 s . c om*/ fileCopyInfo.setFileName(fileName); fileCopyInfo.setSubProcessId(FileMonRunnableMain.getSubProcessId()); fileCopyInfo.setServerId(Integer.toString(123461)); fileCopyInfo.setSrcLocation(fc.getFile().getName().getPath()); fileCopyInfo.setDstLocation(new java.io.File(fileName).getParent() .replace(FileMonRunnableMain.getMonitoredDirName(), FileMonRunnableMain.getHdfsUploadDir())); fileCopyInfo.setFileHash(DigestUtils.md5Hex(fc.getInputStream())); fileCopyInfo.setFileSize(fc.getSize()); fileCopyInfo.setTimeStamp(fc.getLastModifiedTime()); // putting element to structure addToQueue(fileName, fileCopyInfo); } catch (Exception err) { LOGGER.error("Error adding file to queue ", err); throw new BDREException(err); } // *End* Eligible files moved to data structure for ingestion to HDFS }
From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java
private File buildNode(final File parent, final FileObject file) throws org.apache.commons.vfs2.FileSystemException { String name = file.getName().getBaseName(); File n = new AbstractFile(this, name, parent, file.getType() == FileType.FOLDER, true); if (file.getType() == FileType.FILE) { FileContent content = file.getContent(); n.setLastModified(content.getLastModifiedTime()); n.setSize(content.getSize());/*from w w w . j a v a 2 s . c o m*/ } return n; }
From source file:de.blizzy.backup.vfs.RemoteFileOrFolder.java
@Override public FileTime getLastModificationTime() throws IOException { FileContent content = getFileContent(); try {//w w w . j a v a 2s . com long lastModifiedTime = content.getLastModifiedTime(); return FileTime.fromMillis(lastModifiedTime); } catch (FileSystemException e) { return null; } }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
@Test public void A006_testContent() throws Exception { String currAccountStr = testProperties.getProperty("azure.account.name"); String currKey = testProperties.getProperty("azure.account.key"); String currContainerStr = testProperties.getProperty("azure.test0001.container.name"); String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net String currFileNameStr;// w w w . j a v a2 s . c o m DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "file05"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileContent content = currFile.getContent(); long size = content.getSize(); Assert.assertTrue(size >= 0); long modTime = content.getLastModifiedTime(); Assert.assertTrue(modTime > 0); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A005_testContent() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr;//from w ww . jav a2s . c om SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "file05"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileContent content = currFile.getContent(); long size = content.getSize(); Assert.assertTrue(size >= 0); long modTime = content.getLastModifiedTime(); Assert.assertTrue(modTime > 0); }
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does an 'ls' command.//from w w w .j a v a 2s. co m * * @param cmd * @throws org.apache.commons.vfs2.FileSystemException */ public 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; } switch (file.getType()) { case FOLDER: // List the contents System.out.println("Contents of " + file.getName()); listChildren(file, recursive, ""); break; case FILE: // 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); break; case IMAGINARY: System.out.println(String.format("File '%s' is IMAGINARY", file.getName())); break; default: log.error(String.format("Unkown type '%d' on '%s'", file.getType(), file.getName())); break; } }
From source file:net.sourceforge.fullsync.ui.FileObjectChooser.java
private void populateList() throws FileSystemException { FileObject[] children = activeFileObject.getChildren(); Arrays.sort(children, (o1, o2) -> { try {/* w ww . j av a 2s . c o m*/ if ((o1.getType() == FileType.FOLDER) && (o2.getType() == FileType.FILE)) { return -1; } else if ((o1.getType() == FileType.FILE) && (o2.getType() == FileType.FOLDER)) { return 1; } return o1.getName().getBaseName().compareTo(o2.getName().getBaseName()); } catch (FileSystemException fse) { fse.printStackTrace(); return 0; } }); DateFormat df = DateFormat.getDateTimeInstance(); for (int i = 0; i < children.length; i++) { FileObject data = children[i]; TableItem item; if (tableItems.getItemCount() <= i) { item = new TableItem(tableItems, SWT.NULL); } else { item = tableItems.getItem(i); } item.setText(0, data.getName().getBaseName()); String type = data.getType().getName(); //FIXME: translate type name {file,folder} if (data.getType().hasContent()) { FileContent content = data.getContent(); String contentType = content.getContentInfo().getContentType(); if (null != contentType) { type += " (" + contentType + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } item.setText(1, String.valueOf(content.getSize())); item.setText(3, df.format(new Date(content.getLastModifiedTime()))); } else { item.setText(1, ""); //$NON-NLS-1$ item.setText(3, ""); //$NON-NLS-1$ } item.setText(2, type); if (data.getType() == FileType.FOLDER) { item.setImage(imageRepository.getImage("FS_Folder_Collapsed.gif")); //$NON-NLS-1$ } else { item.setImage(imageRepository.getImage("FS_File_text_plain.gif")); //$NON-NLS-1$ } item.setData(data); } tableItems.setItemCount(children.length); }
From source file:com.yenlo.synapse.transport.vfs.VFSTransportListener.java
/** * Process a single file through Axis2/*w w w .j a va 2 s .com*/ * @param entry the PollTableEntry for the file (or its parent directory or archive) * @param file the file that contains the actual message pumped into Axis2 * @throws AxisFault on error */ private void processFile(PollTableEntry entry, FileObject file) throws AxisFault { try { FileContent content = file.getContent(); String fileName = file.getName().getBaseName(); String filePath = file.getName().getPath(); String fileURI = file.getName().getURI(); metrics.incrementBytesReceived(content.getSize()); 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 ignore) { } MessageContext msgContext = entry.createMessageContext(); String contentType = entry.getContentType(); if (BaseUtils.isBlank(contentType)) { if (file.getName().getExtension().toLowerCase().endsWith(".xml")) { contentType = "text/xml"; } else if (file.getName().getExtension().toLowerCase().endsWith(".txt")) { contentType = "text/plain"; } } else { // Extract the charset encoding from the configured content type and // set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this. String charSetEnc = null; try { if (contentType != null) { charSetEnc = new ContentType(contentType).getParameter("charset"); } } catch (ParseException ex) { // ignore } msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc); } // if the content type was not found, but the service defined it.. use it if (contentType == null) { if (entry.getContentType() != null) { contentType = entry.getContentType(); } else if (VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE) != null) { contentType = VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE); } } // does the service specify a default reply file URI ? String replyFileURI = entry.getReplyFileURI(); if (replyFileURI != null) { msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new VFSOutTransportInfo(replyFileURI, entry.isFileLockingEnabled())); } // Determine the message builder to use Builder builder; if (contentType == null) { log.debug("No content type specified. Using SOAP builder."); builder = new SOAPBuilder(); } else { int index = contentType.indexOf(';'); String type = index > 0 ? contentType.substring(0, index) : contentType; builder = BuilderUtil.getBuilderFromSelector(type, msgContext); if (builder == null) { if (log.isDebugEnabled()) { log.debug("No message builder found for type '" + type + "'. Falling back to SOAP."); } builder = new SOAPBuilder(); } } // set the message payload to the message context InputStream in; ManagedDataSource dataSource; if (builder instanceof DataSourceMessageBuilder && entry.isStreaming()) { in = null; dataSource = ManagedDataSourceFactory.create(new FileObjectDataSource(file, contentType)); } else { in = new AutoCloseInputStream(content.getInputStream()); dataSource = null; } try { OMElement documentElement; if (in != null) { documentElement = builder.processDocument(in, contentType, msgContext); } else { documentElement = ((DataSourceMessageBuilder) builder).processDocument(dataSource, contentType, msgContext); } msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement)); handleIncomingMessage(msgContext, transportHeaders, null, //* SOAP Action - not applicable *// contentType); } finally { if (dataSource != null) { dataSource.destroy(); } } if (log.isDebugEnabled()) { log.debug("Processed file : " + file + " of Content-type : " + contentType); } } catch (FileSystemException e) { handleException("Error reading file content or attributes : " + file, e); } finally { try { file.close(); } catch (FileSystemException warn) { // log.warn("Cannot close file after processing : " + file.getName().getPath(), warn); // ignore the warning, since we handed over the stream close job to AutocloseInputstream.. } } }
From source file:org.apache.commons.vfs2.example.Shell.java
/** * Does an 'ls' command./*from www.ja v a 2 s. c o 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); } }