List of usage examples for org.apache.commons.lang SystemUtils FILE_SEPARATOR
String FILE_SEPARATOR
To view the source code for org.apache.commons.lang SystemUtils FILE_SEPARATOR.
Click Source Link
The file.separator
System Property.
From source file:org.exem.flamingo.agent.nn.hdfs.HdfsFileInfo.java
public static String getDirectoryName(String fullyQualifiedPath) { int sep = fullyQualifiedPath.lastIndexOf(SystemUtils.FILE_SEPARATOR); int length = fullyQualifiedPath.getBytes().length; return fullyQualifiedPath.substring(sep + 1, length); }
From source file:org.exem.flamingo.shared.util.FileUtils.java
/** * Fully Qualified Path? Path Separator . * * @param fullyQualifiedPath Fully Qualified Path * @return Path Separator /* www . j a v a 2s . co m*/ */ public static String getDirectoryName(String fullyQualifiedPath) { int lastIndex = fullyQualifiedPath.lastIndexOf(SystemUtils.FILE_SEPARATOR); return fullyQualifiedPath.substring(lastIndex + 1); }
From source file:org.exem.flamingo.shared.util.FileUtils.java
/** * ? ? ? ? ? .//from w ww .ja va 2 s . c o m * ex. /home/cloudine/flamingo/web -> web * Path ?? getDirectoryName() : String index out of range * * @param path ? * @return ? */ public static String getLastPathName(String path) { String separator = SystemUtils.FILE_SEPARATOR; return org.apache.commons.lang.StringUtils.substringAfterLast(path, separator); }
From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java
/** * ?? ./*from w w w.j a v a 2 s . c o m*/ * * @param node HDFS Tree Node * @return directories */ @RequestMapping(value = "directory", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public Response directory(@RequestParam(defaultValue = "/") String node) { String username = getSessionUsername(); String path = getPathFilter(node); List<FileInfo> directories = fileSystemService.getDirectories(path, true); Response response = new Response(); if (path.equalsIgnoreCase(hadoopUserHome) && getSessionUserLevel() != 1) { String filter = hadoopUserHome + SystemUtils.FILE_SEPARATOR + username; List<FileInfo> userHomeDirectory = new ArrayList<>(); for (FileInfo directory : directories) { if (directory.getFullyQualifiedPath().equalsIgnoreCase(filter)) { userHomeDirectory.add(0, directory); break; } } response.getList().addAll(userHomeDirectory); } else { response.getList().addAll(directories); } response.setSuccess(true); return response; }
From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java
/** * ?.//from w ww.j a va 2s. co m * * @param dirMap ?? * @return True or False */ @RequestMapping(value = "createDirectory", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public Response createDirectory(@RequestBody Map<String, String> dirMap) { Response response = new Response(); try { String username = getSessionUsername(); String currentPath = getPathFilter(dirMap.get("currentPath")); String directoryName = dirMap.get("directoryName"); //TODO HDFS ? ? //List<String> paths = hdfsBrowserAuthService.getHdfsBrowserPatternAll(username); //String hdfsPathPattern = hdfsBrowserAuthService.validateHdfsPathPattern(currentPath, paths); String dirDstPath; if (currentPath.equalsIgnoreCase("/")) { dirDstPath = currentPath + directoryName; } else { dirDstPath = currentPath + SystemUtils.FILE_SEPARATOR + directoryName; } //TODO HDFS ? ? /* dirMap.put("username", username); dirMap.put("hdfsPathPattern", hdfsPathPattern); dirMap.put("condition", "createDir"); hdfsBrowserAuthService.getHdfsBrowserUserDirAuth(dirMap);*/ boolean created = fileSystemService.createDirectory(dirDstPath, username); response.setSuccess(created); } catch (Exception ex) { response.setSuccess(false); response.getError().setMessage(ex.getMessage()); } return response; }
From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java
/** * .//from w w w . jav a 2s .co m * * @param dirMap ? * @return True or False */ @RequestMapping(value = "copyDirectory", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public Response copyDirectory(@RequestBody Map<String, String> dirMap) { String username = getSessionUsername(); String currentPath = getPathFilter(dirMap.get("currentPath")); String dstPath = getPathFilter(dirMap.get("dstPath")); String directoryName = FileUtils.getDirectoryName(currentPath); String filter = hadoopUserHome + SystemUtils.FILE_SEPARATOR + username; int userLevel = getSessionUserLevel(); //TODO HDFS ? ? /*hdfsBrowserAuthService.validateHdfsHomeWritePermission(currentPath, filter, userLevel); List<String> paths = hdfsBrowserAuthService.getHdfsBrowserPatternAll(username); String hdfsPathPattern = hdfsBrowserAuthService.validateHdfsPathPattern(currentPath, paths);*/ String dirDstPath; if (dstPath.equalsIgnoreCase("/")) { dirDstPath = dstPath + directoryName; } else { dirDstPath = dstPath + SystemUtils.FILE_SEPARATOR + directoryName; } //TODO HDFS ? ? /*dirMap.put("username", username); dirMap.put("hdfsPathPattern", hdfsPathPattern); dirMap.put("condition", "copyDir"); hdfsBrowserAuthService.getHdfsBrowserUserDirAuth(dirMap);*/ boolean copied = fileSystemService.copyDirectory(currentPath, dirDstPath, username); Response response = new Response(); response.setSuccess(copied); return response; }
From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java
/** * ??./*from www . j a va 2s . c om*/ * * @param dirMap ??? * @return True or False */ @RequestMapping(value = "moveDirectory", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public Response moveDirectory(@RequestBody Map<String, String> dirMap) { String username = getSessionUsername(); String currentPath = getPathFilter(dirMap.get("currentPath")); String dstPath = getPathFilter(dirMap.get("dstPath")); String directoryName = FileUtils.getDirectoryName(currentPath); String filter = hadoopUserHome + SystemUtils.FILE_SEPARATOR + username; int userLevel = getSessionUserLevel(); //TODO HDFS ? ? /*hdfsBrowserAuthService.validateHdfsHomeWritePermission(currentPath, filter, userLevel); List<String> paths = hdfsBrowserAuthService.getHdfsBrowserPatternAll(username); String hdfsPathPattern = hdfsBrowserAuthService.validateHdfsPathPattern(currentPath, paths);*/ String dirDstPath; if (dstPath.equalsIgnoreCase("/")) { dirDstPath = dstPath + directoryName; } else { dirDstPath = dstPath + SystemUtils.FILE_SEPARATOR + directoryName; } //TODO HDFS ? ? /*dirMap.put("username", username); dirMap.put("hdfsPathPattern", hdfsPathPattern); dirMap.put("condition", "moveDir"); hdfsBrowserAuthService.getHdfsBrowserUserDirAuth(dirMap);*/ boolean moved = fileSystemService.moveDirectory(currentPath, dirDstPath, username); Response response = new Response(); response.setSuccess(moved); return response; }
From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java
/** * ? ./*from w w w. j a v a 2s . c om*/ * * @param dirMap ? * @return True or False */ @RequestMapping(value = "renameDirectory", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public Response renameDirectory(@RequestBody Map<String, String> dirMap) { String username = getSessionUsername(); String currentPath = getPathFilter(dirMap.get("currentPath")); String directoryName = dirMap.get("directoryName"); String filter = hadoopUserHome + SystemUtils.FILE_SEPARATOR + username; int userLevel = getSessionUserLevel(); //TODO HDFS ? ? /*hdfsBrowserAuthService.validateHdfsHomeWritePermission(currentPath, filter, userLevel); List<String> paths = hdfsBrowserAuthService.getHdfsBrowserPatternAll(username); String hdfsPathPattern = hdfsBrowserAuthService.validateHdfsPathPattern(currentPath, paths); dirMap.put("username", username); dirMap.put("hdfsPathPattern", hdfsPathPattern); dirMap.put("condition", "renameDir"); hdfsBrowserAuthService.getHdfsBrowserUserDirAuth(dirMap);*/ boolean renamed = fileSystemService.renameDirectory(currentPath, directoryName, username); Response response = new Response(); response.setSuccess(renamed); return response; }
From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java
/** * .//from w ww.j a va 2s. c o m * * @param dirMap ? * @return True or False */ @RequestMapping(value = "deleteDirectory", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public Response deleteDirectory(@RequestBody Map<String, String> dirMap) { String username = getSessionUsername(); String currentPath = getPathFilter(dirMap.get("currentPath")); String filter = hadoopUserHome + SystemUtils.FILE_SEPARATOR + username; int userLevel = getSessionUserLevel(); //TODO HDFS ? ? /*hdfsBrowserAuthService.validateHdfsHomeWritePermission(currentPath, filter, userLevel); List<String> paths = hdfsBrowserAuthService.getHdfsBrowserPatternAll(username); String hdfsPathPattern = hdfsBrowserAuthService.validateHdfsPathPattern(currentPath, paths); dirMap.put("username", username); dirMap.put("hdfsPathPattern", hdfsPathPattern); dirMap.put("condition", "deleteDir"); hdfsBrowserAuthService.getHdfsBrowserUserDirAuth(dirMap);*/ boolean deleted = fileSystemService.deleteDirectory(currentPath, username); Response response = new Response(); response.setSuccess(deleted); return response; }
From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java
/** * ? ?? HDFS ? .//from ww w. j av a 2 s . c om * * @return REST Response JAXB Object */ @RequestMapping(value = "upload", method = RequestMethod.POST, consumes = { "multipart/form-data" }) @ResponseStatus(HttpStatus.OK) public ResponseEntity<String> upload(HttpServletRequest req) throws IOException { Response response = new Response(); if (!(req instanceof DefaultMultipartHttpServletRequest)) { response.setSuccess(false); response.getError().setCause("Request is not a file upload."); response.getError().setMessage("Failed to upload a file."); String json = new ObjectMapper().writeValueAsString(response); return new ResponseEntity(json, HttpStatus.BAD_REQUEST); } InputStream inputStream; DefaultMultipartHttpServletRequest request = (DefaultMultipartHttpServletRequest) req; String username = SessionUtils.getUsername(); String dstPath = request.getParameter("dstPath"); MultipartFile uploadedFile = request.getFile("fileName"); String originalFilename = uploadedFile.getOriginalFilename(); String pathToUpload = getPathFilter(dstPath); String fullyQualifiedPath = pathToUpload.equals("/") ? pathToUpload + originalFilename : pathToUpload + SystemUtils.FILE_SEPARATOR + originalFilename; inputStream = uploadedFile.getInputStream(); //TODO HDFS ? ? /*List<String> paths = hdfsBrowserAuthService.getHdfsBrowserPatternAll(username); String hdfsPathPattern = hdfsBrowserAuthService.validateHdfsPathPattern(pathToUpload, paths); Map fileMap = new HashMap(); fileMap.put("username", username); fileMap.put("hdfsPathPattern", hdfsPathPattern); fileMap.put("condition", "uploadFile"); hdfsBrowserAuthService.getHdfsBrowserUserDirAuth(fileMap);*/ // Engine? Remote? ?. boolean isRemoteEngine = Boolean.parseBoolean(isRemote); // Remote ? ? ?, Remote? Store and Forward if (!isRemoteEngine) { fileSystemService.validatePath(pathToUpload); String namenodeAgentUrl = MessageFormatter .arrayFormat("http://{}:{}/remote/agent/transfer/upload?fullyQualifiedPath={}&username={}", new Object[] { namenodeAgentAddress, namenodeAgentPort, URLEncoder.encode(fullyQualifiedPath, "UTF-8"), username }) .getMessage(); HttpPost httpPost = new HttpPost(namenodeAgentUrl); HttpEntity reqEntity = new InputStreamEntity(inputStream); httpPost.setEntity(reqEntity); HttpResponse execute = httpClient.execute(httpPost); if (execute.getStatusLine().getStatusCode() == 500) { response.setSuccess(false); response.getError().setMessage("?? ?? ."); } else if (execute.getStatusLine().getStatusCode() == 600) { response.setSuccess(false); response.getError().setMessage("(/) ? ."); } else { response.setSuccess(true); } inputStream.close(); httpPost.releaseConnection(); } else { boolean saved; byte[] bytes = FileCopyUtils.copyToByteArray(inputStream); fileSystemService.validateBeforeUpload(pathToUpload, fullyQualifiedPath, bytes, username); saved = fileSystemService.save(pathToUpload, fullyQualifiedPath, bytes, username); response.setSuccess(saved); } response.getMap().put("directory", pathToUpload); String json = new ObjectMapper().writeValueAsString(response); HttpStatus statusCode = HttpStatus.OK; return new ResponseEntity(json, statusCode); }