com.zhazhapan.util.FileExecutor Java Examples

The following examples show how to use com.zhazhapan.util.FileExecutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileManagerServiceImpl.java    From efo with MIT License 6 votes vote down vote up
@Override
public JSONObject copy(JSONObject object) {
    JSONArray array = object.getJSONArray("items");
    String dest = object.getString("newPath");
    File[] files = new File[array.size()];
    int i = 0;
    for (Object file : array) {
        files[i++] = new File(file.toString());
    }
    try {
        FileExecutor.copyFiles(files, dest);
        return getBasicResponse(ValueConsts.TRUE);
    } catch (IOException e) {
        logger.error(e.getMessage());
        return getBasicResponse(ValueConsts.FALSE);
    }
}
 
Example #2
Source File: CommonServiceImpl.java    From efo with MIT License 6 votes vote down vote up
@Override
public String uploadAvatar(MultipartFile multipartFile) {
    if (!multipartFile.isEmpty()) {
        String name = RandomUtils.getRandomStringOnlyLowerCase(ValueConsts.SIXTEEN_INT) + ValueConsts.DOT_SIGN +
                FileExecutor.getFileSuffix(multipartFile.getOriginalFilename());
        if (Checker.isImage(name) && multipartFile.getSize() < ValueConsts.MB * DefaultValues.TWO_INT) {
            String path = SettingConfig.getAvatarStoragePath() + ValueConsts.SEPARATOR + name;
            try {
                FileExecutor.writeByteArrayToFile(new File(path), multipartFile.getBytes());
                return name;
            } catch (IOException e) {
                logger.error("upload avatar error: " + e.getMessage());
            }
        }
    }
    return "";
}
 
Example #3
Source File: ConfigController.java    From efo with MIT License 6 votes vote down vote up
@ApiOperation(value = "更新配置文件")
@ApiImplicitParam(name = "config", value = "配置文件内容", required = true)
@AuthInterceptor(InterceptorLevel.ADMIN)
@RequestMapping(value = "", method = RequestMethod.PUT)
public String updateConfig(String config) {
    User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
    if (user.getPermission() > ValueConsts.TWO_INT) {
        EfoApplication.settings.setJsonObject(config);
        //打包成jar之后无法修改config.json文件
        try {
            FileExecutor.saveFile(NetUtils.urlToString(EfoApplication.class.getResource(DefaultValues
                    .SETTING_PATH)), EfoApplication.settings.toString());
        } catch (IOException e) {
            logger.error(e.getMessage());
            return "{\"message\":\"internal error, cannot save\"}";
        }
        return "{\"message\":\"saved successfully\"}";
    } else {
        return "{\"message\":\"permission denied\"}";
    }
}
 
Example #4
Source File: FileManagerServiceImpl.java    From efo with MIT License 5 votes vote down vote up
@Override
public JSONObject rename(JSONObject object) {
    String fileName = object.getString("item");
    String newFileName = object.getString("newItemPath");
    FileExecutor.renameTo(fileName, newFileName);
    return getBasicResponse(ValueConsts.TRUE);
}
 
Example #5
Source File: QiniuUtils.java    From qiniu with MIT License 5 votes vote down vote up
public static void saveFile(File file, String content) {
    try {
        FileExecutor.saveFile(file, content);
    } catch (IOException e) {
        Alerts.showError(QiniuValueConsts.MAIN_TITLE, e.getMessage());
    }
}
 
Example #6
Source File: QiniuUtils.java    From qiniu with MIT License 5 votes vote down vote up
public static void saveLogFile(String file, String content) {
    try {
        FileExecutor.saveLogFile(file, content);
    } catch (IOException e) {
        Alerts.showError(QiniuValueConsts.MAIN_TITLE, e.getMessage());
    }
}
 
Example #7
Source File: SpiderUtils.java    From visual-spider with MIT License 5 votes vote down vote up
/**
 * 保存文件
 *
 * @param file 文件路径
 * @param content 内容
 * @param append 保存方式
 */
public static void saveFile(String file, String content, boolean append) {
    try {
        if (Checker.isNotExists(file)) {
            FileExecutor.createFile(file);
        }
        FileExecutor.saveFile(file, content, append);
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
        Alerts.showError(SpiderValueConsts.MAIN_TITLE, e.getMessage());
    }
}
 
Example #8
Source File: CommonTest.java    From efo with MIT License 5 votes vote down vote up
@Test
public void testListRoot() {
    File[] files = FileExecutor.listFile("/c:/");
    for (File file : files) {
        System.out.println(file.getName());
    }
}
 
Example #9
Source File: SettingConfig.java    From efo with MIT License 5 votes vote down vote up
public static String getUploadStoragePath() {
    String parent = getStoragePath(ConfigConsts.UPLOAD_PATH_OF_SETTING);
    String formatWay = EfoApplication.settings.getStringUseEval(ConfigConsts.UPLOAD_FORM_OF_SETTING);
    String childPath = ValueConsts.SEPARATOR + Formatter.datetimeToCustomString(new Date(), formatWay);
    String path = parent + childPath;
    if (!FileExecutor.createFolder(path)) {
        path = ConfigConsts.DEFAULT_UPLOAD_PATH + childPath;
        FileExecutor.createFolder(path);
    }
    logger.info("upload path: " + path);
    return path;
}
 
Example #10
Source File: TokenConfig.java    From efo with MIT License 5 votes vote down vote up
public static Hashtable<String, Integer> loadToken() {
    Hashtable<String, Integer> tokens = new Hashtable<>(ValueConsts.SIXTEEN_INT);
    try {
        String token = FileExecutor.readFile(SettingConfig.getStoragePath(ConfigConsts.TOKEN_OF_SETTINGS));
        JSONArray array = JSON.parseArray(token);
        array.forEach(object -> {
            JSONObject jsonObject = (JSONObject) object;
            tokens.put(jsonObject.getString(ValueConsts.KEY_STRING), jsonObject.getInteger(ValueConsts
                    .VALUE_STRING));
        });
    } catch (Exception e) {
        logger.error("load token error: " + e.getMessage());
    }
    return tokens;
}
 
Example #11
Source File: TokenConfig.java    From efo with MIT License 5 votes vote down vote up
public static void saveToken() {
    String tokens = Formatter.mapToJson(EfoApplication.tokens);
    try {
        FileExecutor.saveFile(SettingConfig.getStoragePath(ConfigConsts.TOKEN_OF_SETTINGS), tokens);
    } catch (Exception e) {
        logger.error("save token error: " + e.getMessage());
    }
}
 
Example #12
Source File: FileManagerServiceImpl.java    From efo with MIT License 5 votes vote down vote up
@Override
public JSONObject move(JSONObject object) {
    JSONArray array = object.getJSONArray("items");
    String dest = object.getString("newPath");
    for (Object file : array) {
        try {
            FileExecutor.moveToDirectory(new File(file.toString()), new File(dest), ValueConsts.TRUE);
        } catch (IOException e) {
            logger.error(e.getMessage());
            return getBasicResponse(ValueConsts.FALSE);
        }
    }
    return getBasicResponse(ValueConsts.TRUE);
}
 
Example #13
Source File: FileManagerServiceImpl.java    From efo with MIT License 5 votes vote down vote up
@Override
public JSONObject edit(JSONObject object) {
    String file = object.getString("item");
    String content = object.getString("content");
    try {
        FileExecutor.saveFile(file, content);
        return getBasicResponse(ValueConsts.TRUE);
    } catch (IOException e) {
        logger.error(e.getMessage());
        return getBasicResponse(ValueConsts.FALSE);
    }
}
 
Example #14
Source File: FileManagerServiceImpl.java    From efo with MIT License 5 votes vote down vote up
@Override
public String getContent(JSONObject object) {
    String fileName = object.getString("item");
    try {
        return FileExecutor.readFile(fileName);
    } catch (IOException e) {
        logger.error(e.getMessage());
        return "";
    }
}
 
Example #15
Source File: FileManagerServiceImpl.java    From efo with MIT License 5 votes vote down vote up
@Override
public void multiDownload(HttpServletResponse response, String[] items, String destFile) throws IOException {
    File zip = ZipUtil.zip(new File(ValueConsts.USER_DESKTOP + File.separator + destFile), ValueConsts.FALSE,
            FileExecutor.getFiles(items));
    if (zip.exists()) {
        response.getOutputStream().write(FileExecutor.readFileToByteArray(zip));
        FileExecutor.deleteFile(zip);
    }
}
 
Example #16
Source File: EfoApplication.java    From efo with MIT License 5 votes vote down vote up
public static void main(String[] args) throws IOException, ClassNotFoundException {
    settings.setJsonObject(FileExecutor.read(EfoApplication.class.getResourceAsStream(DefaultValues.SETTING_PATH)));
    MailSender.config(settings.getObjectUseEval(ConfigConsts.EMAIL_CONFIG_OF_SETTINGS));
    controllers = ReflectUtils.getClasses(DefaultValues.CONTROLLER_PACKAGE);
    tokens = TokenConfig.loadToken();
    SpringApplication.run(EfoApplication.class, args);
}
 
Example #17
Source File: FileController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "通过文件路径获取服务器端的文件")
@ApiImplicitParam(name = "path", value = "文件路径(默认根目录)")
@AuthInterceptor(InterceptorLevel.ADMIN)
@RequestMapping(value = "/server", method = RequestMethod.GET)
public String getServerFilesByPath(String path) {
    File[] files = FileExecutor.listFile(Checker.isEmpty(path) ? (Checker.isWindows() ? "C:\\" : "/") : path);
    JSONArray array = new JSONArray();
    if (Checker.isNotNull(files)) {
        for (File file : files) {
            array.add(BeanUtils.beanToJson(file));
        }
    }
    return array.toJSONString();
}
 
Example #18
Source File: FileManagerServiceImpl.java    From efo with MIT License 4 votes vote down vote up
@Override
public JSONObject remove(JSONObject object) {
    JSONArray array = object.getJSONArray("items");
    array.forEach(file -> FileExecutor.deleteFile(file.toString()));
    return getBasicResponse(ValueConsts.TRUE);
}
 
Example #19
Source File: SettingConfig.java    From efo with MIT License 4 votes vote down vote up
public static String getAvatarStoragePath() {
    String path = getStoragePath(ConfigConsts.UPLOAD_PATH_OF_SETTING) + ValueConsts.SEPARATOR + "avatar";
    FileExecutor.createFolder(path);
    return path;
}
 
Example #20
Source File: FileManagerServiceImpl.java    From efo with MIT License 4 votes vote down vote up
@Override
public JSONObject createFolder(JSONObject object) {
    String folder = object.getString("newPath");
    return getBasicResponse(FileExecutor.createFolder(folder));
}