zoukankan      html  css  js  c++  java
  • 报错:常量字符串过长

    原因分析:常量字符串的长度不能长于65535 - 1字节;

    由于图片通过接口传递,图片转为base64编码后,字符串很大,故yreport的值很大,有360800个字符。

    原代码:

    public class DataEncrypt2Test {
        public static void main(String[] args) throws Exception {
            String pubKey = "省略不写";
            // 生产批次    
            String requestData = "{\n" +
                    "\t\"ycocode\": \"09876543211234567890\",\n" +
                    "\t\"yconame\": \"华润制药\",\n" +
                    "\t\"medicode\": \"B1243253\",\n" +
                    "\t\"mediname\": \"当归\",\n" +
                    "\t\"allowname\": \"张山\",\n" +
                    "\t\"locality\": \"深圳\",\n" +
                    "\t\"batchno\": \"B345353\",\n" +
                    "\t\"batchciid\": \"3452352\",\n" +
                    "\t\"prodate\": \"2021-10-10\",\n" +
                    "\t\"checkdate\": \"2021-11-11\",\n" +
                    "\t\"packgg\": \"10/箱\",\n" +
                    "\t\"checkname\": \"王五\",\n" +
                    "\t\"norm\": \"国标\",\n" +
                    "\t\"arts\": \"工艺01\",\n" +
                    "\t\"yreport\": \"此处为超长字符串,省略不写\",\n" +
                    "\t\"updatetime\": \"2021-12-12\",\n" +
                    "\t\"ybatchid\": \"1232141\",\n" +
                    "\t\"quantity\": \"100\",\n" +
                    "\t\"unit\": \"kg\",\n" +
                    "\t\"billtype\": \"销售出库\"\n" +
                    "}";
            String encrypt = RSAUtils.encryptByPublicKey(requestData, pubKey);
            System.out.println("requestData===> ");
            System.out.println(encrypt);
        }
    }

    解决办法:使用StringBuilder,将字符串分成多段进行拼接

    public class DataEncrypt2Test {
        public static void main(String[] args) throws Exception {
            String pubKey = "省略不写";// 生产批次
            StringBuilder sb = new StringBuilder();
            sb.append("很长字符串1,省略不写,下同");
            sb.append("很长字符穿2");
            sb.append("很长字符串3");
            sb.append("很长字符串4");
            sb.append("很长字符串5");
            sb.append("很长字符串6");
            sb.append("很长字符串7" );
            sb.append("很长字符串8");
            sb.append("很长字符串9");
            sb.append("很长字符串10");
            sb.append("很长字符串11");
            String str = sb.toString();
    
            String requestData = "{\n" +
                    "\t\"ycocode\": \"09876543211234567890\",\n" +
                    "\t\"yconame\": \"众益制药\",\n" +
                    "\t\"medicode\": \"B1243253\",\n" +
                    "\t\"mediname\": \"当归\",\n" +
                    "\t\"allowname\": \"张山\",\n" +
                    "\t\"locality\": \"深圳\",\n" +
                    "\t\"batchno\": \"B345353\",\n" +
                    "\t\"batchciid\": \"3452352\",\n" +
                    "\t\"prodate\": \"2021-10-10\",\n" +
                    "\t\"checkdate\": \"2021-11-11\",\n" +
                    "\t\"packgg\": \"10/箱\",\n" +
                    "\t\"checkname\": \"王五\",\n" +
                    "\t\"norm\": \"国标\",\n" +
                    "\t\"arts\": \"工艺01\",\n" +
                    "\t\"yreport\": \""+ str +"\",\n" +
                    "\t\"updatetime\": \"2021-12-12\",\n" +
                    "\t\"ybatchid\": \"1232141\",\n" +
                    "\t\"quantity\": \"100\",\n" +
                    "\t\"unit\": \"kg\",\n" +
                    "\t\"checkname\": \"王五\",\n" +
                    "\t\"billtype\": \"销售出库\"\n" +
                    "}";
            
            String encrypt = RSAUtils.encryptByPublicKey(requestData, pubKey);
            System.out.println("requestData===> ");
            System.out.println(encrypt);
        }
    }
  • 相关阅读:
    以太坊测试网络搭建以及RPC服务开启-配置注意事项
    AD预测论文研读系列1
    DenseNet 论文阅读笔记
    Deep learning with Python 学习笔记(7)
    ADNI数据
    利用卷积神经网络进行阿尔茨海默病分类的神经影像模式融合 论文研读笔记
    阿尔茨海默病早期诊断的脑结构分级图 论文研读笔记
    GoogLeNetv4 论文研读笔记
    ResNet 论文研读笔记
    GoogLeNetv3 论文研读笔记
  • 原文地址:https://www.cnblogs.com/zwh0910/p/15703535.html
Copyright © 2011-2022 走看看