List of usage examples for org.apache.commons.vfs2 FileContent getFile
FileObject getFile();
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 w w w . jav a 2 s. c o m*/ 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: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 {/*from ww w . ja v a 2 s . c o m*/ 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:org.esupportail.portlet.filemanager.portlet.PortletControllerDownloadEvent.java
@EventMapping(EsupFileManagerConstants.DOWNLOAD_REQUEST_QNAME_STRING) public void downloadEvent(EventRequest request, EventResponse response) { log.info("PortletControllerDownloadEvent.downloadEvent from EsupFilemanager is called"); // INIT // w ww .j a v a 2s . c om portletController.init(request); PortletPreferences prefs = request.getPreferences(); String[] prefsDefaultPathes = prefs.getValues(PortletController.PREF_DEFAULT_PATH, null); boolean showHiddenFiles = "true".equals(prefs.getValue(PortletController.PREF_SHOW_HIDDEN_FILES, "false")); userParameters.setShowHiddenFiles(showHiddenFiles); UploadActionType uploadOption = UploadActionType.valueOf(prefs .getValue(PortletController.PREF_UPLOAD_ACTION_EXIST_FILE, UploadActionType.OVERRIDE.toString())); userParameters.setUploadOption(uploadOption); serverAccess.initializeServices(userParameters); // DefaultPath String defaultPath = serverAccess.getFirstAvailablePath(userParameters, prefsDefaultPathes); // Event final Event event = request.getEvent(); final DownloadRequest downloadRequest = (DownloadRequest) event.getValue(); String fileUrl = downloadRequest.getUrl(); // FS boolean success = false; try { FileSystemManager fsManager = VFS.getManager(); FileSystemOptions fsOptions = new FileSystemOptions(); FileObject file = fsManager.resolveFile(fileUrl, fsOptions); FileContent fc = file.getContent(); String baseName = fc.getFile().getName().getBaseName(); InputStream inputStream = fc.getInputStream(); success = serverAccess.putFile(defaultPath, baseName, inputStream, userParameters, userParameters.getUploadOption()); } catch (FileSystemException e) { log.error("putFile failed for this downloadEvent", e); } //Build the result object final DownloadResponse downloadResponse = new DownloadResponse(); if (success) downloadResponse.setSummary("Upload OK"); else downloadResponse.setSummary("Upload Failed"); //Add the result to the results and send the event response.setEvent(EsupFileManagerConstants.DOWNLOAD_RESPONSE_QNAME, downloadResponse); }
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public DownloadFile getFile(String dir, SharedUserPortletParameters userParameters) { try {/*w ww. j a v a2s . c om*/ FileObject file = cd(dir, userParameters); FileContent fc = file.getContent(); int size = new Long(fc.getSize()).intValue(); String baseName = fc.getFile().getName().getBaseName(); // fc.getContentInfo().getContentType() use URLConnection.getFileNameMap, // we prefer here to use our getMimeType : for Excel files and co // String contentType = fc.getContentInfo().getContentType(); String contentType = JsTreeFile.getMimeType(baseName.toLowerCase()); InputStream inputStream = fc.getInputStream(); DownloadFile dlFile = new DownloadFile(contentType, size, baseName, inputStream); return dlFile; } catch (FileSystemException e) { log.warn("can't download file : " + e.getMessage(), e); } return null; }
From source file:org.jahia.modules.external.vfs.VFSDataSource.java
protected ExternalData getFileContent(final FileContent content) throws FileSystemException { Map<String, String[]> properties = new HashMap<String, String[]>(1); properties.put(Constants.JCR_MIMETYPE, new String[] { getContentType(content) }); String path = content.getFile().getName().getPath().substring(rootPath.length()); String jcrContentPath = path + "/" + Constants.JCR_CONTENT; ExternalData externalData = new ExternalData(jcrContentPath, jcrContentPath, Constants.JAHIANT_RESOURCE, properties);/*from w ww . ja v a 2 s. c om*/ Map<String, Binary[]> binaryProperties = new HashMap<String, Binary[]>(1); binaryProperties.put(Constants.JCR_DATA, new Binary[] { new VFSBinaryImpl(content) }); externalData.setBinaryProperties(binaryProperties); return externalData; }
From source file:org.jahia.modules.external.vfs.VFSDataSource.java
protected String getContentType(FileContent content) throws FileSystemException { String s1 = content.getContentInfo().getContentType(); if (s1 == null) { s1 = JCRContentUtils.getMimeType(content.getFile().getName().getBaseName()); }// w ww . j a v a2 s . c o m if (s1 == null) { s1 = "application/octet-stream"; } return s1; }