com.zhazhapan.util.Formatter Java Examples

The following examples show how to use com.zhazhapan.util.Formatter. 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: QiniuService.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 获取空间的流量统计,使用自定义单位
 */
public XYChart.Series<String, Long> getBucketFlux(String[] domains, String startDate, String endDate, String unit) {
    // 获取流量数据
    CdnResult.FluxResult fluxResult = null;
    try {
        fluxResult = sdkManager.getFluxData(domains, startDate, endDate);
    } catch (QiniuException e) {
        Platform.runLater(() -> DialogUtils.showException(QiniuValueConsts.BUCKET_FLUX_ERROR, e));
    }
    // 设置图表
    XYChart.Series<String, Long> series = new XYChart.Series<>();
    series.setName(QiniuValueConsts.BUCKET_FLUX_COUNT.replaceAll("[A-Z]+", unit));
    // 格式化数据
    if (Checker.isNotNull(fluxResult) && Checker.isNotEmpty(fluxResult.data)) {
        long unitSize = Formatter.sizeToLong("1 " + unit);
        for (Map.Entry<String, CdnResult.FluxData> flux : fluxResult.data.entrySet()) {
            CdnResult.FluxData fluxData = flux.getValue();
            if (Checker.isNotNull(fluxData)) {
                setSeries(fluxResult.time, fluxData.china, fluxData.oversea, series, unitSize);
            }
        }
    }
    return series;
}
 
Example #2
Source File: QiniuService.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 获取空间带宽统计,使用自定义单位
 */
public XYChart.Series<String, Long> getBucketBandwidth(String[] domains, String startDate, String endDate,
                                                       String unit) {
    // 获取带宽数据
    CdnResult.BandwidthResult bandwidthResult = null;
    try {
        bandwidthResult = sdkManager.getBandwidthData(domains, startDate, endDate);
    } catch (QiniuException e) {
        Platform.runLater(() -> DialogUtils.showException(QiniuValueConsts.BUCKET_BAND_ERROR, e));
    }
    // 设置图表
    XYChart.Series<String, Long> series = new XYChart.Series<>();
    series.setName(QiniuValueConsts.BUCKET_BANDWIDTH_COUNT.replaceAll("[A-Z]+", unit));
    // 格式化数据
    if (Checker.isNotNull(bandwidthResult) && Checker.isNotEmpty(bandwidthResult.data)) {
        long unitSize = Formatter.sizeToLong("1 " + unit);
        for (Map.Entry<String, CdnResult.BandwidthData> bandwidth : bandwidthResult.data.entrySet()) {
            CdnResult.BandwidthData bandwidthData = bandwidth.getValue();
            if (Checker.isNotNull(bandwidthData)) {
                setSeries(bandwidthResult.time, bandwidthData.china, bandwidthData.oversea, series, unitSize);
            }
        }
    }
    return series;
}
 
Example #3
Source File: QiniuService.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 获取空间文件列表
 */
public void listFile() {
    MainController main = MainController.getInstance();
    // 列举空间文件列表
    BucketManager.FileListIterator iterator = sdkManager.getFileListIterator(main.bucketCB.getValue());
    ArrayList<FileBean> files = new ArrayList<>();
    main.setDataLength(0);
    main.setDataSize(0);
    // 处理结果
    while (iterator.hasNext()) {
        FileInfo[] items = iterator.next();
        for (FileInfo item : items) {
            main.setDataLength(main.getDataLength() + 1);
            main.setDataSize(main.getDataSize() + item.fsize);
            // 将七牛的时间单位(100纳秒)转换成毫秒,然后转换成时间
            String time = Formatter.timeStampToString(item.putTime / 10000);
            String size = Formatter.formatSize(item.fsize);
            FileBean file = new FileBean(item.key, item.mimeType, size, time);
            files.add(file);
        }
    }
    main.setResData(FXCollections.observableArrayList(files));
}
 
Example #4
Source File: FileController.java    From efo with MIT License 6 votes vote down vote up
@ApiOperation(value = "获取文件记录")
@ApiImplicitParams({@ApiImplicitParam(name = "offset", value = "偏移量", required = true), @ApiImplicitParam(name =
        "categoryId", value = "分类ID", required = true), @ApiImplicitParam(name = "orderBy", value = "排序方式",
        required = true, example = "id desc"), @ApiImplicitParam(name = "search", value = "记录匹配(允许为空)")})
@AuthInterceptor(InterceptorLevel.NONE)
@RequestMapping(value = "/all", method = RequestMethod.GET)
public String getAll(int offset, int categoryId, String orderBy, String search) {
    User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
    boolean canGet = EfoApplication.settings.getBooleanUseEval(ConfigConsts.ANONYMOUS_VISIBLE_OF_SETTING) ||
            (Checker.isNotNull(user) && user.getIsVisible() == 1);
    if (canGet) {
        int userId = Checker.isNull(user) ? 0 : user.getId();
        return Formatter.listToJson(fileService.listAll(userId, offset, categoryId, orderBy, search));
    } else {
        jsonObject.put("error", "权限被限制,无法获取资源,请联系管理员");
        return jsonObject.toString();
    }
}
 
Example #5
Source File: MainController.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 搜索资源文件,忽略大小写
 */
public void searchFile() {
    ArrayList<FileBean> files = new ArrayList<>();
    String search = Checker.checkNull(searchTF.getText());
    dataLength = 0;
    dataSize = 0;
    // 正则匹配查询
    Pattern pattern = Pattern.compile(search, Pattern.CASE_INSENSITIVE);
    for (FileBean file : resData) {
        if (pattern.matcher(file.getName()).find()) {
            files.add(file);
            dataLength++;
            dataSize += Formatter.sizeToLong(file.getSize());
        }
    }
    countBucket();
    resTV.setItems(FXCollections.observableArrayList(files));
}
 
Example #6
Source File: AuthServiceImpl.java    From efo with MIT License 6 votes vote down vote up
@Override
public boolean addAuth(String files, String users, String auths) {
    if (Checker.isNotEmpty(files) && Checker.isNotEmpty(users) && Checker.isNotEmpty(auths)) {
        String[] file = files.split(ValueConsts.COMMA_SIGN);
        String[] user = users.split(ValueConsts.COMMA_SIGN);
        for (String f : file) {
            long fileId = Formatter.stringToLong(f);
            for (String u : user) {
                int userId = Formatter.stringToInt(u);
                if (Checker.isNull(authDAO.exists(userId, fileId))) {
                    Auth auth = new Auth(userId, fileId);
                    auth.setAuth(BeanUtils.getAuth(auths));
                    authDAO.insertAuth(auth);
                }
            }
        }
    }
    return true;
}
 
Example #7
Source File: AuthController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "获取权限记录")
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "用户", required = true), @ApiImplicitParam(name =
        "file", value = "文件", required = true), @ApiImplicitParam(name = "offset", value = "偏移量", required = true)})
@AuthInterceptor(InterceptorLevel.ADMIN)
@RequestMapping(value = "/all", method = RequestMethod.GET)
public String getAuth(String user, String file, int offset) {
    return Formatter.listToJson(authService.listAuth(user, file, offset));
}
 
Example #8
Source File: FormatterTest.java    From qiniu with MIT License 5 votes vote down vote up
@Test
public void testSizeToLong() {
	String[] sizes = { "23.12 MB", "12.89 KB", "23 B", "23.77 GB", "89.12 TB" };
	for (String size : sizes) {
		System.out.println(Formatter.sizeToLong(size));
	}
}
 
Example #9
Source File: QiniuUtils.java    From qiniu with MIT License 5 votes vote down vote up
public static String getFileName(String string) {
    try {
        return Formatter.getFileName(string);
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("get file name of url failed, message -> " + e.getMessage());
        return "";
    }
}
 
Example #10
Source File: QiniuService.java    From qiniu with MIT License 5 votes vote down vote up
/**
 * 批量删除文件,单次批量请求的文件数量不得超过1000
 */
public void deleteFile(ObservableList<FileBean> fileBeans, String bucket) {
    if (Checker.isNotEmpty(fileBeans) && QiniuUtils.checkNet()) {
        // 生成待删除的文件列表
        String[] files = new String[fileBeans.size()];
        ArrayList<FileBean> selectedFiles = new ArrayList<>();
        int i = 0;
        for (FileBean fileBean : fileBeans) {
            files[i++] = fileBean.getName();
            selectedFiles.add(fileBean);
        }
        try {
            BatchStatus[] batchStatusList = sdkManager.batchDelete(bucket, files);
            MainController main = MainController.getInstance();
            // 文件列表是否为搜索后结果
            boolean isInSearch = Checker.isNotEmpty(main.searchTF.getText());
            ObservableList<FileBean> currentRes = main.resTV.getItems();
            // 更新界面数据
            for (i = 0; i < files.length; i++) {
                BatchStatus status = batchStatusList[i];
                String file = files[i];
                if (status.code == 200) {
                    main.getResData().remove(selectedFiles.get(i));
                    main.setDataLength(main.getDataLength() - 1);
                    main.setDataSize(main.getDataSize() - Formatter.sizeToLong(selectedFiles.get(i).getSize()));
                    if (isInSearch) {
                        currentRes.remove(selectedFiles.get(i));
                    }
                } else {
                    LOGGER.error("delete " + file + " failed, message -> " + status.data.error);
                    DialogUtils.showError("删除文件:" + file + " 失败");
                }
            }
        } catch (QiniuException e) {
            DialogUtils.showException(QiniuValueConsts.DELETE_ERROR, e);
        }
        MainController.getInstance().countBucket();
    }
}
 
Example #11
Source File: MainController.java    From qiniu with MIT License 5 votes vote down vote up
/**
 * 设置文件生存时间
 */
public void setLife() {
    ObservableList<FileBean> selectedItems = resTV.getSelectionModel().getSelectedItems();
    if (Checker.isNotEmpty(selectedItems)) {
        // 弹出输入框
        String fileLife = DialogUtils.showInputDialog(null, QiniuValueConsts.FILE_LIFE,
                QiniuValueConsts.DEFAULT_FILE_LIFE);
        if (Checker.isNumber(fileLife)) {
            int life = Formatter.stringToInt(fileLife);
            selectedItems.forEach(bean -> service.setFileLife(bucketCB.getValue(), bean.getName(), life));
        }
    }
}
 
Example #12
Source File: MainController.java    From qiniu with MIT License 5 votes vote down vote up
/**
 * 绘制数据统计图表
 */
private void drawChart(boolean isFluxUnitChange, boolean isBandwidthUnitChange) {
    Date localStartDate = Formatter.localDateToDate(startDP.getValue());
    Date localEndDate = Formatter.localDateToDate(endDP.getValue());
    // 将本地日期装换成字符串
    String fromDate = Formatter.dateToString(localStartDate);
    String toDate = Formatter.dateToString(localEndDate);
    // 获取开始日期和结束日期的时间差
    long timeSpan = localEndDate.getTime() - localStartDate.getTime();
    if (Checker.isNotEmpty(domainTF.getText()) && timeSpan >= 0 && timeSpan <= QiniuValueConsts.DATE_SPAN_OF_THIRTY_ONE) {
        Platform.runLater(() -> {
            String[] domains = {domainTF.getText()};
            if (isFluxUnitChange) {
                // 获取流量数据
                String fluxUnit = fluxUnitCB.getValue();
                fluxAC.getData().clear();
                fluxAC.getData().add(service.getBucketFlux(domains, fromDate, toDate, fluxUnit));
            }
            if (isBandwidthUnitChange) {
                // 获取带宽数据
                String bandUnit = bandwidthUnitCB.getValue();
                bandwidthAC.getData().clear();
                bandwidthAC.getData().add(service.getBucketBandwidth(domains, fromDate, toDate, bandUnit));
            }
        });
    }
}
 
Example #13
Source File: VsController.java    From visual-spider with MIT License 5 votes vote down vote up
/**
 * 初始化
 *
 * @param numberOfCrawlers 爬虫线程数
 * @param maxDepthOfCrawling 抓取深度
 * @param maxPagesToFetch 最大抓取页数
 * @param politenessDelay 延迟
 * @param links 待爬取链接
 */
public void init(int numberOfCrawlers, int maxDepthOfCrawling, int maxPagesToFetch, int politenessDelay, String[]
        links) {
    this.numberOfCrawlers = numberOfCrawlers;
    CrawlConfig config = new CrawlConfig();
    config.setCrawlStorageFolder(DefaultConfigValues.CRAWL_STORAGE_FOLDER);
    config.setMaxDepthOfCrawling(maxDepthOfCrawling);
    config.setIncludeHttpsPages(true);
    config.setMaxPagesToFetch(maxPagesToFetch);
    config.setIncludeBinaryContentInCrawling(false);
    config.setPolitenessDelay(politenessDelay);
    config.setUserAgentString(DefaultConfigValues.USER_AGENT);
    config.setResumableCrawling(true);

    if (com.zhazhapan.vspider.models.CrawlConfig.getTurnOnProxy().get()) {
        LOGGER.info("open proxy");
        config.setProxyHost(com.zhazhapan.vspider.models.CrawlConfig.getProxyServer().get());
        config.setProxyPort(Formatter.stringToInt(com.zhazhapan.vspider.models.CrawlConfig.getProxyPort().get()));
        config.setProxyUsername(com.zhazhapan.vspider.models.CrawlConfig.getProxyUser().get());
        config.setProxyPassword(com.zhazhapan.vspider.models.CrawlConfig.getProxyPass().get());
    }

    PageFetcher pageFetcher = new PageFetcher(config);
    RobotstxtConfig robotstxtConfig = new RobotstxtConfig();
    robotstxtConfig.setEnabled(false);
    RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher);
    try {
        controller = new CrawlController(config, pageFetcher, robotstxtServer);
        for (String link : links) {
            if (Checker.isHyperLink(link)) {
                controller.addSeed(link);
            }
        }
        isInited = true;
    } catch (Exception e) {
        LOGGER.error("start to crawl urls error: " + e.getMessage());
    }
}
 
Example #14
Source File: CommonTest.java    From efo with MIT License 5 votes vote down vote up
@Test
public void testGetDriver() {
    FileSystemView fsv = FileSystemView.getFileSystemView();
    File[] fs = File.listRoots();
    for (File f : fs) {
        System.out.println(fsv.getSystemDisplayName(f));
        System.out.print("总大小" + Formatter.formatSize(f.getTotalSpace()));
        System.out.println("剩余" + Formatter.formatSize(f.getFreeSpace()));
        System.out.println(f.isDirectory());
    }
}
 
Example #15
Source File: FileController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "更新文件路径(包括本地路径,访问路径,如果新的本地路径和访问路径均为空,这什么也不会做)")
@ApiImplicitParams({@ApiImplicitParam(name = "oldLocalUrl", value = "文件本地路径", required = true), @ApiImplicitParam
        (name = "localUrl", value = "新的本地路径(可空)"), @ApiImplicitParam(name = "visitUrl", value = "新的访问路径(可空)")})
@AuthInterceptor(InterceptorLevel.ADMIN)
@RequestMapping(value = "/{id}/url", method = RequestMethod.PUT)
public String uploadFileUrl(@PathVariable("id") int id, String oldLocalUrl, String localUrl, String visitUrl) {
    boolean[] b = fileService.updateUrl(id, oldLocalUrl, localUrl, visitUrl);
    String responseJson = "{status:{localUrl:" + b[0] + ",visitUrl:" + b[1] + "}}";
    return Formatter.formatJson(responseJson);
}
 
Example #16
Source File: UserController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "获取所有用户")
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name = "offset",
        value = "偏移量", required = true)})
@AuthInterceptor(InterceptorLevel.ADMIN)
@RequestMapping(value = "/all", method = RequestMethod.GET)
public String getUser(String user, int offset) {
    User u = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
    return Formatter.listToJson(userService.listUser(u.getPermission(), user, offset));
}
 
Example #17
Source File: DownloadedController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "获取文件下载记录")
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name =
        "指定文件(默认所有文件)"), @ApiImplicitParam(name = "category", value = "指定分类(默认所有分类)"), @ApiImplicitParam(name =
        "offset", value = "偏移量", required = true)})
@AuthInterceptor(InterceptorLevel.ADMIN)
@RequestMapping(value = "all", method = RequestMethod.GET)
public String getAll(String user, String file, String category, int offset) {
    return Formatter.listToJson(downloadService.list(user, file, category, offset));
}
 
Example #18
Source File: UploadedController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "获取文件上传记录")
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name =
        "指定文件(默认所有文件)"), @ApiImplicitParam(name = "category", value = "指定分类(默认所有分类)"), @ApiImplicitParam(name =
        "offset", value = "偏移量", required = true)})
@AuthInterceptor(InterceptorLevel.ADMIN)
@RequestMapping(value = "all", method = RequestMethod.GET)
public String getAll(String user, String file, String category, int offset) {
    return Formatter.listToJson(uploadedService.list(user, file, category, offset));
}
 
Example #19
Source File: FileController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "获取我的下载记录")
@ApiImplicitParams({@ApiImplicitParam(name = "offset", value = "偏移量", required = true), @ApiImplicitParam(name =
        "search", value = "记录匹配(允许为空)")})
@AuthInterceptor(InterceptorLevel.USER)
@RequestMapping(value = "/user/downloaded", method = RequestMethod.GET)
public String getUserDownloaded(int offset, String search) {
    User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
    return Formatter.listToJson(fileService.listUserDownloaded(user.getId(), offset, search));
}
 
Example #20
Source File: FileController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "获取我的上传记录")
@ApiImplicitParams({@ApiImplicitParam(name = "offset", value = "偏移量", required = true), @ApiImplicitParam(name =
        "search", value = "记录匹配(允许为空)")})
@AuthInterceptor(InterceptorLevel.USER)
@RequestMapping(value = "/user/uploaded", method = RequestMethod.GET)
public String getUserUploaded(int offset, String search) {
    User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
    return Formatter.listToJson(fileService.listUserUploaded(user.getId(), offset, search));
}
 
Example #21
Source File: FileController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "获取所有文件的基本信息")
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name = "file",
        value = "指定文件(默认所有文件)"), @ApiImplicitParam(name = "category", value = "指定分类(默认所有分类)"), @ApiImplicitParam
        (name = "offset", value = "偏移量", required = true)})
@AuthInterceptor(InterceptorLevel.ADMIN)
@RequestMapping(value = "/basic/all", method = RequestMethod.GET)
public String getBasicAll(String user, String file, String category, int offset) {
    return Formatter.listToJson(fileService.listBasicAll(user, file, category, offset));
}
 
Example #22
Source File: BeanUtils.java    From efo with MIT License 5 votes vote down vote up
/**
 * 将Bean转换成JSON
 *
 * @param object Bean对象
 *
 * @return {@link String}
 */
public static String toPrettyJson(Object object) {
    String result;
    try {
        result = com.zhazhapan.util.BeanUtils.toPrettyJson(object, FieldModifier.PRIVATE);
    } catch (IllegalAccessException e) {
        result = Formatter.formatJson(ERROR_JSON);
        logger.error(e.getMessage());
    }
    return result;
}
 
Example #23
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 #24
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 #25
Source File: BeanUtils.java    From efo with MIT License 5 votes vote down vote up
/**
 * 将权限字符串装换成权限数组
 *
 * @param auth 权限字符串
 *
 * @return 权限数组
 */
public static int[] getAuth(String auth) {
    int[] a = new int[5];
    if (Checker.isNotEmpty(auth)) {
        String[] u = auth.split(ValueConsts.COMMA_SIGN);
        int len = Math.min(a.length, u.length);
        for (int i = 0; i < len; i++) {
            a[i] = Formatter.stringToInt(u[i]);
        }
    }
    return a;
}
 
Example #26
Source File: MainController.java    From qiniu with MIT License 4 votes vote down vote up
/**
 * 下载日志
 */
public void downloadCdnLog() {
    String date = DialogUtils.showInputDialog(null, QiniuValueConsts.INPUT_LOG_DATE,
            Formatter.dateToString(new Date()));
    service.downloadCdnLog(date);
}
 
Example #27
Source File: MainController.java    From visual-spider with MIT License 4 votes vote down vote up
/**
 * 爬取URL
 */
public void toCrawl() {
    if (crawling) {
        // 暂停爬虫
        crawling = false;
        toggleCrawling.setText(SpiderValueConsts.CRAWLER_START);
        statusLabel.setText("crawler suspend");
        SpiderApplication.controller.shutdown();
    } else {
        if (MysqlConfig.isEnableCustom() && !MysqlConfig.isConnectionSuccessful()) {
            MysqlConfig.setEnableSql(true);
            Alerts.showWarning(SpiderValueConsts.MAIN_TITLE, "数据库连接失败,将自动为您生成SQL文件");
        }
        // 开始爬虫
        if (!Checker.isHyperLink(crawlUrl.getText())) {
            String html = htmlContent.getText();
            if (Checker.isNotEmpty(html)) {
                // 如果没有输入要爬取的链接,并且链接访问文本域的内容不为空,将直接把该内容作为源代码传送到下载模式
                ThreadPool.executor.submit(() -> new Crawler().downloadURL("", html));
                htmlContent.clear();
            }
            return;
        }
        crawling = true;
        toggleCrawling.setText(SpiderValueConsts.CRAWLER_STOP);
        LOGGER.info("start to crawl urls: " + crawlUrl.getText());
        statusLabel.setText("starting......");
        // 读取爬虫配置
        String[] urls = crawlUrl.getText().split(" ");
        SpiderApplication.domains = new String[urls.length];
        for (int i = 0; i < urls.length; i++) {
            String url = urls[i].replaceAll("https?://", "");
            if (url.contains("/")) {
                SpiderApplication.domains[i] = url.substring(0, url.indexOf("/") + 1);
            } else {
                SpiderApplication.domains[i] = url;
            }
        }
        // 爬虫参数转换为合法的数据
        int numNon = Formatter.stringToInt(CrawlConfig.getNumberOfCrawlers().get());
        int num = numNon < 1 ? DefaultConfigValues.NUMBER_OF_CRAWLERS : numNon;
        int depNon = Formatter.stringToInt(CrawlConfig.getMaxDepthOfCrawling().get());
        int dep = depNon < 1 || depNon > DefaultConfigValues.MAX_DEPTH_OF_CRAWLING ? DefaultConfigValues
                .MAX_DEPTH_OF_CRAWLING : depNon;
        int pagNon = Formatter.stringToInt(CrawlConfig.getMaxPagesToFetch().get());
        int pag = pagNon < 1 ? Integer.MAX_VALUE : pagNon;
        int delNon = Formatter.stringToInt(CrawlConfig.getPolitenessDelay().get());
        int del = delNon < 1 ? DefaultConfigValues.POLITENESS_DELAY : delNon;
        SpiderApplication.crawlingDelay = del;
        ThreadPool.executor.submit(() -> {
            // 开启爬虫
            SpiderApplication.controller.init(num, dep, pag, del, urls);
            boolean res = SpiderApplication.controller.start();
            finished(res);
        });
    }
}
 
Example #28
Source File: MainController.java    From qiniu with MIT License 4 votes vote down vote up
/**
 * 显示移动或复制文件的弹窗
 */
public void showFileMovableDialog() {
    ObservableList<FileBean> selectedItems = resTV.getSelectionModel().getSelectedItems();
    if (Checker.isEmpty(selectedItems)) {
        // 没有选择文件,结束方法
        return;
    }
    Pair<SdkManager.FileAction, String[]> resultPair;
    String bucket = bucketCB.getValue();
    if (selectedItems.size() > 1) {
        resultPair = dialog.showFileDialog(bucket, "", false);
    } else {
        resultPair = dialog.showFileDialog(bucket, selectedItems.get(0).getName(), true);
    }
    if (Checker.isNotNull(resultPair)) {
        boolean useNewKey = Checker.isNotEmpty(resultPair.getValue()[1]);
        ObservableList<FileBean> fileBeans = resTV.getItems();
        for (FileBean fileBean : selectedItems) {
            String fromBucket = bucketCB.getValue();
            String toBucket = resultPair.getValue()[0];
            String name = useNewKey ? resultPair.getValue()[1] : fileBean.getName();
            boolean isSuccess = service.moveOrCopyFile(fromBucket, fileBean.getName(), toBucket, name,
                    resultPair.getKey());
            if (resultPair.getKey() == SdkManager.FileAction.MOVE && isSuccess) {
                boolean isInSearch = Checker.isNotEmpty(searchTF.getText());
                if (fromBucket.equals(toBucket)) {
                    // 更新文件名
                    fileBean.setName(name);
                    if (isInSearch) {
                        fileBeans.get(fileBeans.indexOf(fileBean)).setName(name);
                    }
                } else {
                    // 删除数据源
                    fileBeans.remove(fileBean);
                    dataLength--;
                    dataSize -= Formatter.sizeToLong(fileBean.getSize());
                    if (isInSearch) {
                        fileBeans.remove(fileBean);
                    }
                }
            }
        }
        countBucket();
    }
}
 
Example #29
Source File: MainController.java    From qiniu with MIT License 4 votes vote down vote up
/**
 * 统计空间文件的数量以及大小
 */
public void countBucket() {
    lengthLabel.setText(Formatter.customFormatDecimal(dataLength, ",###") + " 个文件");
    sizeLabel.setText(Formatter.formatSize(dataSize));
}
 
Example #30
Source File: UserDAOTest.java    From efo with MIT License 4 votes vote down vote up
@Test
public void testGetAllUser() {
    System.out.println(Formatter.listToJson(userDAO.listUserBy(3, "", 0)));
}