Java Code Examples for com.zhazhapan.util.Formatter#sizeToLong()

The following examples show how to use com.zhazhapan.util.Formatter#sizeToLong() . 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: 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 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 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 4
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();
    }
}